import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
-import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
*/
public class DocumentFacade implements HistoryFacade {
- private final AbstractOpenObject owner;
- private final Publication me;
- private final Document my; // Published document
- private ProgressState state; // Document state
- private String version; // My document version in customized format
- private State display; // Presentation state
- private String surl; // URL of the source file
- private String format; // Extension of the source file
- private String icon; // Corresponding icon
- private String sharing; // Icon qualifying sharing between scenarios of a same study
- private String updated; // Icon qualifying versioning from the previous study version
- private String size;
- private String date;
- private String description;
- private List<DocumentFacade> uses;
- private List<FileFacade> exports;
- private List<HistoryFacade> history;
- private PopupMenu popup;
+ /**
+ * Icon extension.
+ */
+ static private final String ICON_EXT = ".png";
+ /**
+ * Document's owner.
+ */
+ private final transient AbstractOpenObject _owner;
+ /**
+ * Wrapped document publication.
+ */
+ private final transient Publication _me;
+ /**
+ * Published document.
+ */
+ private final transient Document _mydoc;
+ /**
+ * Document state.
+ */
+ private transient ProgressState _state;
+ /**
+ * My document version in customized format.
+ */
+ private transient String _version;
+ /**
+ * Presentation state: open, deep open, closed.
+ *
+ * @see DocumentFacade.State
+ */
+ private transient State _display;
+ /**
+ * URL of the source file.
+ */
+ private transient String _surl;
+ /**
+ * Corresponding icon.
+ */
+ private transient String _icon;
+ /**
+ * Icon qualifying sharing between scenarios of a same study.
+ */
+ private transient String _sharing;
+ /**
+ * Icon qualifying versioning from the previous study version.
+ */
+ private transient String _updated;
+ /**
+ * Document size.
+ */
+ private transient String _size;
+ /**
+ * Document last modification date.
+ */
+ private transient String _date;
+ /**
+ * Document's description.
+ */
+ private transient String _description;
+ /**
+ * List of used documents presentations.
+ */
+ private transient List<DocumentFacade> _uses;
+ /**
+ * List of attached files presentations.
+ */
+ private transient List<FileFacade> _exports;
+ /**
+ * List of the document's history nodes.
+ */
+ private transient List<HistoryFacade> _history;
+ /**
+ * Document's popup menu.
+ */
+ private transient PopupMenu _popup;
/**
* Injected project settings service.
*/
- private ProjectSettingsService _projectSettingsService;
+ private ProjectSettingsService _projectSettings;
/**
* Injected publication service.
*/
*/
private ApplicationSettings _applicationSettings;
+ /**
+ * Document presentation state enumeration.
+ */
private enum State {
- closed, open, deepopen
+ /**
+ * Closed presentation state.
+ */
+ closed,
+ /**
+ * Open presentation state (history and attached files nodes are visible).
+ */
+ open,
+ /**
+ * Deeply open presentation.
+ */
+ deepopen
}
// ==============================================================================================================================
// Constructors
// ==============================================================================================================================
+ /**
+ * Constructor.
+ *
+ * @param opened
+ * document owner
+ * @param represented
+ * document presentation
+ * @param projectSettings
+ * project settings service
+ * @param publicationService
+ * publication service
+ * @param applicationSettings
+ * application settings
+ */
public DocumentFacade(final AbstractOpenObject opened,
final Publication represented,
final ProjectSettingsService projectSettings,
setProjectSettings(projectSettings);
setPublicationService(publicationService);
setApplicationSettings(applicationSettings);
- owner = opened;
- me = represented;
- my = me.value();
- state = my.getProgressState();
- display = State.closed;
- description = null;
- uses = null;
- exports = null;
- history = null;
- popup = null;
+ _owner = opened;
+ _me = represented;
+ _mydoc = _me.value();
+ _state = _mydoc.getProgressState();
+ _display = State.closed;
- this.refresh(); // Initializes the presentation of my document
+ refresh(); // Initializes the presentation of my document //NOPMD:RKV: to be reviewed
}
/**
* Constructs the facade of a document presented in the history folder.
*
+ * @param opened
+ * document owner
* @param represented
- * the represented history document
+ * document presentation
+ * @param projectSettings
+ * project settings service
+ * @param publicationService
+ * publication service
+ * @param applicationSettings
+ * application settings
*/
private DocumentFacade(final AbstractOpenObject opened,
final Document represented,
setProjectSettings(projectSettings);
setPublicationService(publicationService);
setApplicationSettings(applicationSettings);
- owner = opened;
- me = null; // Marks the history context
- my = represented;
- state = my.getProgressState(); // In reality, HISTORY
- display = State.open; // Because the given document is a history document
- description = ResourceBundle.getBundle("som",
+ _owner = opened;
+ _me = null; // Marks the history context
+ _mydoc = represented;
+ _state = _mydoc.getProgressState(); // In reality, HISTORY
+ _display = State.open; // Because the given document is a history document
+ _description = ResourceBundle.getBundle("som",
applicationSettings.getCurrentLocale()).getString(
"history.creation")
- + " " + my.getAuthor().toString();
- uses = null;
- exports = null;
- history = null;
- popup = null;
+ + " " + _mydoc.getAuthor().toString();
this.refresh(); // Initializes the presentation of my document
}
// Public member functions
// ==============================================================================================================================
+ /**
+ * Open the presentation subtree.
+ */
public void develop() {
- if (display != State.open) { // Opening the document
- if (uses == null) {
- List<Publication> relist = me.getRelations(UsesRelation.class);
-
- uses = new ArrayList<DocumentFacade>(relist.size());
- for (Iterator<Publication> i = relist.iterator(); i.hasNext();) {
- Publication used = i.next();
- long index = used.getIndex();
- DocumentFacade facade = owner.docpres
- .get(index);
+ if (_display == State.open) { // Opening the history of document, if exist
+ if (_history.isEmpty()) {
+ collectHistory(_mydoc);
+ }
+ _display = State.deepopen;
+ } else { // Opening the document
+ if (_uses == null) {
+ List<Relation> relist = _me.value().getRelations(UsesRelation.class);
+
+ _uses = new ArrayList<DocumentFacade>(relist.size());
+ for (Relation relation : relist) {
+ Document used = ((UsesRelation)relation).getTo();
+
+ DocumentFacade facade = null;
+
+ Publication publication = _me.getOwner().getPublication(used);
+ if(publication == null) {
+ publication = _me.getOwnerStudy().getPublication(used);
+ }
+ if(publication != null) {
+ facade = _owner._docpres.get(publication.getIndex());
+ }
+
if (facade == null) {
- facade = new DocumentFacade(owner, used,
+ facade = new DocumentFacade(_owner, used,
getProjectSettings(), getPublicationService(),
getApplicationSettings());
- owner.docpres.put(index, facade);
}
- uses.add(facade);
+ _uses.add(facade);
}
}
- if (exports == null) {
- List<Relation> relation = my
- .getRelations(ConvertsRelation.class);
-
- exports = new ArrayList<FileFacade>(relation.size());
- for (Iterator<Relation> i = relation.iterator(); i.hasNext();) {
- ConvertsRelation export = (ConvertsRelation) i.next();
- exports
- .add(new FileFacade(export,
- getApplicationSettings()));
- }
+ if (_exports == null) {
+ updateExports();
}
- if (history == null) {
- if (my.getPreviousVersion() != null
- || state == ProgressState.inCHECK
- || state == ProgressState.APPROVED) {
- history = new ArrayList<HistoryFacade>();
+ if (_history == null) {
+ if (_mydoc.getPreviousVersion() != null
+ || _state == ProgressState.inCHECK
+ || _state == ProgressState.APPROVED) {
+ _history = new ArrayList<HistoryFacade>();
}
}
- display = State.open;
- } else { // Opening the history of document, if exist
- if (history.isEmpty()) {
- collectHistory(my);
- }
- display = State.deepopen;
+ _display = State.open;
+ }
+ }
+
+ /**
+ * Update the list of export files.
+ */
+ private void updateExports() {
+ List<Relation> relations = _mydoc
+ .getRelations(ConvertsRelation.class);
+
+ _exports = new ArrayList<FileFacade>(relations.size());
+ for (Relation rel : relations) {
+ _exports.add(new FileFacade((ConvertsRelation)rel,
+ getApplicationSettings()));
}
}
+ /**
+ * Close the presentation tree partially.
+ */
public void reduce() {
- if (display == State.deepopen) {
- display = State.open;
+ if (_display == State.deepopen) {
+ _display = State.open;
}
}
+ /**
+ * Close the presentation tree.
+ */
public void reduceAll() {
- display = State.closed;
+ _display = State.closed;
}
// ==============================================================================================================================
// Getters
// ==============================================================================================================================
+ /**
+ * Get a list of attached files presentations.
+ *
+ * @return list of FileFacades
+ */
public List<FileFacade> getAttachments() {
- return exports;
+ return _exports;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getDate()
+ */
public String getDate() {
- return date;
+ return _date;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getDescription()
+ */
public String getDescription() {
- return description;
+ return _description;
}
+ /**
+ * Get a document edit icon file name according to the document state.
+ *
+ * @return the icon file name
+ */
public String getEditIcon() {
- return "icon.ed" + state + ".png";
+ return "icon.ed" + _state + ICON_EXT;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getFileIcon()
+ */
public String getFileIcon() {
- return icon;
+ return _icon;
}
+ /**
+ * Get the document history presentation.
+ *
+ * @return the history facade
+ */
public List<HistoryFacade> getHistory() {
- return history;
+ return _history;
}
+ /**
+ * Get the document persistent id.
+ *
+ * @return the document persistent id
+ */
public String getIndex() {
- return String.valueOf(my.getIndex());
+ return String.valueOf(_mydoc.getIndex());
}
+ /**
+ * Get the document contextual popup menu.
+ *
+ * @return the document popup menu
+ */
public PopupMenu getPopup() { // Contextualizes the pop-up
- popup.setContext("document", new DocumentRights(owner.getUser(), me));
- return popup; // callers must "use" the returned pop-up before getting another pop-up
+ _popup
+ .setContext("document", new DocumentRights(_owner.getUser(),
+ _me));
+ return _popup; // callers must "use" the returned pop-up before getting another pop-up
}
+ /**
+ * Get the document presentation state: open, deep open, closed.
+ *
+ * @return the document presentation state
+ * @see DocumentFacade.State
+ */
public String getPresentationState() {
- return display.toString();
+ return _display.toString();
}
+ /**
+ * Get document progress state.
+ *
+ * @return the document state
+ * @see ProgressState
+ */
public String getProgressState() {
- return state.toString();
+ return _state.toString();
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getSharingIcon()
+ */
public String getSharingIcon() {
- return sharing;
+ return _sharing;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getSize()
+ */
public String getSize() {
- return size;
+ return _size;
}
+ /**
+ * Get a document state icon file name according to the document state.
+ *
+ * @return the icon file name
+ */
public String getStateIcon() {
- return "icon." + state + ".png";
+ return "icon." + _state + ICON_EXT;
}
+ /**
+ * Get the document title.
+ *
+ * @return the document title
+ */
public String getTitle() {
- return my.getTitle();
+ return _mydoc.getTitle();
}
+ /**
+ * Get the URL of the document in the repository.
+ *
+ * @return the document URL
+ */
public String getURL() {
- return surl;
+ return _surl;
}
+ /**
+ * Get the list of used documents presentations.
+ *
+ * @return list of DocumentFacades
+ */
public List<DocumentFacade> getUses() {
- return uses;
+ return _uses;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getVersion()
+ */
public String getVersion() {
- return version;
+ return _version;
}
+ /**
+ * {@inheritDoc}
+ *
+ * @see org.splat.simer.HistoryFacade#getVersioningIcon()
+ */
public String getVersioningIcon() {
- return updated;
+ return _updated;
}
+ /**
+ * Check if this is a representation of the given document publication.
+ *
+ * @param represented
+ * the document publication
+ * @return true if this facades represents the given document publication
+ */
public boolean isFacadeOf(final Publication represented) {
- return me.equals(represented);
+ return _me.equals(represented);
}
// ==============================================================================================================================
// Protected services
// ==============================================================================================================================
- protected void refresh() {
+ /**
+ * Refresh the document presentation.
+ */
+ protected final void refresh() {
ResourceBundle custom = ResourceBundle.getBundle("som",
getApplicationSettings().getCurrentLocale());
DecimalFormat sizstring = new DecimalFormat(custom
.getString("size.format")); // Locale size display format
SimpleDateFormat datstring = new SimpleDateFormat(custom
- .getString("date.format")); // Locale date display format
- Revision.Format verstring = new Revision.Format(getProjectSettings()
- .getRevisionPattern());
- String path = my.getSourceFile().getRelativePath();
+ .getString("date.format"), getApplicationSettings()
+ .getCurrentLocale()); // Locale date display format
+ String path = _mydoc.getSourceFile().getRelativePath();
String[] mapping = ApplicationSettings.getViewersMapping();
for (int i = 0; i < mapping.length; i++) {
- org.splat.dal.bo.som.File export = my.getAttachedFile(mapping[i]);
- if (export == null) {
- continue;
+ org.splat.dal.bo.som.File export = _mydoc
+ .getAttachedFile(mapping[i]);
+ if (export != null) {
+ path = export.getRelativePath();
+ break;
}
- path = export.getRelativePath();
- break;
- }
- surl = getApplicationSettings().getRepositoryURL() + path;
- surl = surl.replaceAll("'", "\\\\'");
- format = my.getFormat();
- if (format.equals("xml")) {
- format = XMLDocument.getActualFormat(my.getSourceFile().asFile());
}
+ _surl = getApplicationSettings().getRepositoryURL() + path;
+ _surl = _surl.replaceAll("'", "\\\\'");
// Document state (overridable by the publication - see below)
- state = my.getProgressState();
- version = my.getVersion(); // May be null
+ _state = _mydoc.getProgressState();
+ _version = _mydoc.getVersion(); // May be null
- // Icons definition
- icon = "icon." + format + ".png";
- sharing = "image.hold.gif";
- updated = "image.hold.gif";
- File image = new File(ApplicationSettings.getApplicationSkinPath()
- + icon);
- if (!image.exists()) {
- icon = "icon.any.png";
- }
+ initIcons();
- if (me != null) {
- if (me.getOwnerStudy().shares(my)) {
- sharing = "image.share.png";
- updated = "icon.hold.png";
- }
- if (me.isOutdated()) {
- state = ProgressState.inWORK; // Overrides the document state
- }
-
- } else { // Facade in the history folder
- if (!my.isVersioned()) { // History of the last version
- if (state != ProgressState.inWORK) {
- icon = "icon.inWORK.png";
- } else {
- icon = "icon." + state.toString() + ".png";
- }
- } else if (my.isPublished()) {
- sharing = "image.share.png"; // Not correct if published in a previous version of the study
- updated = "icon.hold.png";
- }
- }
// Document description
- VersionsRelation versions = (VersionsRelation) my
+ VersionsRelation versions = (VersionsRelation) _mydoc
.getFirstRelation(VersionsRelation.class);
if (versions != null) {
- description = versions.getDescription();
+ _description = versions.getDescription();
}
// File details
- if (state != ProgressState.EXTERN) {
- version = verstring.format(version);
+ Revision.Format verstring = new Revision.Format(
+ getProjectSettings().getRevisionPattern());
+ _version = verstring.format(_version);
+ _size = sizstring.format(_mydoc.getSourceFile().asFile().length() / 1000);
+ _date = datstring.format(_mydoc.getLastModificationDate());
+ updateExports();
+ // Refresh of the history in case of promotion
+ if (_display == State.deepopen) {
+ _history.clear();
+ this.collectHistory(_mydoc);
}
- size = sizstring.format(my.getSourceFile().asFile().length() / 1000);
- date = datstring.format(my.getLastModificationDate());
+ initPopupMenu();
+ }
- // Refresh of the history in case of promotion
- if (display == State.deepopen) {
- history.clear();
- collectHistory(my);
+ /**
+ * Initialize document presentation icons.
+ */
+ private final void initIcons() {
+ // Icons definition
+ String format = _mydoc.getFormat();
+ if ("xml".equals(format)) {
+ format = XMLDocument.getActualFormat(_mydoc.getSourceFile()
+ .asFile());
+ if ("schema".equals(_mydoc.getType().getName())) {
+ format = "schema";
+ }
}
- // Popup menus
- if (me == null) {
- return; // No pop-up (yet) in the history folder
+
+ _icon = "icon." + format + ICON_EXT;
+ _sharing = "image.hold.gif";
+ _updated = "image.hold.gif";
+ File image = new File(ApplicationSettings.getApplicationSkinPath()
+ + _icon);
+ if (!image.exists()) {
+ _icon = "icon.any.png";
}
- if (state == ProgressState.EXTERN) {
- popup = getApplicationSettings().getPopupMenu("extern");
- } else if (state == ProgressState.inWORK) {
- popup = getApplicationSettings().getPopupMenu("editable");
- } else if (state == ProgressState.inDRAFT) {
- popup = getApplicationSettings().getPopupMenu("reviewable");
- } else if (state == ProgressState.APPROVED) {
- popup = getApplicationSettings().getPopupMenu("approved");
- } else { // (state == ProgressState.inCHECK)
- DocumentType mytype = me.value().getType(); // Only result documents need to be approved
- Step mystep = getPublicationService().getInvolvedStep(me);
- if (mytype.isResultOf(mystep.getStep())) {
- popup = getApplicationSettings().getPopupMenu("approvable");
+
+ if (_me == null) { // Facade in the history folder
+ if (_mydoc.isVersioned()) { // History of the last version
+ if (_mydoc.isPublished()) {
+ _sharing = "image.share.png"; // Not correct if published in a previous version of the study
+ _updated = "icon.hold.png";
+ }
} else {
- popup = getApplicationSettings().getPopupMenu("notresult");
+ if (_state == ProgressState.inWORK) {
+ _icon = "icon." + _state.toString() + ICON_EXT;
+ } else {
+ _icon = "icon.inWORK.png";
+ }
+ }
+ } else {
+ if (_me.getOwnerStudy().shares(_mydoc)) {
+ _sharing = "image.share.png";
+ _updated = "icon.hold.png";
+ }
+ //if (_me.isOutdated()) {
+ // _state = ProgressState.inWORK; // Overrides the document state
+ //}
+ }
+ }
+
+ /**
+ * Initialize document's popup menu.
+ */
+ private final void initPopupMenu() {
+ // Popup menus
+ if (_me != null) { // There is a pop-up
+ if (_state == ProgressState.EXTERN) {
+ _popup = getApplicationSettings().getPopupMenu("extern");
+ } else if (_state == ProgressState.inWORK) {
+ _popup = getApplicationSettings().getPopupMenu("editable");
+ } else if (_state == ProgressState.inDRAFT) {
+ _popup = getApplicationSettings().getPopupMenu("reviewable");
+ } else if (_state == ProgressState.APPROVED) {
+ _popup = getApplicationSettings().getPopupMenu("approved");
+ } else { // (state == ProgressState.inCHECK)
+ DocumentType aType = _me.value().getType(); // Only result documents need to be approved
+ Step aStep = getPublicationService().getInvolvedStep(_me);
+ if (aType.isResultOf(aStep.getStep())) {
+ _popup = getApplicationSettings()
+ .getPopupMenu("approvable");
+ } else {
+ _popup = getApplicationSettings().getPopupMenu("notresult");
+ }
}
}
}
+ /**
+ * Turn on the versioning icon.
+ */
protected void setVersioned() {
- updated = "image.modified.png";
+ _updated = "image.modified.png";
}
// ==============================================================================================================================
// Private services
// ==============================================================================================================================
- private void collectHistory(final Document given) {
+ /**
+ * Collect the document's previous versions presentation.
+ *
+ * @param given
+ * the document to explore
+ */
+ private final void collectHistory(final Document given) {
VersionsRelation versions = (VersionsRelation) given
.getFirstRelation(VersionsRelation.class);
Timestamp[] stamp = given.getStamps(); // Stamps in ascending order of date
for (int i = stamp.length - 1; i > -1; i--) {
- history.add(new StampFacade(stamp[i], getApplicationSettings()
+ _history.add(new StampFacade(stamp[i], getApplicationSettings()
.getCurrentLocale()));
}
- history.add(new DocumentFacade(owner, given, getProjectSettings(),
+ _history.add(new DocumentFacade(_owner, given, getProjectSettings(),
getPublicationService(), getApplicationSettings()));
if (versions != null) {
- collectHistory(versions.getTo());
+ this.collectHistory(versions.getTo());
}
}
* @return Project settings service
*/
private ProjectSettingsService getProjectSettings() {
- return _projectSettingsService;
+ return _projectSettings;
}
/**
* @param projectSettingsService
* project settings service
*/
- public void setProjectSettings(
+ public final void setProjectSettings(
final ProjectSettingsService projectSettingsService) {
- _projectSettingsService = projectSettingsService;
+ _projectSettings = projectSettingsService;
}
/**
* @param publicationService
* the publicationService to set
*/
- public void setPublicationService(
+ public final void setPublicationService(
final PublicationService publicationService) {
_publicationService = publicationService;
}
* @param applicationSettings
* the applicationSettings to set
*/
- public void setApplicationSettings(
+ public final void setApplicationSettings(
final ApplicationSettings applicationSettings) {
_applicationSettings = applicationSettings;
}