X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=Workspace%2FSiman%2Fsrc%2Forg%2Fsplat%2Fsimer%2FVersionDocumentAction.java;h=9f975c0311c054d034c689c236ef2f0da43bdd88;hb=81e0cd22ce9eb29d2b36bbeb1eda8c9be0f5621c;hp=98550dc2488e751476a50474ea7e1a51f46cd3b5;hpb=f3ca2dec8c9fdfeac0b9ecac5d5783a6aa4f6c3a;p=tools%2Fsiman.git diff --git a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java index 98550dc..9f975c0 100644 --- a/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java +++ b/Workspace/Siman/src/org/splat/simer/VersionDocumentAction.java @@ -4,28 +4,29 @@ 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; -import java.util.Vector; -import org.splat.kernel.InvalidPropertyException; import org.splat.dal.bo.kernel.Relation; import org.splat.dal.bo.kernel.User; -import org.splat.manox.Reader; -import org.splat.manox.Toolbox; import org.splat.dal.bo.som.Document; 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.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.dal.bo.som.Publication; import org.splat.som.Revision; import org.splat.som.Step; -import org.splat.dal.bo.som.UsedByRelation; -import org.splat.dal.bo.som.UsesRelation; +import org.splat.wapp.Constants; /** * Action for creating a new version of a document. @@ -40,31 +41,31 @@ public class VersionDocumentAction extends UploadBaseNextAction { /** * Versioned document index. */ - private String index = null; + private String _index = null; /** * List of publications which use the selected document. */ - private List usedby = null; + private transient List _usedby = null; /** * List of selected impacted documents ids. */ - private long[] docusedby = null; + private transient long[] _docusedby = null; /** * Summary of changes in the new version. */ - private String summary = null; + private String _description = null; /** * Version number extracted from the imported file, if exist. */ - private String docver = ""; + private String _version = ""; /** * Date extracted from the imported file, if exist. */ - private String date = ""; + private String _date = ""; /** * Injected project settings service. */ - private ProjectSettingsService _projectSettingsService; + private ProjectSettingsService _projectSettings; /** * Injected publication service. */ @@ -87,6 +88,16 @@ public class VersionDocumentAction extends UploadBaseNextAction { */ 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. + */ + 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. @@ -104,11 +115,17 @@ public class VersionDocumentAction extends UploadBaseNextAction { */ public String doInitialize() { - setMenuProperty("study"); - setTitleProperty("study"); + setMenuProperty(Constants.STUDY_MENU); + setTitleProperty(Constants.STUDY_MENU); setEditDisabledProperty("true"); - initializationScreenContext(_menuProperty, _titleProperty, - _editDisabledProperty); + 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); @@ -117,30 +134,36 @@ public class VersionDocumentAction extends UploadBaseNextAction { mystudy = getOpenStudy(); Publication tag = mystudy.getSelectedStep().getDocument( - Integer.valueOf(index)); + Integer.valueOf(_index)); Document doc = tag.value(); deftype = doc.getType(); docname = doc.getTitle(); - defuses = new Vector(); - usedby = new Vector(); - - if (!extractProperties(upfile, doc)) { - return ERROR; - } - 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); - } - // Setup dependencies - List relist = tag.getRelations(UsedByRelation.class); - for (Iterator i = relist.iterator(); i.hasNext();) { - usedby.add(i.next()); + defuses = new ArrayList(); + _usedby = new ArrayList(); + + String res = SUCCESS; + if (extractProperties(upfile, doc)) { + 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); + } + } + // Setup dependencies + _usedby.addAll(tag.getRelations(UsedByRelation.class)); + } else { + if (!(Constants.NONE.equals(_toolProperty))) { + setToolProperty(Constants.NONE); + setLeftMenuProperty(Constants.STUDY_MENU); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); + } + res = ERROR; } - return SUCCESS; + return res; } /** @@ -152,16 +175,13 @@ public class VersionDocumentAction extends UploadBaseNextAction { * the document to version * @return true if succeeded or if the file is not XML, otherwise return false */ - private boolean extractProperties(File upfile, Document doc) { + private boolean extractProperties(final File upfile, final Document doc) { boolean res = true; Reader tool = Toolbox.getReader(upfile); if (tool != null) { String fileref = tool.extractProperty("reference"); String filever = tool.extractProperty("version"); - if (fileref != null && !doc.getReference().equals(fileref)) { - setErrorCode("reference.mismatch"); - res = false; - } else { + if (fileref == null || doc.getReference().equals(fileref)) { if (filever != null) { try { Revision.Format get = new Revision.Format( @@ -176,30 +196,33 @@ public class VersionDocumentAction extends UploadBaseNextAction { } else { state = ProgressState.inDRAFT; } - docver = newver.toString(); + _version = newver.toString(); } catch (Exception e) { - setErrorCode("version.mismatch"); + setErrorCode("message.error.version.mismatch"); res = false; } } if (res) { - summary = tool.extractProperty("history"); - date = tool.extractProperty("date"); - if (date != null) { + _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); + check.parse(_date); } catch (ParseException e) { - setErrorCode("format.date"); + setErrorCode("message.error.format.date"); res = false; } - } else { - date = ""; } } + } else { + setErrorCode("message.error.reference.mismatch"); + res = false; } } return res; @@ -211,50 +234,60 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @return SUCCESS - if succeeded, "cancel" - if canceled, ERROR - if failed */ public String doVersion() { - setMenuProperty("study"); - setTitleProperty("study"); + String res = ERROR; + setMenuProperty(Constants.STUDY_MENU); + setTitleProperty(Constants.STUDY_MENU); setEditDisabledProperty("true"); initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty); - if (action == ToDo.cancel) - return "cancel"; - - try { - // Getting user inputs - mystudy = getOpenStudy(); - User user = getConnectedUser(); - Step step = mystudy.getSelectedStep(); - Date aDate = null; - if (date.length() > 0) { - ResourceBundle locale = ResourceBundle.getBundle("som", - getApplicationSettings().getCurrentLocale()); - SimpleDateFormat get = new SimpleDateFormat(locale - .getString("date.format")); - aDate = get.parse(date); + if (action == ToDo.cancel) { + res = "cancel"; + } else { + + try { + // Getting user inputs + mystudy = getOpenStudy(); + User user = getConnectedUser(); + Step step = mystudy.getSelectedStep(); + Date aDate = null; + if (_date.length() > 0) { + ResourceBundle locale = ResourceBundle.getBundle("som", + getApplicationSettings().getCurrentLocale()); + SimpleDateFormat get = new SimpleDateFormat(locale + .getString("date.format")); + aDate = get.parse(_date); + } + + String[] listDocuses = null; + if (docuses != null) { + listDocuses = docuses.split(","); + } + getPublicationService().versionDocument(step, user, filename, + Integer.valueOf(_index), _version, _description, state, + aDate, listDocuses, _docusedby); + + // Update of the open study + 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; + } 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(res)) { + setToolProperty(Constants.NONE); - String[] listDocuses = null; - if (docuses != null) { - listDocuses = docuses.split(","); + setLeftMenuProperty(Constants.STUDY_MENU); + initializationFullScreenContext(_menuProperty, _titleProperty, + _editDisabledProperty, _toolProperty, _leftMenuProperty); } - getPublicationService().versionDocument(step, user, filename, - Integer.valueOf(index), docver, summary, state, aDate, - listDocuses, docusedby); - - // Update of the open study - mystudy.setSelection(mystudy.getSelection()); // Rebuilds the presentation - // TODO: Look is an optimization is possible (for example by updating the presentation of versioned document) - - return SUCCESS; - } catch (FileNotFoundException error) { - logger.error("Reason:", error); - setErrorCode("import.file"); - } catch (Exception error) { - logger.error("Reason:", error); - setErrorCode("internal"); } - return ERROR; + return res; } // ============================================================================================================================== @@ -262,48 +295,49 @@ public class VersionDocumentAction extends UploadBaseNextAction { // ============================================================================================================================== public String getDate() { - return date; + return _date; } public List getDependencies() { - return usedby; + return _usedby; } public String getDescription() { - return summary; + return _description; } public String getIndex() { - return index; + return _index; } public String getVersion() { - return docver; + return _version; } - public void setDate(String date) { - this.date = date; + public void setDate(final String date) { + this._date = date; } - public void setDefaultDescription(String summary) { - if (this.summary == null) - this.summary = summary; + public void setDefaultDescription(final String summary) { + if (this._description == null) { + this._description = summary; + } } - public void setDescription(String summary) { - this.summary = summary; + public void setDescription(final String summary) { + this._description = summary; } - public void setIndex(String index) { - this.index = index; + public void setIndex(final String index) { + this._index = index; } - public void setUsedBy(long[] list) { - this.docusedby = list; + public void setUsedBy(final long[] list) { + this._docusedby = list; } - public void setVersion(String value) { - this.docver = value; + public void setVersion(final String value) { + this._version = value; } /** @@ -312,7 +346,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @return Project settings service */ private ProjectSettingsService getProjectSettings() { - return _projectSettingsService; + return _projectSettings; } /** @@ -321,8 +355,9 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param projectSettingsService * project settings service */ - public void setProjectSettings(ProjectSettingsService projectSettingsService) { - _projectSettingsService = projectSettingsService; + public void setProjectSettings( + final ProjectSettingsService projectSettingsService) { + _projectSettings = projectSettingsService; } /** @@ -340,7 +375,8 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param publicationService * the publicationService to set */ - public void setPublicationService(PublicationService publicationService) { + public void setPublicationService( + final PublicationService publicationService) { _publicationService = publicationService; } @@ -359,7 +395,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param stepService * the stepService to set */ - public void setStepService(StepService stepService) { + public void setStepService(final StepService stepService) { _stepService = stepService; } @@ -378,7 +414,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param repositoryService * the repositoryService to set */ - public void setRepositoryService(RepositoryService repositoryService) { + public void setRepositoryService(final RepositoryService repositoryService) { _repositoryService = repositoryService; } @@ -397,7 +433,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param menuProperty * the menuProperty to set */ - public void setMenuProperty(String menuProperty) { + public void setMenuProperty(final String menuProperty) { this._menuProperty = menuProperty; } @@ -416,7 +452,7 @@ public class VersionDocumentAction extends UploadBaseNextAction { * @param titleProperty * the titleProperty to set */ - public void setTitleProperty(String titleProperty) { + public void setTitleProperty(final String titleProperty) { _titleProperty = titleProperty; } @@ -430,12 +466,50 @@ public class VersionDocumentAction extends UploadBaseNextAction { } /** - * Set the _editDisabledProperty. + * Set the editDisabledProperty. + * + * @param editDisabledProperty + * the editDisabledProperty to set + */ + public void setEditDisabledProperty(final String editDisabledProperty) { + this._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. + * + * @return the leftMenuProperty + */ + public String getLeftMenuProperty() { + return _leftMenuProperty; + } + + /** + * Set the leftMenuProperty. * - * @param _editDisabledProperty - * the _editDisabledProperty to set + * @param leftMenuProperty + * the leftMenuProperty to set */ - public void setEditDisabledProperty(String _editDisabledProperty) { - this._editDisabledProperty = _editDisabledProperty; + public void setLeftMenuProperty(final String leftMenuProperty) { + _leftMenuProperty = leftMenuProperty; } } \ No newline at end of file