]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Salome HOME
Actions menu properties are refactored, unnecessary code is removed.
[tools/siman.git] / Workspace / Siman / src / org / splat / simer / EditDocumentAction.java
1 package org.splat.simer;
2
3 import java.io.File;
4 import java.util.Calendar;
5
6 import org.splat.dal.bo.kernel.User;
7 import org.splat.dal.bo.som.ConvertsRelation;
8 import org.splat.dal.bo.som.Publication;
9 import org.splat.kernel.InvalidPropertyException;
10 import org.splat.service.PublicationService;
11 import org.splat.service.StepService;
12 import org.splat.service.technical.RepositoryService;
13 import org.splat.som.Step;
14
15 /**
16  * Document modification action.
17  */
18 public class EditDocumentAction extends DisplayStudyStepAction {
19
20         /**
21          * Serial version ID.
22          */
23         private static final long serialVersionUID = 4573036736137033679L;
24
25         private transient String _index = null;
26         private transient String _title = null;
27         private transient String _filename = null;
28         /**
29          * Injected publication service.
30          */
31         private PublicationService _publicationService;
32         /**
33          * Injected step service.
34          */
35         private StepService _stepService;
36         /**
37          * Injected repository service.
38          */
39         private RepositoryService _repositoryService;
40
41         /**
42          * Operations enumeration.
43          */
44         private enum Execute {
45                 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
46         };
47
48         // ==============================================================================================================================
49         // Action methods
50         // ==============================================================================================================================
51
52         /**
53          * Open a study.
54          * 
55          * @return SUCCESS
56          */
57         public String doInitialize() {
58                 _openStudy = getOpenStudy();
59                 setMenu();
60                 return SUCCESS;
61         }
62
63         public String doSetDocument() {
64
65                 setMenu();
66
67                 try {
68                         _openStudy = getOpenStudy();
69
70                         Execute todo = Execute.valueOf(_action);
71                         Step step = _openStudy.getSelectedStep();
72                         Publication doc = step.getDocument(Integer.valueOf(_index));
73
74                         if (todo == Execute.renameDocument) {
75                                 getPublicationService().rename(doc, _title);
76                                 // Useless to update the document presentation
77                         } else if (todo == Execute.accept) {
78                                 getPublicationService().actualize(doc);
79                                 _openStudy.update(doc);
80                         } else if (todo == Execute.promote) {
81                                 getPublicationService().promote(doc,
82                                                 Calendar.getInstance().getTime());
83                                 _openStudy.update(doc);
84                         } else if (todo == Execute.demote) {
85                                 getPublicationService().demote(doc);
86                                 _openStudy.update(doc);
87                         } else if (todo == Execute.review) {
88                                 getPublicationService().review(doc,
89                                                 Calendar.getInstance().getTime());
90                                 _openStudy.update(doc);
91                         } else if (todo == Execute.invalidate) {
92                                 getPublicationService().invalidate(doc);
93                                 _openStudy.update(doc);
94                         } else if (todo == Execute.approve) {
95                                 getPublicationService().approve(doc,
96                                                 Calendar.getInstance().getTime());
97                                 _openStudy.update(doc);
98                                 _openStudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
99                         }
100                         return SUCCESS;
101                 } catch (RuntimeException saverror) {
102                         LOG.error("Reason:", saverror);
103                         return ERROR;
104                 } catch (InvalidPropertyException error) {
105                         return INPUT;
106                 }
107         }
108
109         public String doAttach() {
110
111                 setMenu();
112
113                 try {
114                         // Getting user inputs
115                         _openStudy = getOpenStudy();
116                         User user = getConnectedUser();
117                         Step step = _openStudy.getSelectedStep();
118                         File updir = getRepositoryService().getDownloadDirectory(user);
119                         File upfile = new File(updir.getPath() + "/" + _filename);
120                         String[] parse = _filename.split("\\x2E");
121
122                         Publication edited = step.getDocument(Integer.valueOf(_index));
123                         ConvertsRelation export = getPublicationService().attach(edited,
124                                         parse[parse.length - 1]);
125
126                         if (LOG.isInfoEnabled()) {
127                                 LOG.info("Moving \"" + upfile.getName() + "\" to \""
128                                                 + updir.getPath() + "\".");
129                         }
130                         upfile.renameTo(export.getTo().asFile());
131
132                         _openStudy.update(edited);
133                         return SUCCESS;
134                 } catch (Exception error) {
135                         LOG.error("Reason:", error);
136                         return ERROR;
137                 }
138         }
139
140         public String doDeleteDocument() {
141
142                 setMenu();
143
144                 try {
145                         _openStudy = getOpenStudy();
146
147                         Step step = _openStudy.getSelectedStep();
148                         Publication doctag = step.getDocument(Integer.valueOf(_index));
149
150                         getStepService().removeDocument(step, doctag); // Updates the data structure
151
152                         _openStudy.remove(doctag); // Updates the presentation
153                         return SUCCESS;
154                 } catch (RuntimeException saverror) {
155                         LOG.error("Reason:", saverror);
156                         return ERROR;
157                 }
158         }
159
160         // ==============================================================================================================================
161         // Getters and setters
162         // ==============================================================================================================================
163
164         public void setDocumentTitle(final String title) {
165                 this._title = title;
166         }
167
168         public void setFileName(final String filename) {
169                 this._filename = filename;
170         }
171
172         @Override
173         public void setIndex(final String index) {
174                 this._index = index;
175         }
176
177         /**
178          * Get the publicationService.
179          * 
180          * @return the publicationService
181          */
182         public PublicationService getPublicationService() {
183                 return _publicationService;
184         }
185
186         /**
187          * Set the publicationService.
188          * 
189          * @param publicationService
190          *            the publicationService to set
191          */
192         public void setPublicationService(
193                         final PublicationService publicationService) {
194                 _publicationService = publicationService;
195         }
196
197         /**
198          * Get the repositoryService.
199          * 
200          * @return the repositoryService
201          */
202         public RepositoryService getRepositoryService() {
203                 return _repositoryService;
204         }
205
206         /**
207          * Set the repositoryService.
208          * 
209          * @param repositoryService
210          *            the repositoryService to set
211          */
212         public void setRepositoryService(final RepositoryService repositoryService) {
213                 _repositoryService = repositoryService;
214         }
215
216         /**
217          * Get the stepService.
218          * 
219          * @return the stepService
220          */
221         public StepService getStepService() {
222                 return _stepService;
223         }
224
225         /**
226          * Set the stepService.
227          * 
228          * @param stepService
229          *            the stepService to set
230          */
231         public void setStepService(final StepService stepService) {
232                 _stepService = stepService;
233         }
234 }