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.util.ArrayList;
21 import java.util.Iterator;
22 import java.util.List;
24 import org.splat.dal.bo.kernel.Persistent;
25 import org.splat.dal.bo.kernel.Relation;
26 import org.splat.som.Step;
29 public class Publication extends Persistent {
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
39 // ==============================================================================================================================
41 // ==============================================================================================================================
47 public Step getStep() {
52 * @param aStep the mystep to set
54 public void setStep(final Step aStep) {
57 // Database fetch constructor
58 public Publication () {
59 // ------------------------
62 // Internal constructors
63 public Publication (final Document doc, final ProjectElement publisher) {
64 // --------------------------------------------------------------
70 // ==============================================================================================================================
72 // ==============================================================================================================================
74 public Relation addDependency (final Publication to) {
75 // ----------------------------------------------
76 return this.addDependency(to.value());
79 public Relation addDependency (final Document to) {
80 // -------------------------------------------
84 return mydoc.addRelation( new UsesRelation(mydoc, to) );
89 * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
90 * which the referenced document has been published.<br/>
91 * If this publication belongs to a Study, the Project Element returned is the Study returned by getOwnerStudy().
93 * @return the Study Scenario or the Study to which this publication belongs to
94 * @see #getOwnerStudy()
96 public ProjectElement getOwner () {
97 // ---------------------------------
103 * @param owner the owner to set
105 public void setOwner(final ProjectElement owner) {
109 public Study getOwnerStudy () {
110 // -----------------------------
111 if (owner instanceof Study) {
114 return ((Scenario)owner).getOwnerStudy();
119 * Returns the state of this published document.
120 * It is the same than the state of the referenced document, unless this publication is out-of-date, in which case it is
126 public ProgressState getProgressState () {
127 // ----------------------------------------
128 if (this.isOutdated()) {
129 return ProgressState.inWORK; // Overrides the document state
131 return mydoc.getProgressState();
135 public List<Publication> getRelations (final Class<? extends Relation> type) {
136 // ----------------------------------------------------------------------
141 List<Publication> result = new ArrayList<Publication>();
142 List<Relation> relist = mydoc.getRelations(type);
143 for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
144 Relation relation = i.next();
145 Document relatedoc = (Document)relation.getTo();
146 Publication related = owner.getPublication(relatedoc);
147 if (related != null) {
149 } else if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
150 related = ((Scenario)owner).getOwnerStudy().getPublication(relatedoc);
151 if (related != null) {
159 public File getSourceFile () {
160 // ----------------------------
161 return mydoc.getSourceFile();
164 public boolean isNewForOwner () {
165 // -------------------------------
166 return (isnew == 'Y');
169 public boolean isOutdated () {
170 // ----------------------------
171 return (isnew == 'O');
178 public char getIsnew() {
183 * @param isnew the isnew to set
185 public void setIsnew(final char isnew) {
190 * Returns the document version referenced by this Publication.
192 public Document value () {
193 // ------------------------
198 * @param mydoc the mydoc to set
200 public void setValue (final Document aDoc) {