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(Step aStep) {
57 // Database fetch constructor
58 public Publication () {
59 // ------------------------
62 // Internal constructors
63 public Publication (Document doc, ProjectElement publisher) {
64 // --------------------------------------------------------------
70 // ==============================================================================================================================
72 // ==============================================================================================================================
74 public Relation addDependency (Publication to) {
75 // ----------------------------------------------
76 return this.addDependency(to.value());
79 public Relation addDependency (Document to) {
80 // -------------------------------------------
81 if (to == null) return null;
82 else return mydoc.addRelation( new UsesRelation(mydoc, to) );
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().
90 * @return the Study Scenario or the Study to which this publication belongs to
91 * @see #getOwnerStudy()
93 public ProjectElement getOwner () {
94 // ---------------------------------
100 * @param owner the owner to set
102 public void setOwner(ProjectElement owner) {
106 public Study getOwnerStudy () {
107 // -----------------------------
108 if (owner instanceof Study) return (Study)owner;
109 else return ((Scenario)owner).getOwnerStudy();
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
120 public ProgressState getProgressState () {
121 // ----------------------------------------
122 if (this.isOutdated()) return ProgressState.inWORK; // Overrides the document state
123 else return mydoc.getProgressState();
126 public List<Publication> getRelations (Class<? extends Relation> type) {
127 // ----------------------------------------------------------------------
128 if (type == null) return null;
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) {
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);
147 public File getSourceFile () {
148 // ----------------------------
149 return mydoc.getSourceFile();
152 public boolean isNewForOwner () {
153 // -------------------------------
154 return (isnew == 'Y');
157 public boolean isOutdated () {
158 // ----------------------------
159 return (isnew == 'O');
166 public char getIsnew() {
171 * @param isnew the isnew to set
173 public void setIsnew(char isnew) {
178 * Returns the document version referenced by this Publication.
180 public Document value () {
181 // ------------------------
186 * @param mydoc the mydoc to set
188 public void setValue (Document aDoc) {