]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman-Common/src/org/splat/dal/bo/som/Publication.java
Salome HOME
Refactoring continues: UserService is created instead of UserDirectory. Database...
[tools/siman.git] / Workspace / Siman-Common / src / org / splat / dal / bo / som / Publication.java
1 package org.splat.dal.bo.som;
2 /**
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/>
7  * <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/>
10  * <br/>
11  * The document version referenced by a Publication object is the Value of the publication.
12  * 
13  * @see Document
14  * @see ProjectElement
15  * @see Step
16  * @author    Daniel Brunier-Coulin
17  * @copyright OPEN CASCADE 2012
18  */
19
20 import java.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
23
24 import org.splat.dal.bo.kernel.Persistent;
25 import org.splat.dal.bo.kernel.Relation;
26 import org.splat.som.Step;
27
28
29 public class Publication extends Persistent {
30
31 //  Persistent fields
32     private  Document        mydoc;
33     private  ProjectElement  owner;     // Either Study or Scenario, depending on the step involved by the publication
34     private  char            isnew;     // True if this references a document version new for the owner project element
35
36 //  Transient fields
37     private  Step            mystep;
38
39 //  ==============================================================================================================================
40 //  Construction
41 //  ==============================================================================================================================
42
43 /**
44          * Get the mystep.
45          * @return the mystep
46          */
47         public Step getStep() {
48                 return mystep;
49         }
50         /**
51          * Set the mystep.
52          * @param aStep the mystep to set
53          */
54         public void setStep(Step aStep) {
55                 this.mystep = aStep;
56         }
57         //  Database fetch constructor
58     public Publication () {
59 //  ------------------------
60       mystep = null;
61     }
62 //  Internal constructors
63     public Publication (Document doc, ProjectElement publisher) {
64 //  --------------------------------------------------------------
65       mydoc  = doc;
66       mystep = null;
67       owner  = publisher;
68       isnew  = 'Y';
69     }
70 //  ==============================================================================================================================
71 //  Member functions
72 //  ==============================================================================================================================
73
74     public Relation addDependency (Publication to) {
75 //  ----------------------------------------------
76       return  this.addDependency(to.value());
77     }
78
79     public Relation addDependency (Document to) {
80 //  -------------------------------------------
81       if (to == null) return null;
82       else            return mydoc.addRelation( new UsesRelation(mydoc, to) );
83     }
84
85 /**
86  * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
87  * which the referenced document has been published.<br/>
88  * If this publication belongs to a Study, the Project Element returned is the Study returned by getOwnerStudy().
89  * 
90  * @return the Study Scenario or the Study to which this publication belongs to
91  * @see    #getOwnerStudy()
92  */
93     public ProjectElement getOwner () {
94 //  ---------------------------------
95       return owner;
96     }
97
98     /**
99          * Set the owner.
100          * @param owner the owner to set
101          */
102         public void setOwner(ProjectElement owner) {
103                 this.owner = owner;
104         }
105
106         public Study getOwnerStudy () {
107 //  -----------------------------
108       if (owner instanceof Study) return  (Study)owner;
109       else                        return ((Scenario)owner).getOwnerStudy();
110     }
111
112 /**
113  * Returns the state of this published document.
114  * It is the same than the state of the referenced document, unless this publication is out-of-date, in which case it is
115  * In-Work state.
116  * 
117  * @see #outdate()
118  * @see #isOutdated()
119  */
120     public ProgressState getProgressState () {
121 //  ----------------------------------------
122       if (this.isOutdated()) return ProgressState.inWORK;   // Overrides the document state
123       else                   return mydoc.getProgressState();
124     }
125
126     public List<Publication> getRelations (Class<? extends Relation> type) {
127 //  ----------------------------------------------------------------------
128       if (type == null) return null;
129
130       List<Publication> result = new ArrayList<Publication>();
131       List<Relation>    relist = mydoc.getRelations(type);
132       for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
133         Relation     relation  = i.next();
134         Document     relatedoc = (Document)relation.getTo();
135         Publication  related   = owner.getPublication(relatedoc);
136         if (related != null) {
137           result.add(related);
138         } else
139         if (owner instanceof Scenario) {   // The relation may cross steps belonging to a scenario and its owner study
140           related = ((Scenario)owner).getOwnerStudy().getPublication(relatedoc);
141           if (related != null) result.add(related);
142         }
143       }
144       return result;
145     }
146
147     public File getSourceFile () {
148 //  ----------------------------
149       return mydoc.getSourceFile();
150     }
151
152     public boolean isNewForOwner () {
153 //  -------------------------------
154       return (isnew == 'Y');
155     }
156
157     public boolean isOutdated () {
158 //  ----------------------------
159       return (isnew == 'O');
160     }
161
162     /**
163          * Get the isnew.
164          * @return the isnew
165          */
166         public char getIsnew() {
167                 return isnew;
168         }
169         /**
170          * Set the isnew.
171          * @param isnew the isnew to set
172          */
173         public void setIsnew(char isnew) {
174                 this.isnew = isnew;
175         }
176         
177 /**
178  * Returns the document version referenced by this Publication.
179  */
180     public Document value () {
181 //  ------------------------
182       return mydoc;
183     }
184         /**
185          * Set the mydoc.
186          * @param mydoc the mydoc to set
187          */
188         public void setValue (Document aDoc) {
189                 this.mydoc = aDoc;
190         }
191 }