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.io.FileNotFoundException;
21 import java.util.ArrayList;
22 import java.util.Date;
23 import java.util.Iterator;
24 import java.util.List;
26 import org.hibernate.Session;
27 import org.splat.dal.bo.kernel.Persistent;
28 import org.splat.dal.bo.kernel.Relation;
29 import org.splat.dal.bo.kernel.User;
30 import org.splat.dal.dao.som.Database;
31 import org.splat.kernel.InvalidPropertyException;
32 import org.splat.kernel.NotApplicableException;
33 import org.splat.manox.Reader;
34 import org.splat.manox.Toolbox;
35 import org.splat.som.DocumentRights;
36 import org.splat.som.Revision;
37 import org.splat.som.Step;
40 public class Publication extends Persistent {
43 private Document mydoc;
44 private ProjectElement owner; // Either Study or Scenario, depending on the step involved by the publication
45 private char isnew; // True if this references a document version new for the owner project element
50 // ==============================================================================================================================
52 // ==============================================================================================================================
58 public Step getStep() {
63 * @param aStep the mystep to set
65 public void setStep(Step aStep) {
68 // Database fetch constructor
69 public Publication () {
70 // ------------------------
73 // Internal constructors
74 public Publication (Document doc, ProjectElement publisher) {
75 // --------------------------------------------------------------
81 // ==============================================================================================================================
83 // ==============================================================================================================================
85 public Relation addDependency (Publication to) {
86 // ----------------------------------------------
87 return this.addDependency(to.value());
90 public Relation addDependency (Document to) {
91 // -------------------------------------------
92 if (to == null) return null;
93 else return mydoc.addRelation( new UsesRelation(mydoc, to) );
97 * Undo the out-date operation.
99 * @return true if the acceptance succeeds
101 * @see DocumentRights#canAccept()
103 public boolean actualize () {
104 // ---------------------------
105 if (!this.isOutdated()) return false;
107 Database.getSession().update(this);
111 public ConvertsRelation attach (String format) {
112 // ----------------------------------------------
113 return mydoc.attach(format);
116 public ConvertsRelation attach (String format, String description) {
117 // ------------------------------------------------------------------
118 return mydoc.attach(format, description);
122 * Returns either the Study Scenario or the Study itself to which this publication belongs, depending on the Study Step into
123 * which the referenced document has been published.<br/>
124 * If this publication belongs to a Study, the Project Element returned is the Study returned by getOwnerStudy().
126 * @return the Study Scenario or the Study to which this publication belongs to
127 * @see #getOwnerStudy()
129 public ProjectElement getOwner () {
130 // ---------------------------------
136 * @param owner the owner to set
138 public void setOwner(ProjectElement owner) {
142 public Study getOwnerStudy () {
143 // -----------------------------
144 if (owner instanceof Study) return (Study)owner;
145 else return ((Scenario)owner).getOwnerStudy();
149 * Returns the state of this published document.
150 * It is the same than the state of the referenced document, unless this publication is out-of-date, in which case it is
156 public ProgressState getProgressState () {
157 // ----------------------------------------
158 if (this.isOutdated()) return ProgressState.inWORK; // Overrides the document state
159 else return mydoc.getProgressState();
162 public List<Publication> getRelations (Class<? extends Relation> type) {
163 // ----------------------------------------------------------------------
164 if (type == null) return null;
166 List<Publication> result = new ArrayList<Publication>();
167 List<Relation> relist = mydoc.getRelations(type);
168 for (Iterator<Relation> i=relist.iterator(); i.hasNext();) {
169 Relation relation = i.next();
170 Document relatedoc = (Document)relation.getTo();
171 Publication related = owner.getPublication(relatedoc);
172 if (related != null) {
175 if (owner instanceof Scenario) { // The relation may cross steps belonging to a scenario and its owner study
176 related = ((Scenario)owner).getOwnerStudy().getPublication(relatedoc);
177 if (related != null) result.add(related);
183 public File getSourceFile () {
184 // ----------------------------
185 return mydoc.getSourceFile();
188 public boolean isNewForOwner () {
189 // -------------------------------
190 return (isnew == 'Y');
193 public boolean isOutdated () {
194 // ----------------------------
195 return (isnew == 'O');
202 public char getIsnew() {
207 * @param isnew the isnew to set
209 public void setIsnew(char isnew) {
212 public void rename (String title) throws InvalidPropertyException {
213 // ---------------------------------
218 * Out-dates this publication and recursively all publications using this one.
219 * Typically, a publication is out-dated when modifying a document to which it depends.
222 * @see #getProgressState()
225 public void outdate () {
226 // ----------------------
227 if (this.isOutdated()) return;
229 List<Publication> relist = this.getRelations(UsedByRelation.class);
230 for (Iterator<Publication> i = relist.iterator(); i.hasNext(); ) {
234 Database.getSession().update(this);
238 * Returns the document version referenced by this Publication.
240 public Document value () {
241 // ------------------------
246 * @param mydoc the mydoc to set
248 public void setValue (Document aDoc) {