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 transient String _index = null;
26 private transient String _title = null;
27 private transient 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 _openStudy = getOpenStudy();
63 public String doSetDocument() {
68 _openStudy = getOpenStudy();
70 Execute todo = Execute.valueOf(_action);
71 Step step = _openStudy.getSelectedStep();
72 Publication doc = step.getDocument(Integer.valueOf(_index));
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
101 } catch (RuntimeException saverror) {
102 LOG.error("Reason:", saverror);
104 } catch (InvalidPropertyException error) {
109 public String doAttach() {
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");
122 Publication edited = step.getDocument(Integer.valueOf(_index));
123 ConvertsRelation export = getPublicationService().attach(edited,
124 parse[parse.length - 1]);
126 if (LOG.isInfoEnabled()) {
127 LOG.info("Moving \"" + upfile.getName() + "\" to \""
128 + updir.getPath() + "\".");
130 upfile.renameTo(export.getTo().asFile());
132 _openStudy.update(edited);
134 } catch (Exception error) {
135 LOG.error("Reason:", error);
140 public String doDeleteDocument() {
143 _openStudy = getOpenStudy();
144 Step step = _openStudy.getSelectedStep();
145 Publication doctag = step.getDocument(Integer.valueOf(_index));
147 if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
148 _openStudy.remove(doctag); // Updates the presentation
153 // ==============================================================================================================================
154 // Getters and setters
155 // ==============================================================================================================================
157 public void setDocumentTitle(final String title) {
161 public void setFileName(final String filename) {
162 this._filename = filename;
166 public void setIndex(final String index) {
171 * Get the publicationService.
173 * @return the publicationService
175 public PublicationService getPublicationService() {
176 return _publicationService;
180 * Set the publicationService.
182 * @param publicationService
183 * the publicationService to set
185 public void setPublicationService(
186 final 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(final RepositoryService repositoryService) {
206 _repositoryService = repositoryService;
210 * Get the stepService.
212 * @return the stepService
214 public StepService getStepService() {
219 * Set the stepService.
222 * the stepService to set
224 public void setStepService(final StepService stepService) {
225 _stepService = stepService;