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