]> SALOME platform Git repositories - tools/siman.git/blob - Workspace/Siman/src/org/splat/simer/EditDocumentAction.java
Salome HOME
c4260d8d71ebb82ad5b2acb5deb96d2208b8760d
[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                 _openStudy = getOpenStudy();
144                 Step step = _openStudy.getSelectedStep();
145                 Publication doctag = step.getDocument(Integer.valueOf(_index));
146
147                 if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
148                         _openStudy.remove(doctag); // Updates the presentation
149                 }
150                 return SUCCESS;
151         }
152
153         // ==============================================================================================================================
154         // Getters and setters
155         // ==============================================================================================================================
156
157         public void setDocumentTitle(final String title) {
158                 this._title = title;
159         }
160
161         public void setFileName(final String filename) {
162                 this._filename = filename;
163         }
164
165         @Override
166         public void setIndex(final String index) {
167                 this._index = index;
168         }
169
170         /**
171          * Get the publicationService.
172          * 
173          * @return the publicationService
174          */
175         public PublicationService getPublicationService() {
176                 return _publicationService;
177         }
178
179         /**
180          * Set the publicationService.
181          * 
182          * @param publicationService
183          *            the publicationService to set
184          */
185         public void setPublicationService(
186                         final 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(final RepositoryService repositoryService) {
206                 _repositoryService = repositoryService;
207         }
208
209         /**
210          * Get the stepService.
211          * 
212          * @return the stepService
213          */
214         public StepService getStepService() {
215                 return _stepService;
216         }
217
218         /**
219          * Set the stepService.
220          * 
221          * @param stepService
222          *            the stepService to set
223          */
224         public void setStepService(final StepService stepService) {
225                 _stepService = stepService;
226         }
227 }