]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Salome HOME
Menus are 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.kernel.InvalidPropertyException;
7 import org.splat.dal.bo.kernel.User;
8 import org.splat.dal.bo.som.Publication;
9 import org.splat.dal.bo.som.ConvertsRelation;
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          * Operations enumeration.
49          */
50         private enum Execute {
51                 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
52         };
53
54         // ==============================================================================================================================
55         // Action methods
56         // ==============================================================================================================================
57
58         /**
59          * Open a study.
60          * 
61          * @return SUCCESS
62          */
63         public String doInitialize() {
64                 mystudy = getOpenStudy();
65                 
66                 setMenuProperty("study");
67                 initializationScreenContext(_menuProperty);
68                 
69                 return SUCCESS;
70         }
71
72         public String doSetDocument() {
73                 
74                 setMenuProperty("study");
75                 initializationScreenContext(_menuProperty);
76                 
77                 try {
78                         mystudy = getOpenStudy();
79
80                         Execute todo = Execute.valueOf(action);
81                         Step step = mystudy.getSelectedStep();
82                         Publication doc = step.getDocument(Integer.valueOf(index));
83
84                         if (todo == Execute.renameDocument) {
85                                 getPublicationService().rename(doc, title);
86                                 // Useless to update the document presentation
87                         } else if (todo == Execute.accept) {
88                                 getPublicationService().actualize(doc);
89                                 mystudy.update(doc);
90                         } else if (todo == Execute.promote) {
91                                 getPublicationService().promote(doc,
92                                                 Calendar.getInstance().getTime());
93                                 mystudy.update(doc);
94                         } else if (todo == Execute.demote) {
95                                 getPublicationService().demote(doc);
96                                 mystudy.update(doc);
97                         } else if (todo == Execute.review) {
98                                 getPublicationService().review(doc,
99                                                 Calendar.getInstance().getTime());
100                                 mystudy.update(doc);
101                         } else if (todo == Execute.invalidate) {
102                                 getPublicationService().invalidate(doc);
103                                 mystudy.update(doc);
104                         } else if (todo == Execute.approve) {
105                                 getPublicationService().approve(doc,
106                                                 Calendar.getInstance().getTime());
107                                 mystudy.update(doc);
108                                 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
109                         }
110                         return SUCCESS;
111                 } catch (RuntimeException saverror) {
112                         logger.error("Reason:", saverror);
113                         return ERROR;
114                 } catch (InvalidPropertyException error) {
115                         return INPUT;
116                 }
117         }
118
119         public String doAttach() {
120                 // -------------------------
121 //              Session connex = Database.getCurSession();
122 //              Transaction transax = connex.beginTransaction();
123                 
124                 setMenuProperty("study");
125                 initializationScreenContext(_menuProperty);
126                 
127                 try {
128                         // Getting user inputs
129                         mystudy = getOpenStudy();
130                         User user = getConnectedUser();
131                         Step step = mystudy.getSelectedStep();
132                         File updir = getRepositoryService().getDownloadDirectory(user);
133                         File upfile = new File(updir.getPath() + "/" + filename);
134                         String[] parse = filename.split("\\x2E");
135
136                         Publication edited = step.getDocument(Integer.valueOf(index));
137                         ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
138
139                         if (logger.isInfoEnabled())
140                                 logger.info("Moving \"" + upfile.getName() + "\" to \""
141                                                 + updir.getPath() + "\".");
142                         upfile.renameTo(export.getTo().asFile());
143
144                         mystudy.update(edited);
145 //                      transax.commit();
146                         return SUCCESS;
147                 } catch (Exception error) {
148                         logger.error("Reason:", error);
149                         return ERROR;
150                 }
151         }
152
153         public String doDeleteDocument() {
154                 
155                 setMenuProperty("study");
156                 initializationScreenContext(_menuProperty);
157                 
158                 try {
159                         mystudy = getOpenStudy();
160
161                         Step step = mystudy.getSelectedStep();
162                         Publication doctag = step.getDocument(Integer.valueOf(index));
163
164                         getStepService().removeDocument(step, doctag); // Updates the data structure
165
166                         mystudy.remove(doctag); // Updates the presentation
167                         return SUCCESS;
168                 } catch (RuntimeException saverror) {
169                         logger.error("Reason:", saverror);
170                         return ERROR;
171                 }
172         }
173
174         // ==============================================================================================================================
175         // Getters and setters
176         // ==============================================================================================================================
177
178         public void setDocumentTitle(String title) {
179                 // -------------------------------------------
180                 this.title = title;
181         }
182
183         public void setFileName(String filename) {
184                 // -----------------------------------------
185                 this.filename = filename;
186         }
187
188         public void setIndex(String index) {
189                 // -----------------------------------
190                 this.index = index;
191         }
192
193         /**
194          * Get the publicationService.
195          * 
196          * @return the publicationService
197          */
198         public PublicationService getPublicationService() {
199                 return _publicationService;
200         }
201
202         /**
203          * Set the publicationService.
204          * 
205          * @param publicationService
206          *            the publicationService to set
207          */
208         public void setPublicationService(PublicationService publicationService) {
209                 _publicationService = publicationService;
210         }
211
212         /**
213          * Get the repositoryService.
214          * 
215          * @return the repositoryService
216          */
217         public RepositoryService getRepositoryService() {
218                 return _repositoryService;
219         }
220
221         /**
222          * Set the repositoryService.
223          * 
224          * @param repositoryService
225          *            the repositoryService to set
226          */
227         public void setRepositoryService(RepositoryService repositoryService) {
228                 _repositoryService = repositoryService;
229         }
230
231         /**
232          * Get the stepService.
233          * @return the stepService
234          */
235         public StepService getStepService() {
236                 return _stepService;
237         }
238
239         /**
240          * Set the stepService.
241          * @param stepService the stepService to set
242          */
243         public void setStepService(StepService stepService) {
244                 _stepService = stepService;
245         }
246         
247         /**
248          * Get the menuProperty.
249          * @return the menuProperty
250          */
251         public String getMenuProperty() {
252                 return _menuProperty;
253         }
254
255         /**
256          * Set the menuProperty.
257          * @param menuProperty the menuProperty to set
258          */
259         public void setMenuProperty(String menuProperty) {
260                 this._menuProperty = menuProperty;
261         }
262 }