]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Salome HOME
Tool bar is improved.
[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 String index = null;
26         private String title = null;
27         private 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          * Value of the menu property. 
43          * It can be: none, create, open, study, knowledge, sysadmin, help.
44          */
45         private String _menuProperty;
46         
47         /**
48          * Value of the title bar property. 
49          * It can be: study, knowledge.
50          */
51         private String _titleProperty;
52         
53         /**
54          * Value of the tool bar property. 
55          * It can be: none, standard, study, back.
56          */
57         private String _toolProperty;
58         
59         /**
60          * Property that indicates whether the current open study is editable or not.
61          * On the screen it looks like pen on the status icon, pop-up menu also can be called.
62          * It is necessary for correct building the title bar.
63          */
64         private String _editDisabledProperty = "false";
65
66         /**
67          * Operations enumeration.
68          */
69         private enum Execute {
70                 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
71         };
72
73         // ==============================================================================================================================
74         // Action methods
75         // ==============================================================================================================================
76
77         /**
78          * Open a study.
79          * 
80          * @return SUCCESS
81          */
82         public String doInitialize() {
83                 mystudy = getOpenStudy();
84                 
85                 setMenuProperty("study");
86                 setTitleProperty("study");
87                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
88                         setToolProperty("study");
89                 } else {
90                         setToolProperty("standard");
91                 }
92                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
93                 
94                 return SUCCESS;
95         }
96
97         public String doSetDocument() {
98                 
99                 setMenuProperty("study");
100                 setTitleProperty("study");
101                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
102                         setToolProperty("study");
103                 } else {
104                         setToolProperty("standard");
105                 }
106                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
107                 
108                 try {
109                         mystudy = getOpenStudy();
110
111                         Execute todo = Execute.valueOf(action);
112                         Step step = mystudy.getSelectedStep();
113                         Publication doc = step.getDocument(Integer.valueOf(index));
114
115                         if (todo == Execute.renameDocument) {
116                                 getPublicationService().rename(doc, title);
117                                 // Useless to update the document presentation
118                         } else if (todo == Execute.accept) {
119                                 getPublicationService().actualize(doc);
120                                 mystudy.update(doc);
121                         } else if (todo == Execute.promote) {
122                                 getPublicationService().promote(doc,
123                                                 Calendar.getInstance().getTime());
124                                 mystudy.update(doc);
125                         } else if (todo == Execute.demote) {
126                                 getPublicationService().demote(doc);
127                                 mystudy.update(doc);
128                         } else if (todo == Execute.review) {
129                                 getPublicationService().review(doc,
130                                                 Calendar.getInstance().getTime());
131                                 mystudy.update(doc);
132                         } else if (todo == Execute.invalidate) {
133                                 getPublicationService().invalidate(doc);
134                                 mystudy.update(doc);
135                         } else if (todo == Execute.approve) {
136                                 getPublicationService().approve(doc,
137                                                 Calendar.getInstance().getTime());
138                                 mystudy.update(doc);
139                                 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
140                         }
141                         return SUCCESS;
142                 } catch (RuntimeException saverror) {
143                         logger.error("Reason:", saverror);
144                         return ERROR;
145                 } catch (InvalidPropertyException error) {
146                         return INPUT;
147                 }
148         }
149
150         public String doAttach() {
151                 // -------------------------
152 //              Session connex = Database.getCurSession();
153 //              Transaction transax = connex.beginTransaction();
154                 
155                 setMenuProperty("study");
156                 setTitleProperty("study");
157                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
158                         setToolProperty("study");
159                 } else {
160                         setToolProperty("standard");
161                 }
162                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
163                 
164                 try {
165                         // Getting user inputs
166                         mystudy = getOpenStudy();
167                         User user = getConnectedUser();
168                         Step step = mystudy.getSelectedStep();
169                         File updir = getRepositoryService().getDownloadDirectory(user);
170                         File upfile = new File(updir.getPath() + "/" + filename);
171                         String[] parse = filename.split("\\x2E");
172
173                         Publication edited = step.getDocument(Integer.valueOf(index));
174                         ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
175
176                         if (logger.isInfoEnabled())
177                                 logger.info("Moving \"" + upfile.getName() + "\" to \""
178                                                 + updir.getPath() + "\".");
179                         upfile.renameTo(export.getTo().asFile());
180
181                         mystudy.update(edited);
182 //                      transax.commit();
183                         return SUCCESS;
184                 } catch (Exception error) {
185                         logger.error("Reason:", error);
186                         return ERROR;
187                 }
188         }
189
190         public String doDeleteDocument() {
191                 
192                 setMenuProperty("study");
193                 setTitleProperty("study");
194                 if ("true".equals(getWriteAccess()) &&  getUserRights().canCreateDocument()) {
195                         setToolProperty("study");
196                 } else {
197                         setToolProperty("standard");
198                 }
199                 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
200                 
201                 try {
202                         mystudy = getOpenStudy();
203
204                         Step step = mystudy.getSelectedStep();
205                         Publication doctag = step.getDocument(Integer.valueOf(index));
206
207                         getStepService().removeDocument(step, doctag); // Updates the data structure
208
209                         mystudy.remove(doctag); // Updates the presentation
210                         return SUCCESS;
211                 } catch (RuntimeException saverror) {
212                         logger.error("Reason:", saverror);
213                         return ERROR;
214                 }
215         }
216
217         // ==============================================================================================================================
218         // Getters and setters
219         // ==============================================================================================================================
220
221         public void setDocumentTitle(String title) {
222                 // -------------------------------------------
223                 this.title = title;
224         }
225
226         public void setFileName(String filename) {
227                 // -----------------------------------------
228                 this.filename = filename;
229         }
230
231         public void setIndex(String index) {
232                 // -----------------------------------
233                 this.index = index;
234         }
235
236         /**
237          * Get the publicationService.
238          * 
239          * @return the publicationService
240          */
241         public PublicationService getPublicationService() {
242                 return _publicationService;
243         }
244
245         /**
246          * Set the publicationService.
247          * 
248          * @param publicationService
249          *            the publicationService to set
250          */
251         public void setPublicationService(PublicationService publicationService) {
252                 _publicationService = publicationService;
253         }
254
255         /**
256          * Get the repositoryService.
257          * 
258          * @return the repositoryService
259          */
260         public RepositoryService getRepositoryService() {
261                 return _repositoryService;
262         }
263
264         /**
265          * Set the repositoryService.
266          * 
267          * @param repositoryService
268          *            the repositoryService to set
269          */
270         public void setRepositoryService(RepositoryService repositoryService) {
271                 _repositoryService = repositoryService;
272         }
273
274         /**
275          * Get the stepService.
276          * @return the stepService
277          */
278         public StepService getStepService() {
279                 return _stepService;
280         }
281
282         /**
283          * Set the stepService.
284          * @param stepService the stepService to set
285          */
286         public void setStepService(StepService stepService) {
287                 _stepService = stepService;
288         }
289         
290         /**
291          * Get the menuProperty.
292          * @return the menuProperty
293          */
294         public String getMenuProperty() {
295                 return _menuProperty;
296         }
297
298         /**
299          * Set the menuProperty.
300          * @param menuProperty the menuProperty to set
301          */
302         public void setMenuProperty(String menuProperty) {
303                 this._menuProperty = menuProperty;
304         }
305         
306         /**
307          * Get the _titleProperty.
308          * @return the _titleProperty
309          */
310         public String getTitleProperty() {
311                 return _titleProperty;
312         }
313
314         /**
315          * Set the _titleProperty.
316          * @param _titleProperty the titleProperty to set
317          */
318         public void setTitleProperty(String titleProperty) {
319                 _titleProperty = titleProperty;
320         }
321
322         /**
323          * Get the editDisabledProperty.
324          * @return the editDisabledProperty
325          */
326         public String getEditDisabledProperty() {
327                 return _editDisabledProperty;
328         }
329
330         /**
331          * Set the editDisabledProperty.
332          * @param editDisabledProperty the editDisabledProperty to set
333          */
334         public void setEditDisabledProperty(String editDisabledProperty) {
335                 _editDisabledProperty = editDisabledProperty;
336         }
337
338
339         /**
340          * Get the toolProperty.
341          * @return the toolProperty
342          */
343         public String getToolProperty() {
344                 return _toolProperty;
345         }
346
347         /**
348          * Set the toolProperty.
349          * @param toolProperty the toolProperty to set
350          */
351         public void setToolProperty(final String toolProperty) {
352                 _toolProperty = toolProperty;
353         }
354
355         
356 }