1 package org.splat.simer;
4 import java.util.Calendar;
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;
16 * Document modification action.
18 public class EditDocumentAction extends DisplayStudyStepAction {
23 private static final long serialVersionUID = 4573036736137033679L;
25 private String index = null;
26 private String title = null;
27 private String filename = null;
29 * Injected publication service.
31 private PublicationService _publicationService;
33 * Injected step service.
35 private StepService _stepService;
37 * Injected repository service.
39 private RepositoryService _repositoryService;
42 * Value of the menu property.
43 * It can be: none, create, open, study, knowledge, sysadmin, help.
45 private String _menuProperty;
48 * Value of the title bar property.
49 * It can be: study, knowledge.
51 private String _titleProperty;
54 * Value of the tool bar property.
55 * It can be: none, standard, study, back.
57 private String _toolProperty;
60 * Value of the left menu property.
61 * It can be: open, study, knowledge, scenario.
63 private String _leftMenuProperty;
66 * Property that indicates whether the current open study is editable or not.
67 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
68 * It is necessary for correct building the title bar.
70 private String _editDisabledProperty = "false";
73 * Operations enumeration.
75 private enum Execute {
76 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
79 // ==============================================================================================================================
81 // ==============================================================================================================================
88 public String doInitialize() {
89 mystudy = getOpenStudy();
91 setMenuProperty("study");
92 setTitleProperty("study");
93 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
94 setToolProperty("study");
96 setToolProperty("standard");
98 setLeftMenuProperty("study");
99 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
104 public String doSetDocument() {
106 setMenuProperty("study");
107 setTitleProperty("study");
108 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
109 setToolProperty("study");
111 setToolProperty("standard");
113 setLeftMenuProperty("study");
114 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
117 mystudy = getOpenStudy();
119 Execute todo = Execute.valueOf(action);
120 Step step = mystudy.getSelectedStep();
121 Publication doc = step.getDocument(Integer.valueOf(index));
123 if (todo == Execute.renameDocument) {
124 getPublicationService().rename(doc, title);
125 // Useless to update the document presentation
126 } else if (todo == Execute.accept) {
127 getPublicationService().actualize(doc);
129 } else if (todo == Execute.promote) {
130 getPublicationService().promote(doc,
131 Calendar.getInstance().getTime());
133 } else if (todo == Execute.demote) {
134 getPublicationService().demote(doc);
136 } else if (todo == Execute.review) {
137 getPublicationService().review(doc,
138 Calendar.getInstance().getTime());
140 } else if (todo == Execute.invalidate) {
141 getPublicationService().invalidate(doc);
143 } else if (todo == Execute.approve) {
144 getPublicationService().approve(doc,
145 Calendar.getInstance().getTime());
147 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
150 } catch (RuntimeException saverror) {
151 LOG.error("Reason:", saverror);
153 } catch (InvalidPropertyException error) {
158 public String doAttach() {
160 setMenuProperty("study");
161 setTitleProperty("study");
162 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
163 setToolProperty("study");
165 setToolProperty("standard");
167 setLeftMenuProperty("study");
168 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
171 // Getting user inputs
172 mystudy = getOpenStudy();
173 User user = getConnectedUser();
174 Step step = mystudy.getSelectedStep();
175 File updir = getRepositoryService().getDownloadDirectory(user);
176 File upfile = new File(updir.getPath() + "/" + filename);
177 String[] parse = filename.split("\\x2E");
179 Publication edited = step.getDocument(Integer.valueOf(index));
180 ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
182 if (LOG.isInfoEnabled())
183 LOG.info("Moving \"" + upfile.getName() + "\" to \""
184 + updir.getPath() + "\".");
185 upfile.renameTo(export.getTo().asFile());
187 mystudy.update(edited);
189 } catch (Exception error) {
190 LOG.error("Reason:", error);
195 public String doDeleteDocument() {
197 setMenuProperty("study");
198 setTitleProperty("study");
199 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
200 setToolProperty("study");
202 setToolProperty("standard");
204 setLeftMenuProperty("study");
205 initializationFullScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty, _leftMenuProperty);
208 mystudy = getOpenStudy();
210 Step step = mystudy.getSelectedStep();
211 Publication doctag = step.getDocument(Integer.valueOf(index));
213 getStepService().removeDocument(step, doctag); // Updates the data structure
215 mystudy.remove(doctag); // Updates the presentation
217 } catch (RuntimeException saverror) {
218 LOG.error("Reason:", saverror);
223 // ==============================================================================================================================
224 // Getters and setters
225 // ==============================================================================================================================
227 public void setDocumentTitle(String title) {
228 // -------------------------------------------
232 public void setFileName(String filename) {
233 // -----------------------------------------
234 this.filename = filename;
237 public void setIndex(String index) {
238 // -----------------------------------
243 * Get the publicationService.
245 * @return the publicationService
247 public PublicationService getPublicationService() {
248 return _publicationService;
252 * Set the publicationService.
254 * @param publicationService
255 * the publicationService to set
257 public void setPublicationService(PublicationService publicationService) {
258 _publicationService = publicationService;
262 * Get the repositoryService.
264 * @return the repositoryService
266 public RepositoryService getRepositoryService() {
267 return _repositoryService;
271 * Set the repositoryService.
273 * @param repositoryService
274 * the repositoryService to set
276 public void setRepositoryService(RepositoryService repositoryService) {
277 _repositoryService = repositoryService;
281 * Get the stepService.
282 * @return the stepService
284 public StepService getStepService() {
289 * Set the stepService.
290 * @param stepService the stepService to set
292 public void setStepService(StepService stepService) {
293 _stepService = stepService;
297 * Get the menuProperty.
298 * @return the menuProperty
300 public String getMenuProperty() {
301 return _menuProperty;
305 * Set the menuProperty.
306 * @param menuProperty the menuProperty to set
308 public void setMenuProperty(String menuProperty) {
309 this._menuProperty = menuProperty;
313 * Get the _titleProperty.
314 * @return the _titleProperty
316 public String getTitleProperty() {
317 return _titleProperty;
321 * Set the _titleProperty.
322 * @param _titleProperty the titleProperty to set
324 public void setTitleProperty(String titleProperty) {
325 _titleProperty = titleProperty;
329 * Get the editDisabledProperty.
330 * @return the editDisabledProperty
332 public String getEditDisabledProperty() {
333 return _editDisabledProperty;
337 * Set the editDisabledProperty.
338 * @param editDisabledProperty the editDisabledProperty to set
340 public void setEditDisabledProperty(String editDisabledProperty) {
341 _editDisabledProperty = editDisabledProperty;
346 * Get the toolProperty.
347 * @return the toolProperty
349 public String getToolProperty() {
350 return _toolProperty;
354 * Set the toolProperty.
355 * @param toolProperty the toolProperty to set
357 public void setToolProperty(final String toolProperty) {
358 _toolProperty = toolProperty;
362 * Get the leftMenuProperty.
363 * @return the leftMenuProperty
365 public String getLeftMenuProperty() {
366 return _leftMenuProperty;
370 * Set the leftMenuProperty.
371 * @param leftMenuProperty the leftMenuProperty to set
373 public void setLeftMenuProperty(final String leftMenuProperty) {
374 _leftMenuProperty = leftMenuProperty;