import org.splat.som.Step;
/**
- * Document persistent class.
+ * Document persistent class.
*/
public class Document extends Entity {
// ==============================================================================================================================
/**
- * Fields initialization class.
+ * Fields initialization class.
*/
public static class Properties extends Persistent.Properties {
- // ------------------------------------------------------------
private DocumentType type = null;
private String did = null; // Only for searching from a given reference
private ProjectElement owner = null; // Only for constructing a document
/**
* Get the date.
+ *
* @return the date
*/
public Date getDate() {
return this;
}
- public Properties setDocument(final Document base, final ProjectSettingsService.Step aStep) {
+ /**
+ * Copy base properties from the given original document for versioning.
+ *
+ * @param base
+ * the original document
+ * @param aStep
+ * study step
+ * @return document properties
+ */
+ public Properties setDocument(final Document base,
+ final ProjectSettingsService.Step aStep) {
type = base.type;
step = aStep;
name = base.name;
return this;
}
- public Properties setName(final String name) throws InvalidPropertyException {
+ public Properties setName(final String name)
+ throws InvalidPropertyException {
if (name.length() == 0) {
throw new InvalidPropertyException("name");
}
this.name = name;
return this;
}
-
+
public String getName() {
return this.name;
}
public ProjectElement getOwner() {
return this.owner;
}
+
// Required only for passing search arguments
public Properties setReference(final String did)
throws InvalidPropertyException {
}
}
}
+
+ /**
+ * Get the format.
+ *
+ * @return the format
+ */
+ public String getFormat() {
+ return format;
+ }
}
+ /**
+ * Database fetch constructor.
+ */
protected Document() {
- // Database fetch constructor
+ super();
}
- // Internal constructor
+ /**
+ * Initialization constructor.
+ *
+ * @param dprop
+ * @throws MissedPropertyException
+ * @throws InvalidPropertyException
+ * @throws MultiplyDefinedException
+ */
public Document(final Properties dprop) throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
- // -------------------------------------
super(dprop); // Throws one of the above exception if not valid
- myfile = new File(null, dprop.format, dprop.date); // The path is initialized below
+ myfile = new File(dprop.getLocalPath(), dprop.format, dprop.date); // The path is initialized below
type = dprop.type;
step = dprop.step.getNumber();
name = dprop.name;
// Public member functions
// ==============================================================================================================================
+ /**
+ * Get the attached file of the given format.
+ *
+ * @param format
+ * the file format
+ * @return the attached file or null if not found
+ */
public File getAttachedFile(final String format) {
- // -------------------------------------------
List<Relation> exports = getRelations(ConvertsRelation.class);
-
- for (Iterator<Relation> i = exports.iterator(); i.hasNext();) {
- File export = (File) i.next().getTo();
+ File res = null;
+ for (Relation rel : exports) {
+ File export = (File) rel.getTo();
if (export.getFormat().equals(format)) {
- return export;
+ res = export;
+ break;
}
}
- return null;
+ return res;
}
public User getAuthor() {
- // ------------------------
return author;
}
public Date getCreationDate() {
- // ------------------------------
return myfile.getDate();
}
public Date getLastModificationDate() {
- // --------------------------------------
return lasdate;
}
-
+
public void setLastModificationDate(final Date aDate) {
lasdate = aDate;
}
public String getFormat() {
- // --------------------------
return myfile.getFormat();
}
public Document getPreviousVersion() {
- // -------------------------------------
Relation previous = getFirstRelation(VersionsRelation.class);
if (previous == null) {
return null;
}
public ProgressState getProgressState() {
- // ----------------------------------------
return state;
}
* @return the path of the document
*/
public String getRelativePath() {
- // --------------------------------
String[] table = myfile.getRelativePath().split("\\x2E");
StringBuffer path = new StringBuffer(table[0]);
for (int i = 1; i < table.length - 1; i++) {
* @return the document reference
*/
public String getReference() {
- // -----------------------------
return did;
}
public File getSourceFile() {
- // ----------------------------
return myfile;
}
* @return the stamps of the document in ascending order of dates, or an empty array if no stamp exist.
*/
public Timestamp[] getStamps() {
- // -------------------------------
Vector<Timestamp> stamps = new Vector<Timestamp>();
for (Iterator<Relation> i = this.getAllRelations().iterator(); i
return name;
}
}
-
+
/**
* Set document title.
- * @param aTitle document title to set
+ *
+ * @param aTitle
+ * document title to set
*/
public void setTitle(final String aTitle) {
this.name = aTitle;
}
public DocumentType getType() {
- // ------------------------------
return type;
}
* @see #isUndefined()
*/
public String getVersion() {
- // ---------------------------
return version;
}
* @see #initialize(Properties)
*/
public boolean isUndefined() {
- // -----------------------------
return (history == -1);
}
public boolean isInto(final Step container) {
- // --------------------------------------
return (step == container.getNumber());
}
public boolean isPublished() {
- // -----------------------------
return (countag > 0);
}
public boolean isShared() {
- // --------------------------
return (countag + history > 1);
}
public boolean isVersioned() {
- // -----------------------------
return (history > 0);
}
/**
* Get the step.
+ *
* @return the step
*/
public int getStep() {
/**
* Set the step.
- * @param step the step to set
+ *
+ * @param step
+ * the step to set
*/
public void setStep(final int step) {
this.step = step;
/**
* Get the did.
+ *
* @return the did
*/
public String getDid() {
/**
* Set the did.
- * @param did the did to set
+ *
+ * @param did
+ * the did to set
*/
public void setDid(final String did) {
this.did = did;
/**
* Get the myfile.
+ *
* @return the myfile
*/
public File getFile() {
/**
* Set the myfile.
- * @param myfile the myfile to set
+ *
+ * @param myfile
+ * the myfile to set
*/
public void setFile(final File myfile) {
this.myfile = myfile;
/**
* Get the history.
+ *
* @return the history
*/
public int getHistory() {
/**
* Set the history.
- * @param history the history to set
+ *
+ * @param history
+ * the history to set
*/
public void setHistory(final int history) {
this.history = history;
/**
* Set the version.
- * @param version the version to set
+ *
+ * @param version
+ * the version to set
*/
public void setVersion(final String version) {
this.version = version;
/**
* Set the state.
- * @param state the state to set
+ *
+ * @param state
+ * the state to set
*/
public void setProgressState(final ProgressState state) {
this.state = state;
/**
* Get the countag.
+ *
* @return the countag
*/
public int getCountag() {
/**
* Set the countag.
- * @param countag the countag to set
+ *
+ * @param countag
+ * the countag to set
*/
public void setCountag(final int countag) {
this.countag = countag;