1 package org.splat.simer;
4 import java.util.Calendar;
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;
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 * Operations enumeration.
44 private enum Execute {
45 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
48 // ==============================================================================================================================
50 // ==============================================================================================================================
57 public String doInitialize() {
58 mystudy = getOpenStudy();
62 public String doSetDocument() {
64 mystudy = getOpenStudy();
66 Execute todo = Execute.valueOf(action);
67 Step step = mystudy.getSelectedStep();
68 Publication doc = step.getDocument(Integer.valueOf(index));
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);
76 } else if (todo == Execute.promote) {
77 getPublicationService().promote(doc,
78 Calendar.getInstance().getTime());
80 } else if (todo == Execute.demote) {
81 getPublicationService().demote(doc);
83 } else if (todo == Execute.review) {
84 getPublicationService().review(doc,
85 Calendar.getInstance().getTime());
87 } else if (todo == Execute.invalidate) {
88 getPublicationService().invalidate(doc);
90 } else if (todo == Execute.approve) {
91 getPublicationService().approve(doc,
92 Calendar.getInstance().getTime());
94 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
97 } catch (RuntimeException saverror) {
98 logger.error("Reason:", saverror);
100 } catch (InvalidPropertyException error) {
105 public String doAttach() {
106 // -------------------------
107 // Session connex = Database.getCurSession();
108 // Transaction transax = connex.beginTransaction();
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");
118 Publication edited = step.getDocument(Integer.valueOf(index));
119 ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
121 if (logger.isInfoEnabled())
122 logger.info("Moving \"" + upfile.getName() + "\" to \""
123 + updir.getPath() + "\".");
124 upfile.renameTo(export.getTo().asFile());
126 mystudy.update(edited);
129 } catch (Exception error) {
130 logger.error("Reason:", error);
135 public String doDeleteDocument() {
137 mystudy = getOpenStudy();
139 Step step = mystudy.getSelectedStep();
140 Publication doctag = step.getDocument(Integer.valueOf(index));
142 getStepService().removeDocument(step, doctag); // Updates the data structure
144 mystudy.remove(doctag); // Updates the presentation
146 } catch (RuntimeException saverror) {
147 logger.error("Reason:", saverror);
152 // ==============================================================================================================================
153 // Getters and setters
154 // ==============================================================================================================================
156 public void setDocumentTitle(String title) {
157 // -------------------------------------------
161 public void setFileName(String filename) {
162 // -----------------------------------------
163 this.filename = filename;
166 public void setIndex(String index) {
167 // -----------------------------------
172 * Get the publicationService.
174 * @return the publicationService
176 public PublicationService getPublicationService() {
177 return _publicationService;
181 * Set the publicationService.
183 * @param publicationService
184 * the publicationService to set
186 public void setPublicationService(PublicationService publicationService) {
187 _publicationService = publicationService;
191 * Get the repositoryService.
193 * @return the repositoryService
195 public RepositoryService getRepositoryService() {
196 return _repositoryService;
200 * Set the repositoryService.
202 * @param repositoryService
203 * the repositoryService to set
205 public void setRepositoryService(RepositoryService repositoryService) {
206 _repositoryService = repositoryService;
210 * Get the stepService.
211 * @return the stepService
213 public StepService getStepService() {
218 * Set the stepService.
219 * @param stepService the stepService to set
221 public void setStepService(StepService stepService) {
222 _stepService = stepService;