1 package org.splat.dal.bo.som;
4 * Publication objects are the way to reference document versions from a Project Element.
5 * As such, a Document version is added (or published) to a Project Element through a Publication object.
6 * This publication is done by saving the Publication object produced when creating and versioning a Document from a given
7 * Project Element Step (call of the saveAs() function).<br/>
9 * A Publication object is homogeneous to a reference to a Document version and belongs to one Project Element, this latter
10 * being either a Study Scenario or a Study itself, depending on the Study Step to which the document is published.<br/>
12 * The document version referenced by a Publication object is the Value of the publication.
17 * @author Daniel Brunier-Coulin
18 * @copyright OPEN CASCADE 2012
21 import java.util.ArrayList;
22 import java.util.Iterator;
23 import java.util.List;
25 import org.splat.dal.bo.kernel.Persistent;
26 import org.splat.dal.bo.kernel.Relation;
27 import org.splat.som.Step;
30 * Persistent class representing a tag of a document published in a
31 * study/scenario activity.
33 public class Publication extends Persistent {
37 * Persistent field. The published document.
39 private Document mydoc;
41 * Persistent field. Either Study or Scenario, depending on the step
42 * involved by the publication.
44 private ProjectElement owner;
46 * Persistent field. True if this references a document version new for the
47 * owner project element.
53 * Transient field. The step where the document is published.
57 // ==============================================================================================================================
59 // ==============================================================================================================================
66 public Step getStep() {
76 public void setStep(final Step aStep) {
81 * Database fetch constructor.
83 public Publication() {
89 * Internal constructors.
92 * the published document
94 * the project element where the document is published
96 public Publication(final Document doc, final ProjectElement publisher) {
104 // ==============================================================================================================================
106 // ==============================================================================================================================
108 public Relation addDependency(final Publication to) {
109 return this.addDependency(to.value());
112 public Relation addDependency(final Document to) {
115 res = mydoc.addRelation(new UsesRelation(mydoc, to));
121 * Returns either the Study Scenario or the Study itself to which this
122 * publication belongs, depending on the Study Step into which the
123 * referenced document has been published.<br/>
124 * If this publication belongs to a Study, the Project Element returned is
125 * the Study returned by getOwnerStudy().
127 * @return the Study Scenario or the Study to which this publication belongs
129 * @see #getOwnerStudy()
131 public ProjectElement getOwner() {
141 public void setOwner(final ProjectElement owner) {
146 * Returns the study where the document is published.
148 * @return the owner study
150 public Study getOwnerStudy() {
151 return owner.getOwnerStudy();
155 * Returns the state of this published document. It is the same than the
156 * state of the referenced document, unless this publication is out-of-date,
157 * in which case it is In-Work state.
161 * @return the document progress state
163 public ProgressState getProgressState() {
165 if (this.isOutdated()) {
166 res = ProgressState.inWORK; // Overrides the document state
168 res = mydoc.getProgressState();
173 public List<Publication> getRelations(final Class<? extends Relation> type) {
174 List<Publication> result = null;
176 result = new ArrayList<Publication>();
177 List<Relation> relist = mydoc.getRelations(type);
178 for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
179 Relation relation = i.next();
180 Document relatedoc = (Document) relation.getTo();
181 Publication related = owner.getPublication(relatedoc);
183 // Try to find the publication in scenarios
184 List<Scenario> list = owner.getOwnerStudy().getScenariiList();
185 if (related == null) {
186 for (Scenario scen : list) {
187 related = scen.getPublication(relatedoc);
192 if (related == null) {
193 // If not found try to find the publication in the study
194 if (owner instanceof Scenario) {
195 related = owner.getOwnerStudy().getPublication(
200 if (related != null) {
209 public File getSourceFile() {
210 return mydoc.getSourceFile();
213 public boolean isNewForOwner() {
214 return (isnew == 'Y');
217 public boolean isOutdated() {
218 return (isnew == 'O');
226 public char getIsnew() {
236 public void setIsnew(final char isnew) {
241 * Returns the document version referenced by this Publication.
243 public Document value() {
253 public void setValue(final Document aDoc) {
260 * @see org.splat.dal.bo.kernel.Persistent#evict()
263 public void evict() {
265 // Evict the document
266 if (value() != null) {