import java.io.File;
import java.io.FileNotFoundException;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
-import java.util.Iterator;
import java.util.List;
import java.util.ResourceBundle;
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;
/**
* Action for adding a document into a study step.
*/
-public class ImportDocumentAction extends UploadBaseNextAction {
+public class ImportDocumentAction extends BaseUploadDocumentAction {
/**
* Serial version ID.
*/
private static final long serialVersionUID = 2587822564883588556L;
- private transient List<DocumentType> _documentTypes = null;
- private long _documentType = 0;
- /**
- * Reference extracted from the imported file, if exist.
- */
- private String _reference = null;
/**
- * Version number extracted from the imported file, if exist.
+ * Sorted list of document types for the selected study step.
*/
- private String _version = "";
- /**
- * Date extracted from the imported file, if exist.
- */
- private String _documentDate = "";
+ private transient List<DocumentType> _documentTypes = null;
/**
- * Injected project settings service.
+ * Sorted list of document types for the selected study step.
*/
- private ProjectSettingsService _projectSettings;
+ private transient final List<Boolean> _reviewable = new ArrayList<Boolean>();
/**
- * Injected publication service.
+ * The selected document type.
*/
- private PublicationService _publicationService;
+ private long _documentType = 0;
/**
- * Injected step service.
+ * Reference extracted from the imported file, if exist.
*/
- private StepService _stepService;
+ private String _reference = null;
/**
* Injected document service.
*/
* Injected document type service.
*/
private DocumentTypeService _documentTypeService;
- /**
- * Injected repository service.
- */
- private RepositoryService _repositoryService;
- /**
- * Value of the menu property. It can be: none, create, open, study, knowledge, sysadmin, help.
- */
- private String _menuProperty;
-
- /**
- * Value of the title bar property. It can be: study, knowledge.
- */
- private String _titleProperty;
-
- /**
- * Value of the tool bar property. It can be: none, standard, study, back.
- */
- private String _toolProperty;
/**
- * Value of the left menu property. It can be: open, study, knowledge, scenario.
+ * Update uses documents list if chosen new type of import document.
+ * @return SUCCESS
*/
- private String _leftMenuProperty;
-
- /**
- * Property that indicates whether the current open study is editable or not. On the screen it looks like pen on the status icon, pop-up
- * menu also can be called. It is necessary for correct building the title bar.
- */
- private String _editDisabledProperty = "false";
-
- // ==============================================================================================================================
- // Action methods
- // ==============================================================================================================================
+ public final String updateUsesList() {
+ _mystudy = getOpenStudy();
+ _defuses = new ArrayList<Document>();
+ _deftype = getDocumentTypeService().selectType(
+ (int) _documentType);
+ if (_deftype != null) {
+ setupDefaultUses(_deftype);
+ }
+ return SUCCESS;
+ }
/**
* Initialize the operation.
*/
public String doInitialize() {
- setMenuProperty(Constants.STUDY_MENU);
- setTitleProperty(Constants.STUDY_MENU);
- setEditDisabledProperty("true");
- if ("true".equals(getWriteAccess())) {
- setToolProperty(Constants.STUDY_MENU);
- } else {
- setToolProperty(Constants.NONE);
- }
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
-
- User user = getConnectedUser();
- File updir = getRepositoryService().getDownloadDirectory(user);
- File upfile = new File(updir.getPath() + "/" + filename);
- 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);
- deftype = getApplicationSettings().getDefaultDocumentType(step, filext);
- defuses = new ArrayList<Document>();
- state = ProgressState.inWORK;
+ // Set the document type by default
+ _deftype = getApplicationSettings()
+ .getDefaultDocumentType(step, filext);
+ if (_deftype != null) {
+ setDefaultDocumentType(_deftype.getIndex());
+ }
+ _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
_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;
}
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");
- String filever = tool.extractProperty("version"); // Property kept even if the file is not referenced
- String filetype = tool.extractProperty("type"); // Property kept even if the file is not referenced
- for (Iterator<DocumentType> i = _documentTypes.iterator(); i
- .hasNext();) {
- DocumentType type = i.next();
- if (type.getName().equals(filetype)) {
- deftype = type;
- _documentType = type.getIndex(); // Disables the document type field
- break;
- }
- }
- if (fileref != null) {
- isOk = findTypeByDocRef(fileref);
- }
- if (isOk) {
- if (filever != null) {
- try {
- Revision.Format get = new Revision.Format(
- getProjectSettings().getRevisionPattern());
- Revision version = get.parse(filever);
- if (version.isNull()) {
- throw new ParseException(filever,
- filever.length() - 1);
- }
- if (!version.isMinor()) {
- state = ProgressState.inCHECK;
- }
- _version = version.toString();
- } catch (ParseException e) {
- setError("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"));
- try {
- check.parse(_documentDate);
- } catch (ParseException e) {
- setError("message.error.format.date");
- isOk = false;
- }
- }
- }
- }
+ // String fileref = tool.extractProperty("reference");
+ // String filever = tool.extractProperty("version"); // Property kept even if the file is not referenced
+ // String filetype = tool.extractProperty("type"); // Property kept even if the file is not referenced
+ // for (Iterator<DocumentType> i = _documentTypes.iterator(); i
+ // .hasNext();) {
+ // DocumentType type = i.next();
+ // if (type.getName().equals(filetype)) {
+ // _deftype = type;
+ // _documentType = type.getIndex(); // Disables the document type field
+ // break;
+ // }
+ // }
+ // if (fileref != null) {
+ // isOk = findTypeByDocRef(fileref);
+ // }
+ // if (isOk) {
+ // if (filever != null) {
+ // try {
+ // Revision.Format get = new Revision.Format(
+ // getProjectSettings().getRevisionPattern());
+ // Revision version = get.parse(filever);
+ // if (version.isNull()) {
+ // throw new ParseException(filever,
+ // filever.length() - 1);
+ // }
+ // if (!version.isMinor()) {
+ // _state = ProgressState.inCHECK;
+ // }
+ // setVersion(version.toString());
+ // } catch (ParseException e) {
+ // setErrorCode("message.error.format.version");
+ // isOk = false;
+ // }
+ // }
+ // if (isOk) {
+ // _docname = tool.extractProperty("title"); // Property kept even if the file is not referenced
+ // isOk = extractDate(tool);
+ // }
+ // }
}
return isOk;
}
} 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;
return isOk;
}
- /**
- * Set error message and menus.
- *
- * @param errorCode
- * error message key
- */
- private void setError(final String errorCode) {
- setErrorCode(errorCode);
-
- setToolProperty(Constants.NONE);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
- }
-
/**
* Perform import of a document.
*
* @return SUCCESS if ok, "cancel" - if canceled, ERROR - if error
*/
public String doImport() {
+ String res = ERROR;
- setMenuProperty(Constants.STUDY_MENU);
- setTitleProperty(Constants.STUDY_MENU);
- setEditDisabledProperty("true");
- initializationScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty);
+ initializationScreenContext(Constants.STUDY_MENU, Constants.STUDY_MENU,
+ Constants.TRUE);
- if (action == ToDo.cancel) {
- return "cancel";
- }
if (_documentType == 0) {
setErrorCode("message.error.import.type");
- setToolProperty(Constants.NONE);
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+ Constants.STUDY_MENU);
+ } else {
+ try {
+ // Getting user inputs
+ _mystudy = getOpenStudy();
+ _mystudy.updateCurrentStep(); //update current step
+ User user = getConnectedUser();
+ 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());
+ aDate = get.parse(getDocumentDate());
+ }
+ // 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()));
+ }
+ }
+ 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, getVersion(), aDate, uses);
- 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()));
+ if (_reference.length() > 0) { // Importation of a not foreign document
+ _mystudy.updateSimulationContexts(); // In case of simulation contexts extracted from the imported document
}
- }
- if (LOG.isDebugEnabled()) {
- LOG.debug("Document to be imported uses documents with following ids:");
- for (Long usesId: uses) {
- LOG.debug("#" + usesId);
+
+ // 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
+
+ if (uses.isEmpty()) {
+ _mystudy.add(addoc); // Updates the presentation
+ } else {
+ // Re-opening (refreshing) the currently open study
+ refreshStudy();
}
+ res = SUCCESS;
+ } catch (FileNotFoundException error) {
+ LOG.error("Reason:", error);
+ setErrorCode("message.error.import.file");
+ } catch (Exception error) {
+ LOG.error("Reason:", error);
+ setErrorCode("message.error.internal");
}
- 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 (!SUCCESS.equals(res)) {
+ initializationFullScreenContext(Constants.STUDY_MENU,
+ Constants.STUDY_MENU, Constants.TRUE, Constants.NONE,
+ Constants.STUDY_MENU);
}
-
- // 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");
}
- setToolProperty(Constants.NONE);
- setLeftMenuProperty(Constants.STUDY_MENU);
- initializationFullScreenContext(_menuProperty, _titleProperty,
- _editDisabledProperty, _toolProperty, _leftMenuProperty);
-
- return ERROR;
+ return res;
}
// ==============================================================================================================================
// ==============================================================================================================================
/**
- * Date extracted from the imported file, if exist.
+ * Get sorted list of document types valid for the selected study step.
*
- * @return the file date
+ * @return sorted list of document types
*/
- public String getDocumentDate() {
- return _documentDate;
- }
-
public List<DocumentType> getDocumentTypes() {
return _documentTypes;
}
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.
*
* 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
}
+ /**
+ * 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;
+ 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);
+ 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;
}
}
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.
*
_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.
*
}
/**
- * Get the menuProperty.
- *
- * @return the menuProperty
- */
- public String getMenuProperty() {
- return _menuProperty;
- }
-
- /**
- * Set the menuProperty.
- *
- * @param menuProperty
- * the menuProperty to set
- */
- public void setMenuProperty(final String menuProperty) {
- this._menuProperty = menuProperty;
- }
-
- /**
- * Get the _titleProperty.
- *
- * @return the _titleProperty
- */
- public String getTitleProperty() {
- return _titleProperty;
- }
-
- /**
- * Set the titleProperty.
- *
- * @param titleProperty
- * the titleProperty to set
- */
- public void setTitleProperty(final String titleProperty) {
- _titleProperty = titleProperty;
- }
-
- /**
- * Get the editDisabledProperty.
- *
- * @return the editDisabledProperty
- */
- public final String getEditDisabledProperty() {
- return _editDisabledProperty;
- }
-
- /**
- * Set the editDisabledProperty.
- *
- * @param editDisabledProperty
- * the editDisabledProperty to set
- */
- public final void setEditDisabledProperty(final String editDisabledProperty) {
- _editDisabledProperty = editDisabledProperty;
- }
-
- /**
- * Get the toolProperty.
- *
- * @return the toolProperty
- */
- public String getToolProperty() {
- return _toolProperty;
- }
-
- /**
- * Set the toolProperty.
- *
- * @param toolProperty
- * the toolProperty to set
- */
- public void setToolProperty(final String toolProperty) {
- _toolProperty = toolProperty;
- }
-
- /**
- * Get the leftMenuProperty.
+ * Get sorted list of available document states.
*
- * @return the leftMenuProperty
+ * @return the documentStates
*/
- public String getLeftMenuProperty() {
- return _leftMenuProperty;
+ public List<ProgressState> getDocumentStates() {
+ List<ProgressState> states = new ArrayList<ProgressState>();
+ states.add(ProgressState.inWORK);
+ states.add(ProgressState.inDRAFT);
+ states.add(ProgressState.EXTERN);
+ return states;
}
/**
- * Set the leftMenuProperty.
+ * Get the isReviewable.
*
- * @param leftMenuProperty
- * the leftMenuProperty to set
+ * @return the isReviewable
*/
- public void setLeftMenuProperty(final String leftMenuProperty) {
- _leftMenuProperty = leftMenuProperty;
+ public List<Boolean> getReviewable() {
+ return _reviewable;
}
-}
\ No newline at end of file
+}