*/
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.
// 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;
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) {
* @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;
}
// ==============================================================================================================================
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;
}
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;
* @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;
}
}
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