From 8ff16d08ee73bc5a94266391375422f06675a16d Mon Sep 17 00:00:00 2001 From: rkv Date: Fri, 15 Feb 2013 09:27:09 +0000 Subject: [PATCH] Fix for mantis #0022093: To exclude the "In-Draft" state from drop-down list during Import operation when the V.C. does not contain this state.: Import and version document actions are fixed. --- .../Siman/WebContent/study/importDocument.jsp | 44 ++- .../WebContent/study/versionDocument.jsp | 226 ++++++------- .../splat/simer/AbstractUploadNextAction.java | 95 ++++++ .../splat/simer/BaseUploadDocumentAction.java | 319 ++++++++++++++++++ .../simer/EditScenarioPropertiesAction.java | 24 +- .../org/splat/simer/ImportDocumentAction.java | 307 ++++------------- .../org/splat/simer/UploadBaseNextAction.java | 118 ------- .../splat/simer/VersionDocumentAction.java | 231 +++---------- .../splat/simer/admin/ImportUserAction.java | 120 +++---- .../Siman/src/spring/applicationContext.xml | 2 + 10 files changed, 757 insertions(+), 729 deletions(-) create mode 100644 Workspace/Siman/src/org/splat/simer/AbstractUploadNextAction.java create mode 100644 Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java delete mode 100644 Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java diff --git a/Workspace/Siman/WebContent/study/importDocument.jsp b/Workspace/Siman/WebContent/study/importDocument.jsp index 8d8c00b..8c7d22a 100644 --- a/Workspace/Siman/WebContent/study/importDocument.jsp +++ b/Workspace/Siman/WebContent/study/importDocument.jsp @@ -1,19 +1,40 @@ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib prefix="s" uri="/struts-tags"%> -
@@ -48,14 +69,10 @@ $(document).ready(function () {   - - - - - + @@ -78,8 +95,7 @@ $(document).ready(function () { - + listValue="%{getText(key)}" disabled="" /> diff --git a/Workspace/Siman/WebContent/study/versionDocument.jsp b/Workspace/Siman/WebContent/study/versionDocument.jsp index ca37800..d8ee105 100644 --- a/Workspace/Siman/WebContent/study/versionDocument.jsp +++ b/Workspace/Siman/WebContent/study/versionDocument.jsp @@ -1,123 +1,113 @@ <%@ page language="java" contentType="text/html; charset=ISO-8859-1" - pageEncoding="ISO-8859-1" -%> -<%@ - taglib prefix="s" uri="/struts-tags" -%> - - - - - rel="stylesheet" type="text/css"> - - - + pageEncoding="ISO-8859-1"%> +<%@taglib prefix="s" uri="/struts-tags"%> + -
-
-
- - - - - -
- - - -
+
+
+
+ + + + + + + +
+ + + +
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
   
-   - - " /> -
:
" checked>
: - - - - - " /> -
:
">
- "/>  - - - - - - "/> - -
- -
-
- - \ No newline at end of file +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
   
 
:
" checked>
:
:
+
">
 
+ +
+
diff --git a/Workspace/Siman/src/org/splat/simer/AbstractUploadNextAction.java b/Workspace/Siman/src/org/splat/simer/AbstractUploadNextAction.java new file mode 100644 index 0000000..42e877d --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/AbstractUploadNextAction.java @@ -0,0 +1,95 @@ +package org.splat.simer; + +import org.splat.service.technical.RepositoryService; + +/** + * Abstract action just after uploading a file. + */ +public abstract class AbstractUploadNextAction extends Action { + + /** + * Uploaded file name. + */ + protected String _fileName = null; + /** + * Next action. + */ + protected transient ToDo _action = null; + /** + * Injected repository service. + */ + private RepositoryService _repositoryService; + + /** + * Serial version ID. + */ + private static final long serialVersionUID = -6925961099244461039L; + + /** + * Possible next action. + */ + protected enum ToDo { + /** + * Cancel uploading. + */ + cancel, + /** + * Save uploaded data. + */ + save + }; + + // ============================================================================================================================== + // Getters and setters + // ============================================================================================================================== + + /** + * Get uploaded file name. + * + * @return uploaded file name + */ + public String getFileName() { + return _fileName; + } + + public void setCancel(final boolean cancel) { + this._action = ToDo.cancel; + } + + /** + * Set uploaded file name. + * + * @param path + * uploaded file name + */ + public void setFileName(final String path) { + this._fileName = path; + } + + public void setSave(final boolean save) { + this._action = ToDo.save; + } + + // ============================================================================================================================== + // Protected services + // ============================================================================================================================== + + /** + * 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; + } +} \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java b/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java new file mode 100644 index 0000000..c54d950 --- /dev/null +++ b/Workspace/Siman/src/org/splat/simer/BaseUploadDocumentAction.java @@ -0,0 +1,319 @@ +package org.splat.simer; + +import java.io.File; +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; +import java.util.ResourceBundle; +import java.util.Set; + +import org.splat.dal.bo.kernel.User; +import org.splat.dal.bo.som.Document; +import org.splat.dal.bo.som.DocumentType; +import org.splat.dal.bo.som.ProgressState; +import org.splat.dal.bo.som.Publication; +import org.splat.manox.Reader; +import org.splat.service.PublicationService; +import org.splat.service.StepService; +import org.splat.service.StudyService; +import org.splat.service.technical.ProjectSettingsService; +import org.splat.som.Step; +import org.splat.wapp.Constants; + +/** + * Base action for adding a document into a study step. + */ +public class BaseUploadDocumentAction extends AbstractUploadNextAction { + + /** + * Serial version ID. + */ + private static final long serialVersionUID = 7920982168638437486L; + /** + * Version number extracted from the imported file, if exist. + */ + private String _version = ""; + /** + * Date extracted from the imported file, if exist. + */ + private String _documentDate = ""; + /** + * Injected project settings service. + */ + private ProjectSettingsService _projectSettings; + /** + * Injected publication service. + */ + private PublicationService _publicationService; + /** + * Injected step service. + */ + private StepService _stepService; + /** + * Injected study service. + */ + private StudyService _studyService; + protected DocumentType _deftype = null; + protected List _defuses = null; + protected String _docname = null; + protected String _docuses = null; + protected OpenStudy _mystudy = null; + protected ProgressState _state = null; + + /** + * Common initialization of the action form. + * + * @param editDisabled + * if the study editable or not + * @return downloaded file + */ + protected File commonInitialize(final String editDisabled) { + + if (Constants.TRUE.equals(getWriteAccess())) { + setToolProperty(Constants.STUDY_MENU); + } else { + setToolProperty(Constants.NONE); + } + initializationFullScreenContext(Constants.STUDY_MENU, + Constants.STUDY_MENU, editDisabled, getToolProperty(), + Constants.STUDY_MENU); + + User user = getConnectedUser(); + File updir = getRepositoryService().getDownloadDirectory(user); + File upfile = new File(updir.getPath() + "/" + _fileName); + + _mystudy = getOpenStudy(); + _defuses = new ArrayList(); + return upfile; + } + + /** + * Extract document date. + * + * @param tool + * file reader + * @return true if ok, false if error + */ + protected boolean extractDate(final Reader tool) { + boolean isOk = true; + setDocumentDate(tool.extractProperty("date")); + if (getDocumentDate() == null) { + setDocumentDate(""); + } else { + ResourceBundle locale = ResourceBundle.getBundle("som", + getApplicationSettings().getCurrentLocale()); + SimpleDateFormat check = new SimpleDateFormat(locale + .getString("date.format"), getApplicationSettings() + .getCurrentLocale()); + try { + check.parse(getDocumentDate()); + } catch (ParseException e) { + setErrorCode("message.error.format.date"); + isOk = false; + } + } + return isOk; + } + + /** + * Set error message and menus. + * + * @param errorCode + * error message key + */ + protected void setError(final String errorCode) { + setErrorCode(errorCode); + + initializationFullScreenContext(Constants.STUDY_MENU, + Constants.STUDY_MENU, Constants.FALSE, Constants.NONE, + Constants.STUDY_MENU); + } + + /** + * Date extracted from the imported file, if exist. + * + * @return the file date + */ + public String getDocumentDate() { + return _documentDate; + } + + /** + * Get version number extracted from the imported file, if exist. + * + * @return the document version + */ + public String getVersion() { + return _version; + } + + /** + * Set date extracted from the imported file. + * + * @param date + * the date to set + */ + public void setDocumentDate(final String date) { + this._documentDate = date; + } + + /** + * Set version number extracted from the imported file, if exist. + * + * @param value + * the version + */ + public void setVersion(final String value) { + this._version = value; + } + + /** + * Get project settings. + * + * @return Project settings service + */ + protected 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 studyService. + * + * @return the studyService + */ + public StudyService getStudyService() { + return _studyService; + } + + /** + * Set the studyService. + * + * @param studyService + * the studyService to set + */ + public void setStudyService(final StudyService studyService) { + _studyService = studyService; + } + + // ============================================================================================================================== + // Getters and setters + // ============================================================================================================================== + + public DocumentType getDefaultDocumentType() { + return _deftype; + } + + public List getDefaultDocumentUses() { + return _defuses; + } + + public String getDocumentName() { + return _docname; + } + + public String getDocumentState() { + return _state.toString(); + } + + protected Publication getPublication(final int index) { + List steps = _mystudy.getInvolvedSteps(); + Publication found = null, pub; + for (Iterator i = steps.iterator(); i.hasNext();) { + List published = i.next().getAllDocuments(); + for (Iterator j = published.iterator(); j.hasNext();) { + pub = j.next(); // In a given study step, + if (pub.value().getIndex() == index) { + found = pub; // there is only one publication of a given document + break; + } + } + } + return found; + } + + public void setDocumentState(final String state) { + this._state = ProgressState.valueOf(state); + } + + // ============================================================================================================================== + // Protected services + // ============================================================================================================================== + + protected void setupDefaultUses(final DocumentType type) { + Set uses = type.getDefaultUses(); + + for (Iterator i = uses.iterator(); i.hasNext();) { + DocumentType usetype = i.next(); + List usedoc = _mystudy.collectInvolvedDocuments(usetype); + if (usedoc.isEmpty() && (!usetype.equals(type))) { + setupDefaultUses(usetype); + } else { + _defuses.addAll(usedoc); + } + } + } + + public void setUses(final String list) { + this._docuses = list; + } + + public String getWriteAccess() { + Boolean res = (_mystudy != null); + if (res) { + res = _mystudy.isOpenForWriting(); + } + return res.toString(); + } +} \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java b/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java index c6ddf7d..26a8d47 100644 --- a/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java +++ b/Workspace/Siman/src/org/splat/simer/EditScenarioPropertiesAction.java @@ -15,6 +15,9 @@ import org.splat.som.Step; import org.splat.som.StepRights; import org.splat.wapp.Constants; +/** + * Action for scenario properties modification. + */ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { /** @@ -25,7 +28,7 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { private transient Scenario _myscenario; private transient String _lasdate; private transient String _subject; - + /** * Title of the selected scenario. */ @@ -51,7 +54,8 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { ResourceBundle custom = ResourceBundle.getBundle("som", getApplicationSettings().getCurrentLocale()); SimpleDateFormat datstring = new SimpleDateFormat(custom - .getString("date.format")); // Locale date display format + .getString("date.format"), getApplicationSettings() + .getCurrentLocale()); // Locale date display format Step step; _openStudy = getOpenStudy(); @@ -104,6 +108,7 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { /** * Rename the scenario functionality. + * * @return SUCCESS */ public String doEditScenarioTitle() { @@ -113,14 +118,15 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { Iterator iter = scenarios.iterator(); for (; iter.hasNext();) { Scenario scenario = iter.next(); - if (openStudy.getSelectedScenarioId().equals(String.valueOf(scenario.getIndex()))) { - scenario.setTitle(getSelectedScenarioTitle()); + if (openStudy.getSelectedScenarioId().equals( + String.valueOf(scenario.getIndex()))) { + scenario.setTitle(getSelectedScenarioTitle()); _scenarioService.renameScenario(scenario); } } return SUCCESS; } - + // ============================================================================================================================== // Getters // ============================================================================================================================== @@ -152,15 +158,13 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { return _subject; } - public boolean isCheckedout() { return _myscenario.isCheckedout(); } - - /** * Get the selectedScenarioTitle. + * * @return the selectedScenarioTitle */ public String getSelectedScenarioTitle() { @@ -169,7 +173,9 @@ public class EditScenarioPropertiesAction extends DisplayStudyStepAction { /** * Set the selectedScenarioTitle. - * @param selectedScenarioTitle the selectedScenarioTitle to set + * + * @param selectedScenarioTitle + * the selectedScenarioTitle to set */ public void setSelectedScenarioTitle(final String selectedScenarioTitle) { _selectedScenarioTitle = selectedScenarioTitle; diff --git a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java index 1b376a4..a3a4de2 100644 --- a/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java @@ -16,14 +16,12 @@ import org.splat.dal.bo.som.Document; import org.splat.dal.bo.som.DocumentType; import org.splat.dal.bo.som.ProgressState; import org.splat.dal.bo.som.Publication; +import org.splat.dal.bo.som.ValidationCycle; +import org.splat.dal.bo.som.ValidationStep; import org.splat.manox.Reader; import org.splat.manox.Toolbox; import org.splat.service.DocumentService; import org.splat.service.DocumentTypeService; -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; @@ -31,7 +29,7 @@ import org.splat.wapp.Constants; /** * Action for adding a document into a study step. */ -public class ImportDocumentAction extends UploadBaseNextAction { +public class ImportDocumentAction extends BaseUploadDocumentAction { /** * Serial version ID. @@ -42,6 +40,10 @@ public class ImportDocumentAction extends UploadBaseNextAction { * Sorted list of document types for the selected study step. */ private transient List _documentTypes = null; + /** + * Sorted list of document types for the selected study step. + */ + private transient final List _reviewable = new ArrayList(); /** * The selected document type. */ @@ -50,26 +52,6 @@ public class ImportDocumentAction extends UploadBaseNextAction { * Reference extracted from the imported file, if exist. */ private String _reference = null; - /** - * Version number extracted from the imported file, if exist. - */ - private String _version = ""; - /** - * Date extracted from the imported file, if exist. - */ - private String _documentDate = ""; - /** - * Injected project settings service. - */ - private ProjectSettingsService _projectSettings; - /** - * Injected publication service. - */ - private PublicationService _publicationService; - /** - * Injected step service. - */ - private StepService _stepService; /** * Injected document service. */ @@ -78,14 +60,6 @@ public class ImportDocumentAction extends UploadBaseNextAction { * Injected document type service. */ private DocumentTypeService _documentTypeService; - /** - * Injected repository service. - */ - private RepositoryService _repositoryService; - - // ============================================================================================================================== - // Action methods - // ============================================================================================================================== /** * Initialize the operation. @@ -94,42 +68,31 @@ public class ImportDocumentAction extends UploadBaseNextAction { */ public String doInitialize() { - if (Constants.TRUE.equals(getWriteAccess())) { - setToolProperty(Constants.STUDY_MENU); - } else { - setToolProperty(Constants.NONE); - } - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.FALSE, getToolProperty(), - Constants.STUDY_MENU); - - User user = getConnectedUser(); - File updir = getRepositoryService().getDownloadDirectory(user); - File upfile = new File(updir.getPath() + "/" + filename); - String[] table = filename.split("\\x2E"); + File upfile = commonInitialize(Constants.FALSE); + String[] table = _fileName.split("\\x2E"); String filext = table[table.length - 1].toLowerCase(); - mystudy = getOpenStudy(); - Step step = mystudy.getSelectedStep(); + _mystudy = getOpenStudy(); + Step step = _mystudy.getSelectedStep(); _documentTypes = getStepService().getValidDocumentTypes(step); // Set the document type by default - deftype = getApplicationSettings().getDefaultDocumentType(step, filext); - if (deftype != null) { - setDefaultDocumentType(deftype.getIndex()); + _deftype = getApplicationSettings().getDefaultDocumentType(step, filext); + if (_deftype != null) { + setDefaultDocumentType(_deftype.getIndex()); } - defuses = new ArrayList(); - state = ProgressState.inWORK; + _defuses = new ArrayList(); + _state = ProgressState.inWORK; String res = ERROR; if (extractProperties(upfile, filext)) { - if (docname == null) { - docname = table[0]; + if (_docname == null) { + _docname = table[0]; for (int i = 1; i < table.length - 1; i++) { - docname = docname + "." + table[i]; + _docname = _docname + "." + table[i]; } } - if (deftype != null) { - setupDefaultUses(deftype); + if (_deftype != null) { + setupDefaultUses(_deftype); } DocumentType[] types = _documentTypes @@ -139,6 +102,16 @@ public class ImportDocumentAction extends UploadBaseNextAction { _documentTypes = Arrays.asList(types); res = SUCCESS; } + + // Initialize isReviewable: if a type has review state or not + ValidationCycle cycle; + boolean hasReview; + for (DocumentType dtype : _documentTypes) { + cycle = getStudyService().getValidationCycleOf( + _mystudy.getMystudy(), dtype); + hasReview = (cycle != null) && cycle.enables(ValidationStep.REVIEW); + _reviewable.add(hasReview); + } return res; } @@ -156,7 +129,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { Reader tool = Toolbox.getReader(upfile); if (tool == null) { if ("pdf".equals(filext)) { - state = ProgressState.EXTERN; // TODO: Should external extensions be configurable ? + _state = ProgressState.EXTERN; // TODO: Should external extensions be configurable ? } } else { String fileref = tool.extractProperty("reference"); @@ -166,7 +139,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { .hasNext();) { DocumentType type = i.next(); if (type.getName().equals(filetype)) { - deftype = type; + _deftype = type; _documentType = type.getIndex(); // Disables the document type field break; } @@ -185,32 +158,17 @@ public class ImportDocumentAction extends UploadBaseNextAction { filever.length() - 1); } if (!version.isMinor()) { - state = ProgressState.inCHECK; + _state = ProgressState.inCHECK; } - _version = version.toString(); + setVersion(version.toString()); } catch (ParseException e) { - setError("message.error.format.version"); + setErrorCode("message.error.format.version"); isOk = false; } } if (isOk) { - docname = tool.extractProperty("title"); // Property kept even if the file is not referenced - _documentDate = tool.extractProperty("date"); - if (_documentDate == null) { - _documentDate = ""; - } else { - ResourceBundle locale = ResourceBundle.getBundle("som", - getApplicationSettings().getCurrentLocale()); - SimpleDateFormat check = new SimpleDateFormat(locale - .getString("date.format"), - getApplicationSettings().getCurrentLocale()); - try { - check.parse(_documentDate); - } catch (ParseException e) { - setError("message.error.format.date"); - isOk = false; - } - } + _docname = tool.extractProperty("title"); // Property kept even if the file is not referenced + isOk = extractDate(tool); } } } @@ -234,8 +192,8 @@ public class ImportDocumentAction extends UploadBaseNextAction { } else { if (slot.isUndefined()) { _reference = fileref; // Disables document name and state fields - deftype = slot.getType(); // Just in case - _documentType = deftype.getIndex(); // Disables the document type field + _deftype = slot.getType(); // Just in case + _documentType = _deftype.getIndex(); // Disables the document type field } else { setError("message.error.reference.duplicate"); isOk = false; @@ -244,33 +202,19 @@ public class ImportDocumentAction extends UploadBaseNextAction { return isOk; } - /** - * Set error message and menus. - * - * @param errorCode - * error message key - */ - private void setError(final String errorCode) { - setErrorCode(errorCode); - - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.FALSE, Constants.NONE, - Constants.STUDY_MENU); - } - /** * Perform import of a document. * * @return SUCCESS if ok, "cancel" - if canceled, ERROR - if error */ public String doImport() { - String result = ERROR; + String res = ERROR; initializationScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU, Constants.TRUE); - if (action == ToDo.cancel) { - result = "cancel"; + if (_action == ToDo.cancel) { + res = "cancel"; } else if (_documentType == 0) { setErrorCode("message.error.import.type"); @@ -280,22 +224,22 @@ public class ImportDocumentAction extends UploadBaseNextAction { } else { try { // Getting user inputs - mystudy = getOpenStudy(); + _mystudy = getOpenStudy(); User user = getConnectedUser(); - Step step = mystudy.getSelectedStep(); - Date docdate = null; - if (_documentDate.length() > 0) { + Step step = _mystudy.getSelectedStep(); + Date aDate = null; + if (getDocumentDate().length() > 0) { ResourceBundle locale = ResourceBundle.getBundle("som", getApplicationSettings().getCurrentLocale()); SimpleDateFormat get = new SimpleDateFormat(locale .getString("date.format"), getApplicationSettings() .getCurrentLocale()); - docdate = get.parse(_documentDate); + aDate = get.parse(getDocumentDate()); } // Creation of uses relations List uses = new ArrayList(); - if (docuses != null) { - String[] list = docuses.split(","); + if (_docuses != null) { + String[] list = _docuses.split(","); for (int i = 0; i < list.length; i++) { uses.add(Long.valueOf(list[i].trim())); } @@ -308,12 +252,12 @@ public class ImportDocumentAction extends UploadBaseNextAction { } } Publication addoc = getPublicationService().createDoc( - mystudy.getIndex(), step, _documentType, - user.getIndex(), filename, docname, state, _reference, - _version, docdate, uses); + _mystudy.getIndex(), step, _documentType, + user.getIndex(), _fileName, _docname, _state, _reference, + getVersion(), aDate, uses); if (_reference.length() > 0) { // Importation of a not foreign document - mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document + _mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document } // Creation of derived the document formats @@ -322,8 +266,8 @@ public class ImportDocumentAction extends UploadBaseNextAction { // // if (send != null) send.converts(addoc); // Asynchronous process - mystudy.add(addoc); // Updates the presentation - result = SUCCESS; + _mystudy.add(addoc); // Updates the presentation + res = SUCCESS; } catch (FileNotFoundException error) { LOG.error("Reason:", error); setErrorCode("message.error.import.file"); @@ -332,29 +276,20 @@ public class ImportDocumentAction extends UploadBaseNextAction { setErrorCode("message.error.internal"); } - if (!SUCCESS.equals(result)) { + if (!SUCCESS.equals(res)) { initializationFullScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU, Constants.TRUE, Constants.NONE, Constants.STUDY_MENU); } } - return result; + return res; } // ============================================================================================================================== // Getters and setters // ============================================================================================================================== - /** - * Date extracted from the imported file, if exist. - * - * @return the file date - */ - public String getDocumentDate() { - return _documentDate; - } - /** * Get sorted list of document types valid for the selected study step. * @@ -382,25 +317,6 @@ public class ImportDocumentAction extends UploadBaseNextAction { return _reference; } - /** - * Get version number extracted from the imported file, if exist. - * - * @return the document version - */ - public String getVersion() { - return _version; - } - - /** - * Set date extracted from the imported file. - * - * @param date - * the date to set - */ - public void setDocumentDate(final String date) { - this._documentDate = date; - } - /** * Set document name entered by the user if enabled. * @@ -408,7 +324,7 @@ public class ImportDocumentAction extends UploadBaseNextAction { * the document name */ public void setDocumentName(final String name) { - this.docname = name; // Name entered by the user if enabled + this._docname = name; // Name entered by the user if enabled } /** @@ -418,8 +334,8 @@ public class ImportDocumentAction extends UploadBaseNextAction { * the default document title */ public void setDocumentTitle(final String name) { // Called even if DocumentName is enabled - if (this.docname == null) { - this.docname = name; + if (this._docname == null) { + this._docname = name; } } @@ -440,8 +356,8 @@ public class ImportDocumentAction extends UploadBaseNextAction { * the default state */ public void setDefaultDocumentState(final String state) { // Called even if DocumentState is enabled - if (this.state == null) { - this.state = ProgressState.valueOf(state); + if (this._state == null) { + this._state = ProgressState.valueOf(state); } } @@ -467,75 +383,6 @@ public class ImportDocumentAction extends UploadBaseNextAction { this._reference = value; } - /** - * Set version number extracted from the imported file, if exist. - * - * @param value - * the version - */ - 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 documentService. * @@ -555,25 +402,6 @@ public class ImportDocumentAction extends UploadBaseNextAction { _documentService = documentService; } - /** - * 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 documentTypeService. * @@ -606,4 +434,13 @@ public class ImportDocumentAction extends UploadBaseNextAction { states.add(ProgressState.EXTERN); return states; } + + /** + * Get the isReviewable. + * + * @return the isReviewable + */ + public List getReviewable() { + return _reviewable; + } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java b/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java deleted file mode 100644 index 3091851..0000000 --- a/Workspace/Siman/src/org/splat/simer/UploadBaseNextAction.java +++ /dev/null @@ -1,118 +0,0 @@ -package org.splat.simer; - -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import org.splat.dal.bo.som.Document; -import org.splat.dal.bo.som.DocumentType; -import org.splat.dal.bo.som.ProgressState; -import org.splat.dal.bo.som.Publication; -import org.splat.som.Step; - -public abstract class UploadBaseNextAction extends Action { - - protected OpenStudy mystudy = null; - protected String filename = null; // Uploaded file name - protected DocumentType deftype = null; - protected List defuses = null; - protected String docname = null; - protected ProgressState state = null; - protected String docuses = null; - protected ToDo action = null; - - /** - * Serial version ID. - */ - private static final long serialVersionUID = -6925961099244461039L; - - protected enum ToDo { - cancel, save - }; - - // ============================================================================================================================== - // Getters and setters - // ============================================================================================================================== - - public DocumentType getDefaultDocumentType() { - return deftype; - } - - public List getDefaultDocumentUses() { - return defuses; - } - - public String getDocumentName() { - return docname; - } - - public String getDocumentState() { - return state.toString(); - } - - public String getFileName() { - return filename; - } - - public void setCancel(final boolean cancel) { - this.action = ToDo.cancel; - } - - public void setDocumentState(final String state) { - this.state = ProgressState.valueOf(state); - } - - public void setFileName(final String path) { - this.filename = path; - } - - public void setUses(final String list) { - this.docuses = list; - } - - public void setSave(final boolean save) { - this.action = ToDo.save; - } - - public String getWriteAccess() { - Boolean res = (mystudy != null); - if (res) { - res = mystudy.isOpenForWriting(); - } - return res.toString(); - } - - // ============================================================================================================================== - // Protected services - // ============================================================================================================================== - - protected void setupDefaultUses(final DocumentType type) { - Set uses = type.getDefaultUses(); - - for (Iterator i = uses.iterator(); i.hasNext();) { - DocumentType usetype = i.next(); - List usedoc = mystudy.collectInvolvedDocuments(usetype); - if (usedoc.isEmpty() && (!usetype.equals(type))) { - setupDefaultUses(usetype); - } else { - defuses.addAll(usedoc); - } - } - } - - protected Publication getPublication(final int index) { - List steps = mystudy.getInvolvedSteps(); - Publication found = null, pub; - for (Iterator i = steps.iterator(); i.hasNext();) { - List published = i.next().getAllDocuments(); - for (Iterator j = published.iterator(); j.hasNext();) { - pub = j.next(); // In a given study step, - if (pub.value().getIndex() == index) { - found = pub; // there is only one publication of a given document - break; - } - } - } - return found; - } -} \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index 66778f3..9bf9525 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -2,11 +2,9 @@ package org.splat.simer; 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 java.util.Iterator; import java.util.List; import java.util.ResourceBundle; @@ -17,13 +15,11 @@ import org.splat.dal.bo.som.ProgressState; 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; @@ -31,7 +27,7 @@ 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. @@ -55,33 +51,9 @@ public class VersionDocumentAction extends UploadBaseNextAction { */ 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; - - // ============================================================================================================================== - // Action methods - // ============================================================================================================================== + private transient final List _documentStates = new ArrayList(); /** * Initialize the action form. @@ -89,43 +61,48 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @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); - if ("true".equals(getWriteAccess())) { - setToolProperty(Constants.STUDY_MENU); - } else { - setToolProperty(Constants.NONE); - } - initializationFullScreenContext(Constants.STUDY_MENU, - Constants.STUDY_MENU, Constants.TRUE, getToolProperty(), - Constants.STUDY_MENU); - - User user = getConnectedUser(); - File updir = getRepositoryService().getDownloadDirectory(user); - File upfile = new File(updir.getPath() + "/" + filename); - - mystudy = getOpenStudy(); + _mystudy = getOpenStudy(); + _defuses = new ArrayList(); - Publication tag = mystudy.getSelectedStep().getDocument( + Publication tag = _mystudy.getSelectedStep().getDocument( Integer.valueOf(_index)); Document doc = tag.value(); - deftype = doc.getType(); - docname = doc.getTitle(); - defuses = new ArrayList(); + _deftype = doc.getType(); + _docname = doc.getTitle(); _usedby = new ArrayList(); String res = SUCCESS; if (extractProperties(upfile, doc)) { - setupDefaultUses(deftype); + if (_deftype != null) { + setupDefaultUses(_deftype); + } // Add additional documents used by the current version - List uses = doc.getRelations(UsesRelation.class); - for (Iterator 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(); + if (!_defuses.contains(used)) { + _defuses.add(used); } } + // Avoid recursive using of the document + if (_defuses.contains(doc)) { + _defuses.remove(doc); + } // Setup dependencies _usedby.addAll(tag.getRelations(UsedByRelation.class)); + + // Initialize applicable states list + _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(getToolProperty()))) { initializationFullScreenContext(Constants.STUDY_MENU, @@ -163,11 +140,11 @@ public class VersionDocumentAction extends UploadBaseNextAction { 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; @@ -175,21 +152,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { } 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"); @@ -209,34 +172,35 @@ public class VersionDocumentAction extends UploadBaseNextAction { 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 + _mystudy.setSelection(_mystudy.getSelection()); // Rebuilds the presentation // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document) res = SUCCESS; @@ -260,10 +224,6 @@ public class VersionDocumentAction extends UploadBaseNextAction { // Getters and setters // ============================================================================================================================== - public String getDate() { - return _date; - } - public List getDependencies() { return _usedby; } @@ -276,14 +236,6 @@ public class VersionDocumentAction extends UploadBaseNextAction { 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; @@ -302,85 +254,12 @@ public class VersionDocumentAction extends UploadBaseNextAction { 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. + * Get the documentStates. * - * @param repositoryService - * the repositoryService to set + * @return the documentStates */ - public void setRepositoryService(final RepositoryService repositoryService) { - _repositoryService = repositoryService; + public List getDocumentStates() { + return _documentStates; } } \ No newline at end of file diff --git a/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java b/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java index 376450e..c36bf3e 100644 --- a/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java +++ b/Workspace/Siman/src/org/splat/simer/admin/ImportUserAction.java @@ -7,91 +7,91 @@ import java.util.Set; import org.splat.dal.bo.kernel.User; import org.splat.service.UserService; -import org.splat.service.technical.RepositoryService; -import org.splat.simer.UploadBaseNextAction; +import org.splat.simer.AbstractUploadNextAction; - -public class ImportUserAction extends UploadBaseNextAction { +/** + * Action for importing users from file to the database. + */ +public class ImportUserAction extends AbstractUploadNextAction { /** * Serial version ID. */ - private static final long serialVersionUID = 1516715800624817965L; + private static final long serialVersionUID = 1516715800624817965L; - private transient List _users; - private transient Set _newsers; /** - * Injected repository service. + * All users in the database. */ - private RepositoryService _repositoryService; - + private transient List _users; + /** + * New just imported users which were not in the database before. + */ + private transient Set _newsers; /** * Injected user service. */ private UserService _userService; - -// ============================================================================================================================== -// Action methods -// ============================================================================================================================== - public String doImport () { - String res = SUCCESS; - try { - User user = getConnectedUser(); // The database administrator - File updir = getRepositoryService().getDownloadDirectory(user); - File upfile = new File(updir.getPath() + "/" + filename); + // ============================================================================================================================== + // Action methods + // ============================================================================================================================== - _newsers = getUserService().importUsers(upfile); - _users = getUserService().selectAllUsers(); - for (Iterator i=_users.iterator(); i.hasNext(); ) { - User next = i.next(); - if (!next.equals(user)) { - continue; - } - i.remove(); // Just for not showing the corresponding reserved username - break; - } - - initializationFullScreenContext("sysadmin", "none", "open"); - } - catch (Exception error) { - res = ERROR; - } - return res; - } - -// ============================================================================================================================== -// Getters -// ============================================================================================================================== + /** + * Import users from file into the database. + * + * @return SUCCESS if ok, otherwise - ERROR + */ + public String doImport() { + String res = SUCCESS; + try { + User user = getConnectedUser(); // The database administrator + File updir = getRepositoryService().getDownloadDirectory(user); + File upfile = new File(updir.getPath() + "/" + _fileName); + + _newsers = getUserService().importUsers(upfile); + _users = getUserService().selectAllUsers(); + for (Iterator i = _users.iterator(); i.hasNext();) { + User next = i.next(); + if (next.equals(user)) { + i.remove(); // Just for not showing the corresponding reserved username + break; + } + } - public List getUsers () { -// ----------------------------- - return _users; - } + initializationFullScreenContext("sysadmin", "none", "open"); + } catch (Exception error) { + res = ERROR; + } + return res; + } - public boolean isNew (final User user) { -// -------------------------------- - return _newsers.contains(user); - } + // ============================================================================================================================== + // Getters + // ============================================================================================================================== /** - * Get the repositoryService. - * @return the repositoryService + * Get all users from the database. + * + * @return list of all users from the database */ - public RepositoryService getRepositoryService() { - return _repositoryService; + public List getUsers() { + return _users; } /** - * Set the repositoryService. - * @param repositoryService the repositoryService to set + * Check if the user is a new one that is it was not in the database before. + * + * @param user + * the user to check + * @return true if the user is new */ - public void setRepositoryService(final RepositoryService repositoryService) { - _repositoryService = repositoryService; + public boolean isNew(final User user) { + return _newsers.contains(user); } /** * Get the userService. + * * @return the userService */ public UserService getUserService() { @@ -100,7 +100,9 @@ public class ImportUserAction extends UploadBaseNextAction { /** * Set the userService. - * @param userService the userService to set + * + * @param userService + * the userService to set */ public void setUserService(final UserService userService) { _userService = userService; diff --git a/Workspace/Siman/src/spring/applicationContext.xml b/Workspace/Siman/src/spring/applicationContext.xml index 47ee0e9..1481b2a 100644 --- a/Workspace/Siman/src/spring/applicationContext.xml +++ b/Workspace/Siman/src/spring/applicationContext.xml @@ -140,6 +140,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + @@ -281,6 +282,7 @@ http://www.springframework.org/schema/context/spring-context-3.0.xsd"> + -- 2.30.2