]> SALOME platform Git repositories - tools/siman.git/blobdiff - Workspace/Siman/src/org/splat/simer/ImportDocumentAction.java
Salome HOME
JSP are updated to use more struts tags. Javadoc comments are added.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / ImportDocumentAction.java
index faf4dfe9cf42146190b7c34253e4d36f6cb3652c..1b376a440f86e0cf9cba38fd38c945f4eed2c546 100644 (file)
@@ -38,7 +38,13 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         */
        private static final long serialVersionUID = 2587822564883588556L;
 
+       /**
+        * Sorted list of document types for the selected study step.
+        */
        private transient List<DocumentType> _documentTypes = null;
+       /**
+        * The selected document type.
+        */
        private long _documentType = 0;
        /**
         * Reference extracted from the imported file, if exist.
@@ -109,7 +115,7 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                // Set the document type by default
                deftype = getApplicationSettings().getDefaultDocumentType(step, filext);
                if (deftype != null) {
-                       setDefaultDocumentType(Long.toString(deftype.getIndex()));
+                       setDefaultDocumentType(deftype.getIndex());
                }
                defuses = new ArrayList<Document>();
                state = ProgressState.inWORK;
@@ -196,7 +202,8 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                                                ResourceBundle locale = ResourceBundle.getBundle("som",
                                                                getApplicationSettings().getCurrentLocale());
                                                SimpleDateFormat check = new SimpleDateFormat(locale
-                                                               .getString("date.format"));
+                                                               .getString("date.format"),
+                                                               getApplicationSettings().getCurrentLocale());
                                                try {
                                                        check.parse(_documentDate);
                                                } catch (ParseException e) {
@@ -257,80 +264,82 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         * @return SUCCESS if ok, "cancel" - if canceled, ERROR - if error
         */
        public String doImport() {
+               String result = ERROR;
 
                initializationScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU,
                                Constants.TRUE);
 
                if (action == ToDo.cancel) {
-                       return "cancel";
-               }
-               if (_documentType == 0) {
+                       result = "cancel";
+               } else if (_documentType == 0) {
                        setErrorCode("message.error.import.type");
 
                        initializationFullScreenContext(Constants.STUDY_MENU,
                                        Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
                                        Constants.STUDY_MENU);
-
-                       return ERROR;
-               }
-               try {
-                       // Getting user inputs
-                       mystudy = getOpenStudy();
-                       User user = getConnectedUser();
-                       Step step = mystudy.getSelectedStep();
-                       Date docdate = null;
-                       if (_documentDate.length() > 0) {
-                               ResourceBundle locale = ResourceBundle.getBundle("som",
-                                               getApplicationSettings().getCurrentLocale());
-                               SimpleDateFormat get = new SimpleDateFormat(locale
-                                               .getString("date.format"));
-                               docdate = get.parse(_documentDate);
-                       }
-                       // Creation of uses relations
-                       List<Long> uses = new ArrayList<Long>();
-                       if (docuses != null) {
-                               String[] list = docuses.split(",");
-                               for (int i = 0; i < list.length; i++) {
-                                       uses.add(Long.valueOf(list[i].trim()));
+               } else {
+                       try {
+                               // Getting user inputs
+                               mystudy = getOpenStudy();
+                               User user = getConnectedUser();
+                               Step step = mystudy.getSelectedStep();
+                               Date docdate = null;
+                               if (_documentDate.length() > 0) {
+                                       ResourceBundle locale = ResourceBundle.getBundle("som",
+                                                       getApplicationSettings().getCurrentLocale());
+                                       SimpleDateFormat get = new SimpleDateFormat(locale
+                                                       .getString("date.format"), getApplicationSettings()
+                                                       .getCurrentLocale());
+                                       docdate = get.parse(_documentDate);
                                }
-                       }
-                       if (LOG.isDebugEnabled()) {
-                               LOG
-                                               .debug("Document to be imported uses documents with following ids:");
-                               for (Long usesId : uses) {
-                                       LOG.debug("#" + usesId);
+                               // Creation of uses relations
+                               List<Long> uses = new ArrayList<Long>();
+                               if (docuses != null) {
+                                       String[] list = docuses.split(",");
+                                       for (int i = 0; i < list.length; i++) {
+                                               uses.add(Long.valueOf(list[i].trim()));
+                                       }
                                }
-                       }
-                       Publication addoc = getPublicationService().createDoc(
-                                       mystudy.getIndex(), step, _documentType, user.getIndex(),
-                                       filename, docname, state, _reference, _version, docdate,
-                                       uses);
+                               if (LOG.isDebugEnabled()) {
+                                       LOG
+                                                       .debug("Document to be imported uses documents with following ids:");
+                                       for (Long usesId : uses) {
+                                               LOG.debug("#" + usesId);
+                                       }
+                               }
+                               Publication addoc = getPublicationService().createDoc(
+                                               mystudy.getIndex(), step, _documentType,
+                                               user.getIndex(), filename, docname, state, _reference,
+                                               _version, docdate, uses);
 
-                       if (_reference.length() > 0) { // Importation of a not foreign document
-                               mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document
+                               if (_reference.length() > 0) { // Importation of a not foreign document
+                                       mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document
+                               }
+
+                               // Creation of derived the document formats
+                               // Document ndoc = addoc.value();
+                               // Converter send = getApplicationSettings().getConverter(ndoc.getType(), ndoc.getFormat());
+                               //
+                               // if (send != null) send.converts(addoc); // Asynchronous process
+
+                               mystudy.add(addoc); // Updates the presentation
+                               result = SUCCESS;
+                       } catch (FileNotFoundException error) {
+                               LOG.error("Reason:", error);
+                               setErrorCode("message.error.import.file");
+                       } catch (Exception error) {
+                               LOG.error("Reason:", error);
+                               setErrorCode("message.error.internal");
                        }
 
-                       // Creation of derived the document formats
-                       // Document ndoc = addoc.value();
-                       // Converter send = getApplicationSettings().getConverter(ndoc.getType(), ndoc.getFormat());
-                       //
-                       // if (send != null) send.converts(addoc); // Asynchronous process
-
-                       mystudy.add(addoc); // Updates the presentation
-                       return SUCCESS;
-               } catch (FileNotFoundException error) {
-                       LOG.error("Reason:", error);
-                       setErrorCode("message.error.import.file");
-               } catch (Exception error) {
-                       LOG.error("Reason:", error);
-                       setErrorCode("message.error.internal");
+                       if (!SUCCESS.equals(result)) {
+                               initializationFullScreenContext(Constants.STUDY_MENU,
+                                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+                                               Constants.STUDY_MENU);
+                       }
                }
 
-               initializationFullScreenContext(Constants.STUDY_MENU,
-                               Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
-                               Constants.STUDY_MENU);
-
-               return ERROR;
+               return result;
        }
 
        // ==============================================================================================================================
@@ -346,6 +355,11 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                return _documentDate;
        }
 
+       /**
+        * Get sorted list of document types valid for the selected study step.
+        * 
+        * @return sorted list of document types
+        */
        public List<DocumentType> getDocumentTypes() {
                return _documentTypes;
        }
@@ -397,6 +411,12 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                this.docname = name; // Name entered by the user if enabled
        }
 
+       /**
+        * Set the default title if no title was defined.
+        * 
+        * @param name
+        *            the default document title
+        */
        public void setDocumentTitle(final String name) { // Called even if DocumentName is enabled
                if (this.docname == null) {
                        this.docname = name;
@@ -409,19 +429,31 @@ public class ImportDocumentAction extends UploadBaseNextAction {
         * @param value
         *            the id as string
         */
-       public void setDocumentType(final String value) {
-               this._documentType = Integer.valueOf(value);
+       public void setDocumentType(final Long value) {
+               this._documentType = value;
        }
 
+       /**
+        * Set the default state if no state was selected.
+        * 
+        * @param state
+        *            the default state
+        */
        public void setDefaultDocumentState(final String state) { // Called even if DocumentState is enabled
                if (this.state == null) {
                        this.state = ProgressState.valueOf(state);
                }
        }
 
-       public void setDefaultDocumentType(final String value) { // Called even if DocumentType is enabled
+       /**
+        * Set the default type if no type was selected.
+        * 
+        * @param value
+        *            the default document type id
+        */
+       public void setDefaultDocumentType(final Long value) { // Called even if DocumentType is enabled
                if (this._documentType == 0) {
-                       this._documentType = Integer.valueOf(value);
+                       this._documentType = value;
                }
        }
 
@@ -561,4 +593,17 @@ public class ImportDocumentAction extends UploadBaseNextAction {
                        final DocumentTypeService documentTypeService) {
                _documentTypeService = documentTypeService;
        }
+
+       /**
+        * Get sorted list of available document states.
+        * 
+        * @return the documentStates
+        */
+       public List<ProgressState> getDocumentStates() {
+               List<ProgressState> states = new ArrayList<ProgressState>();
+               states.add(ProgressState.inWORK);
+               states.add(ProgressState.inDRAFT);
+               states.add(ProgressState.EXTERN);
+               return states;
+       }
 }
\ No newline at end of file