import java.util.List;
import java.util.Vector;
+import org.splat.dal.bo.kernel.Entity;
import org.splat.dal.bo.kernel.Persistent;
import org.splat.dal.bo.kernel.Relation;
import org.splat.dal.bo.kernel.User;
import org.splat.kernel.MissedPropertyException;
import org.splat.kernel.MultiplyDefinedException;
import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.ProjectSettingsServiceImpl;
import org.splat.som.Revision;
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
// - Public services
+ @Override
public void clear() {
super.clear();
type = null;
// - Property setters
- public Properties setAuthor(User user) {
+ public Properties setAuthor(final User user) {
this.author = user;
return this;
}
- public Properties setDate(Date date) {
+ public Properties setDate(final Date date) {
this.date = date;
return this;
}
/**
* Get the date.
+ *
* @return the date
*/
public Date getDate() {
return date;
}
- public Properties setDescription(String summary)
+ public Properties setDescription(final String summary)
throws InvalidPropertyException {
- if (summary.length() == 0)
+ if (summary.length() == 0) {
throw new InvalidPropertyException("description");
+ }
this.summary = summary;
return this;
}
- public Properties setDocument(Document base) {
+ /**
+ * 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 = ProjectSettingsServiceImpl.getStep(base.step);
+ step = aStep;
name = base.name;
format = base.getFormat();
state = ProgressState.inWORK; // For incrementing the version number at save time
return this;
}
- public Properties setExternReference(String ref)
+ public Properties setExternReference(final String ref)
throws InvalidPropertyException {
- if (ref.length() == 0)
+ if (ref.length() == 0) {
throw new InvalidPropertyException("reference");
- if (ref.equals(new Revision().toString()))
+ }
+ if (ref.equals(new Revision().toString())) {
throw new InvalidPropertyException("reference"); // Internal version number
+ }
this.version = ref;
return this;
}
- public Properties setFormat(String format)
+ public Properties setFormat(final String format)
throws InvalidPropertyException {
- if (format.length() == 0)
+ if (format.length() == 0) {
throw new InvalidPropertyException("format");
+ }
this.format = format;
return this;
}
// Required only for passing search arguments
- public Properties setLocalPath(String path)
+ public Properties setLocalPath(final String path)
throws InvalidPropertyException {
- if (path.length() == 0)
+ if (path.length() == 0) {
throw new InvalidPropertyException("path");
+ }
this.path = path;
return this;
}
- public Properties setName(String name) throws InvalidPropertyException {
- if (name.length() == 0)
+ 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 Properties setOwner(ProjectElement owner) {
+ public Properties setOwner(final ProjectElement owner) {
this.owner = owner;
return this;
}
public ProjectElement getOwner() {
return this.owner;
}
+
// Required only for passing search arguments
- public Properties setReference(String did)
+ public Properties setReference(final String did)
throws InvalidPropertyException {
- if (did.length() == 0)
+ if (did.length() == 0) {
throw new InvalidPropertyException("reference");
+ }
this.did = did;
return this;
}
- public Properties setState(ProgressState state)
+ public Properties setState(final ProgressState state)
throws InvalidPropertyException {
if (state == ProgressState.inPROGRESS
- || state == ProgressState.TEMPLATE)
+ || state == ProgressState.TEMPLATE) {
throw new InvalidPropertyException("state"); // Non document states
+ }
this.state = state;
return this;
}
- public Properties setStep(ProjectSettingsService.Step step) {
+ public Properties setStep(final ProjectSettingsService.Step step) {
this.step = step;
return this;
}
- public Properties setType(DocumentType type) {
+ public Properties setType(final DocumentType type) {
this.type = type;
return this;
}
public void checkValidity() throws MissedPropertyException,
InvalidPropertyException, MultiplyDefinedException {
- if (type == null)
+ if (type == null) {
throw new MissedPropertyException("type");
- if (owner == null)
+ }
+ if (owner == null) {
throw new MissedPropertyException("owner");
- if (step == null)
+ }
+ if (step == null) {
throw new MissedPropertyException("step");
- if (author == null)
+ }
+ if (author == null) {
throw new MissedPropertyException("author");
- if (format == null)
+ }
+ if (format == null) {
throw new MissedPropertyException("format");
- if (owner instanceof Study && !step.appliesTo(Study.class))
+ }
+ if (owner instanceof Study && !step.appliesTo(Study.class)) {
throw new InvalidPropertyException("step");
- if (!type.isContentInto(step))
+ }
+ if (!type.isContentInto(step)) {
throw new InvalidPropertyException("step");
+ }
if (state != null && state != ProgressState.EXTERN) {
// inDRAFT, inCHECK or APPROVED + version = imposed version (future use)
// inWORK + version = base version incremented at save time (used for versioning)
- if (version == null)
+ if (version == null) {
throw new InvalidPropertyException("state");
+ }
}
if (version != null) {
- if (state == null)
+ if (state == null) {
state = ProgressState.EXTERN;
+ }
}
}
+
+ /**
+ * Get the format.
+ *
+ * @return the format
+ */
+ public String getFormat() {
+ return format;
+ }
}
- // Database fetch constructor
+ /**
+ * Database fetch constructor.
+ */
protected Document() {
+ super();
}
- // Internal constructor
- public Document(Properties dprop) throws MissedPropertyException,
+ /**
+ * 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
// ==============================================================================================================================
- public File getAttachedFile(String format) {
- // -------------------------------------------
+ /**
+ * 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();
- if (export.getFormat().equals(format))
- return export;
+ File res = null;
+ for (Relation rel : exports) {
+ File export = (File) rel.getTo();
+ if (export.getFormat().equals(format)) {
+ 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(Date aDate) {
+
+ 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 (Document) previous.getTo();
- else
+ if (previous == null) {
return null;
+ } else {
+ return (Document) previous.getTo();
+ }
}
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++)
+ for (int i = 1; i < table.length - 1; i++) {
path.append('.').append(table[i]);
+ }
return path.toString();
}
* @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
.hasNext();) {
Relation link = i.next();
- if (link instanceof StampRelation)
+ if (link instanceof StampRelation) {
stamps.add(((StampRelation) link).getTo());
+ }
}
Timestamp[] result = stamps.toArray(new Timestamp[stamps.size()]);
ComparatorByDate bydate = new Timestamp.ComparatorByDate();
*/
public String getTitle() {
// -------------------------
- if (this.isUndefined())
+ if (this.isUndefined()) {
return "";
- else
+ } else {
return name;
+ }
}
-
+
/**
* Set document title.
- * @param aTitle document title to set
+ *
+ * @param aTitle
+ * document title to set
*/
- public void setTitle(String aTitle) {
+ 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(Step container) {
- // --------------------------------------
+ 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(int step) {
+ 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(String did) {
+ 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(File myfile) {
+ 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(int history) {
+ 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(String version) {
+ 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(ProgressState state) {
+ 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(int countag) {
+ public void setCountag(final int countag) {
this.countag = countag;
}
}
\ No newline at end of file