import java.io.File;
import java.io.FileNotFoundException;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.UsedByRelation;
import org.splat.dal.bo.som.UsesRelation;
+import org.splat.dal.bo.som.ValidationCycle;
+import org.splat.dal.bo.som.ValidationStep;
import org.splat.kernel.InvalidPropertyException;
import org.splat.manox.Reader;
import org.splat.manox.Toolbox;
-import org.splat.service.PublicationService;
-import org.splat.service.StepService;
-import org.splat.service.technical.ProjectSettingsService;
-import org.splat.service.technical.RepositoryService;
import org.splat.som.Revision;
import org.splat.som.Step;
import org.splat.wapp.Constants;
/**
* Action for creating a new version of a document.
*/
-public class VersionDocumentAction extends UploadBaseNextAction {
+public class VersionDocumentAction extends BaseUploadDocumentAction {
/**
* Serial version ID.
*/
private String _description = null;
/**
- * Version number extracted from the imported file, if exist.
+ * Applicable document states.
*/
- private String _version = "";
- /**
- * Date extracted from the imported file, if exist.
- */
- private String _date = "";
- /**
- * Injected project settings service.
- */
- private ProjectSettingsService _projectSettings;
- /**
- * Injected publication service.
- */
- private PublicationService _publicationService;
- /**
- * Injected step service.
- */
- private StepService _stepService;
- /**
- * Injected repository service.
- */
- private RepositoryService _repositoryService;
- /**
- * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
- */
- private String _menuProperty;
-
- /**
- * Value of the title bar property. It can be: study, knowledge.
- */
- private String _titleProperty;
-
- /**
- * Value of the tool bar property. It can be: none, standard, study, back.
- */
- private String _toolProperty;
-
- /**
- * Value of the left menu property. It can be: open, study, knowledge, scenario.
- */
- private String _leftMenuProperty;
-
- /**
- * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
- * menu also can be called. It is necessary for correct building the title bar.
- */
- private String _editDisabledProperty = "false";
-
- // ==============================================================================================================================
- // Action methods
- // ==============================================================================================================================
+ private transient final List<ProgressState> _documentStates = new ArrayList<ProgressState>();
/**
* Initialize the action form.
* @return SUCCESS if succeeded, ERROR if uploaded file is XML and we can't extract properties from it
*/
public String doInitialize() {
+ File upfile = commonInitialize(Constants.TRUE);
- setMenuProperty(Constants.STUDY_MENU);
- setTitleProperty(Constants.STUDY_MENU);
- setEditDisabledProperty("true");
- if ("true".equals(getWriteAccess())) {
- setToolProperty(Constants.STUDY_MENU);
- } else {
- setToolProperty(Constants.NONE);
- }
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
-
- User user = getConnectedUser();
- File updir = getRepositoryService().getDownloadDirectory(user);
- File upfile = new File(updir.getPath() + "/" + filename);
-
- mystudy = getOpenStudy();
-
- Publication tag = mystudy.getSelectedStep().getDocument(
+ _mystudy = getOpenStudy();
+ _mystudy.updateCurrentStep();
+ _defuses = new ArrayList<Document>();
+
+ Publication tag = _mystudy.getSelectedStep().getDocument(
Integer.valueOf(_index));
Document doc = tag.value();
- deftype = doc.getType();
- docname = doc.getTitle();
- defuses = new ArrayList<Document>();
+ _deftype = doc.getType();
+ _docname = doc.getTitle();
_usedby = new ArrayList<Publication>();
String res = SUCCESS;
if (extractProperties(upfile, doc)) {
- setupDefaultUses(deftype);
+ if (_deftype != null) {
+ setupDefaultUses(_deftype);
+ }
// Add additional documents used by the current version
- List<Relation> uses = doc.getRelations(UsesRelation.class);
- for (Iterator<Relation> i = uses.iterator(); i.hasNext();) {
- Document used = (Document) i.next().getTo();
- if (!defuses.contains(used)) {
- defuses.add(used);
+ for (Relation usesRel : doc.getRelations(UsesRelation.class)) {
+ Document used = (Document) usesRel.getTo();
+ Document lastVersion = getPublicationService().getLastVersion(used, tag.getOwner());
+ if (lastVersion != null && !_defuses.contains(lastVersion)) {
+ _defuses.add(lastVersion);
}
}
+ // Avoid recursive using of the document
+ if (_defuses.contains(doc)) {
+ _defuses.remove(doc);
+ }
+
+ // Avoid using of documents dependent on the current version of the document being versioned
+ // (This case is possible only if both documents belong to the step of the same Project Element)
+ for(Iterator<Document> document = _defuses.iterator(); document.hasNext(); ) {
+ Publication pub = tag.getOwner().getPublication(document.next());
+ if(pub != null && pub.getRelations(UsesRelation.class).contains(tag)) {
+ document.remove();
+ }
+ }
+
// Setup dependencies
_usedby.addAll(tag.getRelations(UsedByRelation.class));
+
+ // Initialize applicable states list
+ if (tag.value().getProgressState() == ProgressState.EXTERN) {
+ _documentStates.add(ProgressState.EXTERN);
+ } else {
+ _documentStates.add(ProgressState.inWORK);
+ if (_deftype != null) {
+ // Check if the validation cycle of the document type can has a review state
+ ValidationCycle cycle = getStudyService()
+ .getValidationCycleOf(_mystudy.getMystudy(),
+ _deftype);
+ if ((cycle != null) && cycle.enables(ValidationStep.REVIEW)) {
+ _documentStates.add(ProgressState.inDRAFT);
+ }
+ }
+ }
} else {
- if (!(Constants.NONE.equals(_toolProperty))) {
- setToolProperty(Constants.NONE);
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ if (!(Constants.NONE.equals(getToolProperty()))) {
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+ Constants.STUDY_MENU);
}
res = ERROR;
}
throw new InvalidPropertyException("version");
}
if (newver.isMinor()) {
- state = ProgressState.inWORK;
+ _state = ProgressState.inWORK;
} else {
- state = ProgressState.inDRAFT;
+ _state = ProgressState.inDRAFT;
}
- _version = newver.toString();
+ setVersion(newver.toString());
} catch (Exception e) {
setErrorCode("message.error.version.mismatch");
res = false;
}
if (res) {
_description = tool.extractProperty("history");
- _date = tool.extractProperty("date");
- if (_date == null) {
- _date = "";
- } else {
- ResourceBundle locale = ResourceBundle.getBundle("som",
- getApplicationSettings().getCurrentLocale());
- SimpleDateFormat check = new SimpleDateFormat(locale
- .getString("date.format"));
- try {
- check.parse(_date);
- } catch (ParseException e) {
- setErrorCode("message.error.format.date");
- res = false;
- }
- }
+ res = extractDate(tool);
}
} else {
setErrorCode("message.error.reference.mismatch");
*/
public String doVersion() {
String res = ERROR;
- setMenuProperty(Constants.STUDY_MENU);
- setTitleProperty(Constants.STUDY_MENU);
- setEditDisabledProperty("true");
- initializationScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty);
+ initializationScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU,
+ Constants.TRUE);
- if (action == ToDo.cancel) {
+ if (_action == ToDo.cancel) {
res = "cancel";
} else {
try {
// Getting user inputs
- mystudy = getOpenStudy();
+ _mystudy = getOpenStudy();
User user = getConnectedUser();
- Step step = mystudy.getSelectedStep();
+ Step step = _mystudy.getSelectedStep();
Date aDate = null;
- if (_date.length() > 0) {
+ if (getDocumentDate().length() > 0) {
ResourceBundle locale = ResourceBundle.getBundle("som",
getApplicationSettings().getCurrentLocale());
SimpleDateFormat get = new SimpleDateFormat(locale
- .getString("date.format"));
- aDate = get.parse(_date);
+ .getString("date.format"), getApplicationSettings()
+ .getCurrentLocale());
+ aDate = get.parse(getDocumentDate());
}
String[] listDocuses = null;
- if (docuses != null) {
- listDocuses = docuses.split(",");
+ if (_docuses != null) {
+ listDocuses = _docuses.split(",");
}
- getPublicationService().versionDocument(step, user, filename,
- Integer.valueOf(_index), _version, _description, state,
- aDate, listDocuses, _docusedby);
+ getPublicationService().versionDocument(step, user, _fileName,
+ Integer.valueOf(_index), getVersion(), _description,
+ _state, aDate, listDocuses, _docusedby);
// Update of the open study
- mystudy.setSelection(mystudy.getSelection()); // Rebuilds the presentation
- // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document)
+ refreshStudy();
res = SUCCESS;
} catch (FileNotFoundException error) {
setErrorCode("message.error.internal");
}
if (!SUCCESS.equals(res)) {
- setToolProperty(Constants.NONE);
-
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+ Constants.STUDY_MENU);
}
}
return res;
// Getters and setters
// ==============================================================================================================================
- public String getDate() {
- return _date;
- }
-
public List<Publication> getDependencies() {
return _usedby;
}
return _index;
}
- public String getVersion() {
- return _version;
- }
-
- public void setDate(final String date) {
- this._date = date;
- }
-
public void setDefaultDescription(final String summary) {
if (this._description == null) {
this._description = summary;
this._docusedby = list;
}
- public void setVersion(final String value) {
- this._version = value;
- }
-
- /**
- * Get project settings.
- *
- * @return Project settings service
- */
- private ProjectSettingsService getProjectSettings() {
- return _projectSettings;
- }
-
- /**
- * Set project settings service.
- *
- * @param projectSettingsService
- * project settings service
- */
- public void setProjectSettings(
- final ProjectSettingsService projectSettingsService) {
- _projectSettings = projectSettingsService;
- }
-
- /**
- * Get the publicationService.
- *
- * @return the publicationService
- */
- public PublicationService getPublicationService() {
- return _publicationService;
- }
-
- /**
- * Set the publicationService.
- *
- * @param publicationService
- * the publicationService to set
- */
- public void setPublicationService(
- final PublicationService publicationService) {
- _publicationService = publicationService;
- }
-
- /**
- * Get the stepService.
- *
- * @return the stepService
- */
- public StepService getStepService() {
- return _stepService;
- }
-
- /**
- * Set the stepService.
- *
- * @param stepService
- * the stepService to set
- */
- public void setStepService(final StepService stepService) {
- _stepService = stepService;
- }
-
- /**
- * Get the repositoryService.
- *
- * @return the repositoryService
- */
- public RepositoryService getRepositoryService() {
- return _repositoryService;
- }
-
- /**
- * Set the repositoryService.
- *
- * @param repositoryService
- * the repositoryService to set
- */
- public void setRepositoryService(final RepositoryService repositoryService) {
- _repositoryService = repositoryService;
- }
-
- /**
- * Get the menuProperty.
- *
- * @return the menuProperty
- */
- public String getMenuProperty() {
- return _menuProperty;
- }
-
- /**
- * Set the menuProperty.
- *
- * @param menuProperty
- * the menuProperty to set
- */
- public void setMenuProperty(final String menuProperty) {
- this._menuProperty = menuProperty;
- }
-
- /**
- * Get the _titleProperty.
- *
- * @return the _titleProperty
- */
- public String getTitleProperty() {
- return _titleProperty;
- }
-
- /**
- * Set the _titleProperty.
- *
- * @param titleProperty
- * the titleProperty to set
- */
- public void setTitleProperty(final String titleProperty) {
- _titleProperty = titleProperty;
- }
-
- /**
- * Get the _editDisabledProperty.
- *
- * @return the _editDisabledProperty
- */
- public String getEditDisabledProperty() {
- return _editDisabledProperty;
- }
-
- /**
- * Set the editDisabledProperty.
- *
- * @param editDisabledProperty
- * the editDisabledProperty to set
- */
- public void setEditDisabledProperty(final String editDisabledProperty) {
- this._editDisabledProperty = editDisabledProperty;
- }
-
- /**
- * Get the toolProperty.
- *
- * @return the toolProperty
- */
- public String getToolProperty() {
- return _toolProperty;
- }
-
- /**
- * Set the toolProperty.
- *
- * @param toolProperty
- * the toolProperty to set
- */
- public void setToolProperty(final String toolProperty) {
- _toolProperty = toolProperty;
- }
-
- /**
- * Get the leftMenuProperty.
- *
- * @return the leftMenuProperty
- */
- public String getLeftMenuProperty() {
- return _leftMenuProperty;
- }
-
/**
- * Set the leftMenuProperty.
+ * Get the documentStates.
*
- * @param leftMenuProperty
- * the leftMenuProperty to set
+ * @return the documentStates
*/
- public void setLeftMenuProperty(final String leftMenuProperty) {
- _leftMenuProperty = leftMenuProperty;
+ public List<ProgressState> getDocumentStates() {
+ return _documentStates;
}
}
\ No newline at end of file