]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Salome HOME
Fix for mantis #0022093: To exclude the "In-Draft" state from drop-down list during...
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ImportDocumentAction.java
index 1b376a440f86e0cf9cba38fd38c945f4eed2c546..a3a4de2ebebe77981383781d4ed671de829bfc4f 100644 (file)
@@ -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<DocumentType> _documentTypes = null;
+       /**
+        * Sorted list of document types for the selected study step.
+        */
+       private transient final List<Boolean> _reviewable = new ArrayList<Boolean>();
        /**
         * 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<Document>();
-               state = ProgressState.inWORK;
+               _defuses = new ArrayList<Document>();
+               _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<Long> uses = new ArrayList<Long>();
-                               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<Boolean> getReviewable() {
+               return _reviewable;
+       }
 }
\ No newline at end of file