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 * Value of the menu property.
43 * It can be: none, create, open, study, knowledge, sysadmin, help.
45 private String _menuProperty;
48 * Operations enumeration.
50 private enum Execute {
51 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
54 // ==============================================================================================================================
56 // ==============================================================================================================================
63 public String doInitialize() {
64 mystudy = getOpenStudy();
66 setMenuProperty("study");
67 initializationScreenContext(_menuProperty);
72 public String doSetDocument() {
74 setMenuProperty("study");
75 initializationScreenContext(_menuProperty);
78 mystudy = getOpenStudy();
80 Execute todo = Execute.valueOf(action);
81 Step step = mystudy.getSelectedStep();
82 Publication doc = step.getDocument(Integer.valueOf(index));
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);
90 } else if (todo == Execute.promote) {
91 getPublicationService().promote(doc,
92 Calendar.getInstance().getTime());
94 } else if (todo == Execute.demote) {
95 getPublicationService().demote(doc);
97 } else if (todo == Execute.review) {
98 getPublicationService().review(doc,
99 Calendar.getInstance().getTime());
101 } else if (todo == Execute.invalidate) {
102 getPublicationService().invalidate(doc);
104 } else if (todo == Execute.approve) {
105 getPublicationService().approve(doc,
106 Calendar.getInstance().getTime());
108 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
111 } catch (RuntimeException saverror) {
112 logger.error("Reason:", saverror);
114 } catch (InvalidPropertyException error) {
119 public String doAttach() {
120 // -------------------------
121 // Session connex = Database.getCurSession();
122 // Transaction transax = connex.beginTransaction();
124 setMenuProperty("study");
125 initializationScreenContext(_menuProperty);
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");
136 Publication edited = step.getDocument(Integer.valueOf(index));
137 ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
139 if (logger.isInfoEnabled())
140 logger.info("Moving \"" + upfile.getName() + "\" to \""
141 + updir.getPath() + "\".");
142 upfile.renameTo(export.getTo().asFile());
144 mystudy.update(edited);
147 } catch (Exception error) {
148 logger.error("Reason:", error);
153 public String doDeleteDocument() {
155 setMenuProperty("study");
156 initializationScreenContext(_menuProperty);
159 mystudy = getOpenStudy();
161 Step step = mystudy.getSelectedStep();
162 Publication doctag = step.getDocument(Integer.valueOf(index));
164 getStepService().removeDocument(step, doctag); // Updates the data structure
166 mystudy.remove(doctag); // Updates the presentation
168 } catch (RuntimeException saverror) {
169 logger.error("Reason:", saverror);
174 // ==============================================================================================================================
175 // Getters and setters
176 // ==============================================================================================================================
178 public void setDocumentTitle(String title) {
179 // -------------------------------------------
183 public void setFileName(String filename) {
184 // -----------------------------------------
185 this.filename = filename;
188 public void setIndex(String index) {
189 // -----------------------------------
194 * Get the publicationService.
196 * @return the publicationService
198 public PublicationService getPublicationService() {
199 return _publicationService;
203 * Set the publicationService.
205 * @param publicationService
206 * the publicationService to set
208 public void setPublicationService(PublicationService publicationService) {
209 _publicationService = publicationService;
213 * Get the repositoryService.
215 * @return the repositoryService
217 public RepositoryService getRepositoryService() {
218 return _repositoryService;
222 * Set the repositoryService.
224 * @param repositoryService
225 * the repositoryService to set
227 public void setRepositoryService(RepositoryService repositoryService) {
228 _repositoryService = repositoryService;
232 * Get the stepService.
233 * @return the stepService
235 public StepService getStepService() {
240 * Set the stepService.
241 * @param stepService the stepService to set
243 public void setStepService(StepService stepService) {
244 _stepService = stepService;
248 * Get the menuProperty.
249 * @return the menuProperty
251 public String getMenuProperty() {
252 return _menuProperty;
256 * Set the menuProperty.
257 * @param menuProperty the menuProperty to set
259 public void setMenuProperty(String menuProperty) {
260 this._menuProperty = menuProperty;