1 package org.splat.dal.bo.som;
3 * Publication objects are the way to reference document versions from a Project Element.
4 * As such, a Document version is added (or published) to a Project Element through a Publication object.
5 * This publication is done by saving the Publication object produced when creating and versioning a Document from a given
6 * Project Element Step (call of the saveAs() function).<br/>
8 * A Publication object is homogeneous to a reference to a Document version and belongs to one Project Element, this latter
9 * being either a Study Scenario or a Study itself, depending on the Study Step to which the document is published.<br/>
11 * The document version referenced by a Publication object is the Value of the publication.
16 * @author Daniel Brunier-Coulin
17 * @copyright OPEN CASCADE 2012
20 import java.io.FileNotFoundException;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.Iterator;
24 import java.util.List;
26 import org.hibernate.Session;
27 import org.splat.dal.bo.kernel.Persistent;
28 import org.splat.dal.bo.kernel.Relation;
29 import org.splat.dal.bo.kernel.User;
30 import org.splat.dal.dao.som.Database;
31 import org.splat.kernel.InvalidPropertyException;
32 import org.splat.kernel.NotApplicableException;
33 import org.splat.manox.Reader;
34 import org.splat.manox.Toolbox;
35 import org.splat.som.DocumentRights;
36 import org.splat.som.Revision;
37 import org.splat.som.Step;
40 public class Publication extends Persistent {
43 private Document mydoc;
44 private ProjectElement owner; // Either Study or Scenario, depending on the step involved by the publication
45 private char isnew; // True if this references a document version new for the owner project element
50 // ==============================================================================================================================
52 // ==============================================================================================================================
58 public Step getStep() {
63 * @param aStep the mystep to set
65 public void setStep(Step aStep) {
68 // Database fetch constructor
69 public Publication () {
70 // ------------------------
73 // Internal constructors
74 public Publication (Document doc, ProjectElement publisher) {
75 // --------------------------------------------------------------
81 // ==============================================================================================================================
83 // ==============================================================================================================================
85 public Relation addDependency (Publication to) {
86 // ----------------------------------------------
87 return this.addDependency(to.value());
90 public Relation addDependency (Document to) {
91 // -------------------------------------------
92 if (to == null) return null;
93 else return mydoc.addRelation( new UsesRelation(mydoc, to) );
97 * Undo the out-date operation.
99 * @return true if the acceptance succeeds
101 * @see DocumentRights#canAccept()
103 public boolean actualize () {
104 // ---------------------------
105 if (!this.isOutdated()) return false;
107 Database.getSession().update(this);
112 * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
113 * which the referenced document has been published.<br/>
114 * If this publication belongs to a Study, the Project Element returned is the Study returned by getOwnerStudy().
116 * @return the Study Scenario or the Study to which this publication belongs to
117 * @see #getOwnerStudy()
119 public ProjectElement getOwner () {
120 // ---------------------------------
126 * @param owner the owner to set
128 public void setOwner(ProjectElement owner) {
132 public Study getOwnerStudy () {
133 // -----------------------------
134 if (owner instanceof Study) return (Study)owner;
135 else return ((Scenario)owner).getOwnerStudy();
139 * Returns the state of this published document.
140 * It is the same than the state of the referenced document, unless this publication is out-of-date, in which case it is
146 public ProgressState getProgressState () {
147 // ----------------------------------------
148 if (this.isOutdated()) return ProgressState.inWORK; // Overrides the document state
149 else return mydoc.getProgressState();
152 public List<Publication> getRelations (Class<? extends Relation> type) {
153 // ----------------------------------------------------------------------
154 if (type == null) return null;
156 List<Publication> result = new ArrayList<Publication>();
157 List<Relation> relist = mydoc.getRelations(type);
158 for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
159 Relation relation = i.next();
160 Document relatedoc = (Document)relation.getTo();
161 Publication related = owner.getPublication(relatedoc);
162 if (related != null) {
165 if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
166 related = ((Scenario)owner).getOwnerStudy().getPublication(relatedoc);
167 if (related != null) result.add(related);
173 public File getSourceFile () {
174 // ----------------------------
175 return mydoc.getSourceFile();
178 public boolean isNewForOwner () {
179 // -------------------------------
180 return (isnew == 'Y');
183 public boolean isOutdated () {
184 // ----------------------------
185 return (isnew == 'O');
192 public char getIsnew() {
197 * @param isnew the isnew to set
199 public void setIsnew(char isnew) {
203 * Out-dates this publication and recursively all publications using this one.
204 * Typically, a publication is out-dated when modifying a document to which it depends.
207 * @see #getProgressState()
210 public void outdate () {
211 // ----------------------
212 if (this.isOutdated()) return;
214 List<Publication> relist = this.getRelations(UsedByRelation.class);
215 for (Iterator<Publication> i = relist.iterator(); i.hasNext(); ) {
219 Database.getSession().update(this);
223 * Returns the document version referenced by this Publication.
225 public Document value () {
226 // ------------------------
231 * @param mydoc the mydoc to set
233 public void setValue (Document aDoc) {