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.exception.DocumentIsUsedException;
10 import org.splat.kernel.InvalidPropertyException;
11 import org.splat.service.PublicationService;
12 import org.splat.service.StepService;
13 import org.splat.service.technical.RepositoryService;
14 import org.splat.som.Step;
17 * Document modification action.
19 public class EditDocumentAction extends DisplayStudyStepAction {
24 private static final long serialVersionUID = 4573036736137033679L;
26 private transient String _index = null;
27 private transient String _title = null;
28 private transient String _filename = null;
30 * Injected publication service.
32 private PublicationService _publicationService;
34 * Injected step service.
36 private StepService _stepService;
38 * Injected repository service.
40 private RepositoryService _repositoryService;
43 * Operations enumeration.
45 private enum Execute {
46 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
49 // ==============================================================================================================================
51 // ==============================================================================================================================
58 public String doInitialize() {
59 _openStudy = getOpenStudy();
64 public String doSetDocument() {
69 _openStudy = getOpenStudy();
71 Execute todo = Execute.valueOf(_action);
72 Step step = _openStudy.getSelectedStep();
73 Publication doc = step.getDocument(Integer.valueOf(_index));
75 if (todo == Execute.renameDocument) {
76 getPublicationService().rename(doc, _title);
77 // Useless to update the document presentation
78 } else if (todo == Execute.accept) {
79 getPublicationService().actualize(doc);
80 _openStudy.update(doc);
81 } else if (todo == Execute.promote) {
82 getPublicationService().promote(doc,
83 Calendar.getInstance().getTime());
84 _openStudy.update(doc);
85 } else if (todo == Execute.demote) {
86 getPublicationService().demote(doc);
87 _openStudy.update(doc);
88 } else if (todo == Execute.review) {
89 getPublicationService().review(doc,
90 Calendar.getInstance().getTime());
91 _openStudy.update(doc);
92 } else if (todo == Execute.invalidate) {
93 getPublicationService().invalidate(doc);
94 _openStudy.update(doc);
95 } else if (todo == Execute.approve) {
96 getPublicationService().approve(doc,
97 Calendar.getInstance().getTime());
98 _openStudy.update(doc);
99 _openStudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
102 } catch (RuntimeException saverror) {
103 LOG.error("Reason:", saverror);
105 } catch (InvalidPropertyException error) {
110 public String doAttach() {
115 // Getting user inputs
116 _openStudy = getOpenStudy();
117 User user = getConnectedUser();
118 Step step = _openStudy.getSelectedStep();
119 File updir = getRepositoryService().getDownloadDirectory(user);
120 File upfile = new File(updir.getPath() + "/" + _filename);
121 String[] parse = _filename.split("\\x2E");
123 Publication edited = step.getDocument(Integer.valueOf(_index));
124 ConvertsRelation export = getPublicationService().attach(edited,
125 parse[parse.length - 1]);
127 if (LOG.isInfoEnabled()) {
128 LOG.info("Moving \"" + upfile.getName() + "\" to \""
129 + updir.getPath() + "\".");
131 upfile.renameTo(export.getTo().asFile());
133 _openStudy.update(edited);
135 } catch (Exception error) {
136 LOG.error("Reason:", error);
142 * Remove the selected document from the current activity.
145 * @throws DocumentIsUsedException
146 * if the document is used by other document(s)
147 * @throws NumberFormatException
148 * if the document id can not be transformed to number
150 public String doDeleteDocument() throws DocumentIsUsedException,
151 NumberFormatException {
154 _openStudy = getOpenStudy();
155 Step step = _openStudy.getSelectedStep();
156 Publication doctag = step.getDocument(Integer.valueOf(_index));
158 if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
159 _openStudy.remove(doctag); // Updates the presentation
164 // ==============================================================================================================================
165 // Getters and setters
166 // ==============================================================================================================================
168 public void setDocumentTitle(final String title) {
172 public void setFileName(final String filename) {
173 this._filename = filename;
177 public void setIndex(final String index) {
182 * Get the publicationService.
184 * @return the publicationService
186 public PublicationService getPublicationService() {
187 return _publicationService;
191 * Set the publicationService.
193 * @param publicationService
194 * the publicationService to set
196 public void setPublicationService(
197 final PublicationService publicationService) {
198 _publicationService = publicationService;
202 * Get the repositoryService.
204 * @return the repositoryService
206 public RepositoryService getRepositoryService() {
207 return _repositoryService;
211 * Set the repositoryService.
213 * @param repositoryService
214 * the repositoryService to set
216 public void setRepositoryService(final RepositoryService repositoryService) {
217 _repositoryService = repositoryService;
221 * Get the stepService.
223 * @return the stepService
225 public StepService getStepService() {
230 * Set the stepService.
233 * the stepService to set
235 public void setStepService(final StepService stepService) {
236 _stepService = stepService;