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 study/scenario activity.
32 public class Publication extends Persistent {
36 * Persistent field. The published document.
38 private Document mydoc;
40 * Persistent field. Either Study or Scenario, depending on the step involved by the publication.
42 private ProjectElement owner;
44 * Persistent field. True if this references a document version new for the owner project element.
50 * Transient field. The step where the document is published.
54 // ==============================================================================================================================
56 // ==============================================================================================================================
63 public Step getStep() {
73 public void setStep(final Step aStep) {
78 * Database fetch constructor.
80 public Publication() {
86 * Internal constructors.
89 * the published document
91 * the project element where the document is published
93 public Publication(final Document doc, final ProjectElement publisher) {
101 // ==============================================================================================================================
103 // ==============================================================================================================================
105 public Relation addDependency(final Publication to) {
106 return this.addDependency(to.value());
109 public Relation addDependency(final Document to) {
112 res = mydoc.addRelation(new UsesRelation(mydoc, to));
118 * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into which the
119 * referenced document has been published.<br/> If this publication belongs to a Study, the Project Element returned is the Study
120 * returned by getOwnerStudy().
122 * @return the Study Scenario or the Study to which this publication belongs to
123 * @see #getOwnerStudy()
125 public ProjectElement getOwner() {
135 public void setOwner(final ProjectElement owner) {
140 * Returns the study where the document is published.
142 * @return the owner study
144 public Study getOwnerStudy() {
145 return owner.getOwnerStudy();
149 * Returns the state of this published document. It is the same than the state of the referenced document, unless this publication is
150 * out-of-date, in which case it is In-Work state.
154 * @return the document progress state
156 public ProgressState getProgressState() {
158 if (this.isOutdated()) {
159 res = ProgressState.inWORK; // Overrides the document state
161 res = mydoc.getProgressState();
166 public List<Publication> getRelations(final Class<? extends Relation> type) {
171 List<Publication> result = new ArrayList<Publication>();
172 List<Relation> relist = mydoc.getRelations(type);
173 for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
174 Relation relation = i.next();
175 Document relatedoc = (Document) relation.getTo();
176 Publication related = owner.getPublication(relatedoc);
177 if (related != null) {
179 } else if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
180 related = owner.getOwnerStudy().getPublication(relatedoc);
181 if (related != null) {
189 public File getSourceFile() {
190 return mydoc.getSourceFile();
193 public boolean isNewForOwner() {
194 return (isnew == 'Y');
197 public boolean isOutdated() {
198 return (isnew == 'O');
206 public char getIsnew() {
216 public void setIsnew(final char isnew) {
221 * Returns the document version referenced by this Publication.
223 public Document value() {
233 public void setValue(final Document aDoc) {
240 * @see org.splat.dal.bo.kernel.Persistent#evict()
243 public void evict() {
245 // Evict the document
246 if (value() != null) {