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
79 } else if (todo == Execute.accept) {
80 getPublicationService().actualize(doc);
81 _openStudy.update(doc);
82 } else if (todo == Execute.promote) {
83 getPublicationService().promote(doc,
84 Calendar.getInstance().getTime());
85 _openStudy.update(doc);
86 } else if (todo == Execute.demote) {
87 getPublicationService().demote(doc);
88 _openStudy.update(doc);
89 } else if (todo == Execute.review) {
90 getPublicationService().review(doc,
91 Calendar.getInstance().getTime());
92 _openStudy.update(doc);
93 } else if (todo == Execute.invalidate) {
94 getPublicationService().invalidate(doc);
95 _openStudy.update(doc);
96 } else if (todo == Execute.approve) {
97 getPublicationService().approve(doc,
98 Calendar.getInstance().getTime());
99 _openStudy.update(doc);
100 _openStudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
103 } catch (RuntimeException saverror) {
104 LOG.error("Reason:", saverror);
106 } catch (InvalidPropertyException error) {
111 public String doAttach() {
116 // Getting user inputs
117 _openStudy = getOpenStudy();
118 User user = getConnectedUser();
119 Step step = _openStudy.getSelectedStep();
120 File updir = getRepositoryService().getDownloadDirectory(user);
121 File upfile = new File(updir.getPath() + "/" + _filename);
122 String[] parse = _filename.split("\\x2E");
124 Publication edited = step.getDocument(Integer.valueOf(_index));
125 ConvertsRelation export = getPublicationService().attach(edited,
126 parse[parse.length - 1]);
128 if (LOG.isInfoEnabled()) {
129 LOG.info("Moving \"" + upfile.getName() + "\" to \""
130 + updir.getPath() + "\".");
132 upfile.renameTo(export.getTo().asFile());
134 _openStudy.update(edited);
136 } catch (Exception error) {
137 LOG.error("Reason:", error);
143 * Remove the selected document from the current activity.
146 * @throws DocumentIsUsedException
147 * if the document is used by other document(s)
148 * @throws NumberFormatException
149 * if the document id can not be transformed to number
151 public String doDeleteDocument() throws DocumentIsUsedException,
152 NumberFormatException {
155 _openStudy = getOpenStudy();
156 Step step = _openStudy.getSelectedStep();
157 Publication doctag = step.getDocument(Integer.valueOf(_index));
159 if (getStepService().removeDocument(step, Long.valueOf(_index))) { // Updates the data structure
160 _openStudy.remove(doctag); // Updates the presentation
165 // ==============================================================================================================================
166 // Getters and setters
167 // ==============================================================================================================================
169 public void setDocumentTitle(final String title) {
173 public void setFileName(final String filename) {
174 this._filename = filename;
178 public void setIndex(final String index) {
187 public String getIndex() {
192 * Get the publicationService.
194 * @return the publicationService
196 public PublicationService getPublicationService() {
197 return _publicationService;
201 * Set the publicationService.
203 * @param publicationService
204 * the publicationService to set
206 public void setPublicationService(
207 final PublicationService publicationService) {
208 _publicationService = publicationService;
212 * Get the repositoryService.
214 * @return the repositoryService
216 public RepositoryService getRepositoryService() {
217 return _repositoryService;
221 * Set the repositoryService.
223 * @param repositoryService
224 * the repositoryService to set
226 public void setRepositoryService(final RepositoryService repositoryService) {
227 _repositoryService = repositoryService;
231 * Get the stepService.
233 * @return the stepService
235 public StepService getStepService() {
240 * Set the stepService.
243 * the stepService to set
245 public void setStepService(final StepService stepService) {
246 _stepService = stepService;