import org.splat.som.Step;
/**
- * Persistent class representing a tag of a document published in a study/scenario activity.
+ * Persistent class representing a tag of a document published in a
+ * study/scenario activity.
*/
public class Publication extends Persistent {
- // Persistent fields
- /**
- * Persistent field. The published document.
- */
- private Document mydoc;
- /**
- * Persistent field. Either Study or Scenario, depending on the step involved by the publication.
- */
- private ProjectElement owner;
- /**
- * Persistent field. True if this references a document version new for the owner project element.
- */
- private char isnew;
-
- // Transient fields
- /**
- * Transient field. The step where the document is published.
- */
- private Step mystep;
-
- // ==============================================================================================================================
- // Construction
- // ==============================================================================================================================
-
- /**
- * Get the mystep.
- *
- * @return the mystep
- */
- public Step getStep() {
- return mystep;
- }
-
- /**
- * Set the mystep.
- *
- * @param aStep
- * the mystep to set
- */
- public void setStep(final Step aStep) {
- this.mystep = aStep;
- }
-
- /**
- * Database fetch constructor.
- */
- public Publication() {
- super();
- mystep = null;
- }
-
- /**
- * Internal constructors.
- *
- * @param doc
- * the published document
- * @param publisher
- * the project element where the document is published
- */
- public Publication(final Document doc, final ProjectElement publisher) {
- super();
- mydoc = doc;
- mystep = null;
- owner = publisher;
- isnew = 'Y';
- }
-
- // ==============================================================================================================================
- // Member functions
- // ==============================================================================================================================
-
- public Relation addDependency(final Publication to) {
- return this.addDependency(to.value());
- }
-
- public Relation addDependency(final Document to) {
- Relation res = null;
- if (to != null) {
- res = mydoc.addRelation(new UsesRelation(mydoc, to));
- }
- return res;
- }
-
- /**
- * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into which the
- * referenced document has been published.<br/> If this publication belongs to a Study, the Project Element returned is the Study
- * returned by getOwnerStudy().
- *
- * @return the Study Scenario or the Study to which this publication belongs to
- * @see #getOwnerStudy()
- */
- public ProjectElement getOwner() {
- return owner;
- }
-
- /**
- * Set the owner.
- *
- * @param owner
- * the owner to set
- */
- public void setOwner(final ProjectElement owner) {
- this.owner = owner;
- }
-
- /**
- * Returns the study where the document is published.
- *
- * @return the owner study
- */
- public Study getOwnerStudy() {
- return owner.getOwnerStudy();
- }
-
- /**
- * Returns the state of this published document. It is the same than the state of the referenced document, unless this publication is
- * out-of-date, in which case it is In-Work state.
- *
- * @see #outdate()
- * @see #isOutdated()
- * @return the document progress state
- */
- public ProgressState getProgressState() {
- ProgressState res;
- if (this.isOutdated()) {
- res = ProgressState.inWORK; // Overrides the document state
- } else {
- res = mydoc.getProgressState();
- }
- return res;
- }
-
- public List<Publication> getRelations(final Class<? extends Relation> type) {
- if (type == null) {
- return null;
- }
-
- List<Publication> result = new ArrayList<Publication>();
- List<Relation> relist = mydoc.getRelations(type);
- for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
- Relation relation = i.next();
- Document relatedoc = (Document) relation.getTo();
- Publication related = owner.getPublication(relatedoc);
- if (related != null) {
- result.add(related);
- } else if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
- related = owner.getOwnerStudy().getPublication(relatedoc);
- if (related != null) {
+ // Persistent fields
+ /**
+ * Persistent field. The published document.
+ */
+ private Document mydoc;
+ /**
+ * Persistent field. Either Study or Scenario, depending on the step
+ * involved by the publication.
+ */
+ private ProjectElement owner;
+ /**
+ * Persistent field. True if this references a document version new for the
+ * owner project element.
+ */
+ private char isnew;
+
+ // Transient fields
+ /**
+ * Transient field. The step where the document is published.
+ */
+ private Step mystep;
+
+ // ==============================================================================================================================
+ // Construction
+ // ==============================================================================================================================
+
+ /**
+ * Get the mystep.
+ *
+ * @return the mystep
+ */
+ public Step getStep() {
+ return mystep;
+ }
+
+ /**
+ * Set the mystep.
+ *
+ * @param aStep
+ * the mystep to set
+ */
+ public void setStep(final Step aStep) {
+ this.mystep = aStep;
+ }
+
+ /**
+ * Database fetch constructor.
+ */
+ public Publication() {
+ super();
+ mystep = null;
+ }
+
+ /**
+ * Internal constructors.
+ *
+ * @param doc
+ * the published document
+ * @param publisher
+ * the project element where the document is published
+ */
+ public Publication(final Document doc, final ProjectElement publisher) {
+ super();
+ mydoc = doc;
+ mystep = null;
+ owner = publisher;
+ isnew = 'Y';
+ }
+
+ // ==============================================================================================================================
+ // Member functions
+ // ==============================================================================================================================
+
+ public Relation addDependency(final Publication to) {
+ return this.addDependency(to.value());
+ }
+
+ public Relation addDependency(final Document to) {
+ Relation res = null;
+ if (to != null) {
+ res = mydoc.addRelation(new UsesRelation(mydoc, to));
+ }
+ return res;
+ }
+
+ /**
+ * Returns either the Study Scenario or the Study itself to which this
+ * publication belongs, depending on the Study Step into which the
+ * referenced document has been published.<br/>
+ * If this publication belongs to a Study, the Project Element returned is
+ * the Study returned by getOwnerStudy().
+ *
+ * @return the Study Scenario or the Study to which this publication belongs
+ * to
+ * @see #getOwnerStudy()
+ */
+ public ProjectElement getOwner() {
+ return owner;
+ }
+
+ /**
+ * Set the owner.
+ *
+ * @param owner
+ * the owner to set
+ */
+ public void setOwner(final ProjectElement owner) {
+ this.owner = owner;
+ }
+
+ /**
+ * Returns the study where the document is published.
+ *
+ * @return the owner study
+ */
+ public Study getOwnerStudy() {
+ return owner.getOwnerStudy();
+ }
+
+ /**
+ * Returns the state of this published document. It is the same than the
+ * state of the referenced document, unless this publication is out-of-date,
+ * in which case it is In-Work state.
+ *
+ * @see #outdate()
+ * @see #isOutdated()
+ * @return the document progress state
+ */
+ public ProgressState getProgressState() {
+ ProgressState res;
+ if (this.isOutdated()) {
+ res = ProgressState.inWORK; // Overrides the document state
+ } else {
+ res = mydoc.getProgressState();
+ }
+ return res;
+ }
+
+ public List<Publication> getRelations(final Class<? extends Relation> type) {
+ List<Publication> result = null;
+ if (type != null) {
+ result = new ArrayList<Publication>();
+ List<Relation> relist = mydoc.getRelations(type);
+ for (Iterator<Relation> i = relist.iterator(); i.hasNext();) {
+ Relation relation = i.next();
+ Document relatedoc = (Document) relation.getTo();
+ Publication related = owner.getPublication(relatedoc);
+
+ // Try to find the publication in scenarios
+ List<Scenario> list = owner.getOwnerStudy().getScenariiList();
+ if (related == null) {
+ for (Scenario scen : list) {
+ related = scen.getPublication(relatedoc);
+ break;
+ }
+ }
+
+ if (related == null) {
+ // If not found try to find the publication in the study
+ if (owner instanceof Scenario) {
+ related = owner.getOwnerStudy().getPublication(
+ relatedoc);
+ }
+ }
+
+ if (related != null) {
result.add(related);
}
- }
- }
- return result;
- }
-
- public File getSourceFile() {
- return mydoc.getSourceFile();
- }
-
- public boolean isNewForOwner() {
- return (isnew == 'Y');
- }
-
- public boolean isOutdated() {
- return (isnew == 'O');
- }
-
- /**
- * Get the isnew.
- *
- * @return the isnew
- */
- public char getIsnew() {
- return isnew;
- }
-
- /**
- * Set the isnew.
- *
- * @param isnew
- * the isnew to set
- */
- public void setIsnew(final char isnew) {
- this.isnew = isnew;
- }
-
- /**
- * Returns the document version referenced by this Publication.
- */
- public Document value() {
- return mydoc;
- }
-
- /**
- * Set the mydoc.
- *
- * @param mydoc
- * the mydoc to set
- */
- public void setValue(final Document aDoc) {
- this.mydoc = aDoc;
- }
-
- /**
- * {@inheritDoc}
- *
- * @see org.splat.dal.bo.kernel.Persistent#evict()
- */
- @Override
- public void evict() {
- super.evict();
- // Evict the document
- if (value() != null) {
- value().evict();
- }
- }
-}
\ No newline at end of file
+ }
+ }
+ return result;
+
+ }
+
+ public File getSourceFile() {
+ return mydoc.getSourceFile();
+ }
+
+ public boolean isNewForOwner() {
+ return (isnew == 'Y');
+ }
+
+ public boolean isOutdated() {
+ return (isnew == 'O');
+ }
+
+ /**
+ * Get the isnew.
+ *
+ * @return the isnew
+ */
+ public char getIsnew() {
+ return isnew;
+ }
+
+ /**
+ * Set the isnew.
+ *
+ * @param isnew
+ * the isnew to set
+ */
+ public void setIsnew(final char isnew) {
+ this.isnew = isnew;
+ }
+
+ /**
+ * Returns the document version referenced by this Publication.
+ */
+ public Document value() {
+ return mydoc;
+ }
+
+ /**
+ * Set the mydoc.
+ *
+ * @param mydoc
+ * the mydoc to set
+ */
+ public void setValue(final Document aDoc) {
+ this.mydoc = aDoc;
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.dal.bo.kernel.Persistent#evict()
+ */
+ @Override
+ public void evict() {
+ super.evict();
+ // Evict the document
+ if (value() != null) {
+ value().evict();
+ }
+ }
+}