1 package org.splat.simer;
4 import java.util.Calendar;
6 import org.hibernate.HibernateException;
7 import org.hibernate.Session;
8 import org.hibernate.Transaction;
9 import org.splat.kernel.InvalidPropertyException;
10 import org.splat.dal.bo.kernel.User;
11 import org.splat.dal.dao.som.Database;
12 import org.splat.dal.bo.som.Publication;
13 import org.splat.dal.bo.som.ConvertsRelation;
14 import org.splat.service.PublicationService;
15 import org.splat.service.StepService;
16 import org.splat.service.technical.RepositoryService;
17 import org.splat.som.Step;
20 * Document modification action.
22 public class EditDocumentAction extends DisplayStudyStepAction {
27 private static final long serialVersionUID = 4573036736137033679L;
29 private String index = null;
30 private String title = null;
31 private String filename = null;
33 * Injected publication service.
35 private PublicationService _publicationService;
37 * Injected step service.
39 private StepService _stepService;
41 * Injected repository service.
43 private RepositoryService _repositoryService;
46 * Operations enumeration.
48 private enum Execute {
49 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
52 // ==============================================================================================================================
54 // ==============================================================================================================================
61 public String doInitialize() {
62 mystudy = getOpenStudy();
66 public String doSetDocument() {
67 // ------------------------------
68 Session connex = Database.getSession();
69 Transaction transax = connex.beginTransaction();
71 mystudy = getOpenStudy();
73 Execute todo = Execute.valueOf(action);
74 Step step = mystudy.getSelectedStep();
75 Publication doc = step.getDocument(Integer.valueOf(index));
77 if (todo == Execute.renameDocument) {
78 getPublicationService().rename(doc, title);
79 // Useless to update the document presentation
80 } else if (todo == Execute.accept) {
83 } else if (todo == Execute.promote) {
84 getPublicationService().promote(doc,
85 Calendar.getInstance().getTime());
87 } else if (todo == Execute.demote) {
88 getPublicationService().demote(doc);
90 } else if (todo == Execute.review) {
91 getPublicationService().review(doc,
92 Calendar.getInstance().getTime());
94 } else if (todo == Execute.invalidate) {
95 getPublicationService().invalidate(doc);
97 } else if (todo == Execute.approve) {
98 getPublicationService().approve(doc,
99 Calendar.getInstance().getTime());
101 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
105 } catch (RuntimeException saverror) {
106 logger.error("Reason:", saverror);
107 if (transax != null && transax.isActive()) {
108 // Second try-catch as the rollback could fail as well
111 } catch (HibernateException backerror) {
112 logger.debug("Error rolling back transaction", backerror);
116 } catch (InvalidPropertyException error) {
122 public String doAttach() {
123 // -------------------------
124 Session connex = Database.getSession();
125 Transaction transax = connex.beginTransaction();
127 // Getting user inputs
128 mystudy = getOpenStudy();
129 User user = getConnectedUser();
130 Step step = mystudy.getSelectedStep();
131 File updir = getRepositoryService().getDownloadDirectory(user);
132 File upfile = new File(updir.getPath() + "/" + filename);
133 String[] parse = filename.split("\\x2E");
135 Publication edited = step.getDocument(Integer.valueOf(index));
136 ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
138 if (logger.isInfoEnabled())
139 logger.info("Moving \"" + upfile.getName() + "\" to \""
140 + updir.getPath() + "\".");
141 upfile.renameTo(export.getTo().asFile());
143 mystudy.update(edited);
146 } catch (Exception error) {
147 logger.error("Reason:", error);
152 public String doDeleteDocument() {
153 // ---------------------------------
154 Session connex = Database.getSession();
155 Transaction transax = connex.beginTransaction();
157 mystudy = getOpenStudy();
159 Step step = mystudy.getSelectedStep();
160 Publication doctag = step.getDocument(Integer.valueOf(index));
162 getStepService().removeDocument(step, doctag); // Updates the data structure
165 mystudy.remove(doctag); // Updates the presentation
167 } catch (RuntimeException saverror) {
168 logger.error("Reason:", saverror);
169 if (transax != null && transax.isActive()) {
170 // Second try-catch as the rollback could fail as well
173 } catch (HibernateException backerror) {
174 logger.debug("Error rolling back transaction", backerror);
181 // ==============================================================================================================================
182 // Getters and setters
183 // ==============================================================================================================================
185 public void setDocumentTitle(String title) {
186 // -------------------------------------------
190 public void setFileName(String filename) {
191 // -----------------------------------------
192 this.filename = filename;
195 public void setIndex(String index) {
196 // -----------------------------------
201 * Get the publicationService.
203 * @return the publicationService
205 public PublicationService getPublicationService() {
206 return _publicationService;
210 * Set the publicationService.
212 * @param publicationService
213 * the publicationService to set
215 public void setPublicationService(PublicationService publicationService) {
216 _publicationService = publicationService;
220 * Get the repositoryService.
222 * @return the repositoryService
224 public RepositoryService getRepositoryService() {
225 return _repositoryService;
229 * Set the repositoryService.
231 * @param repositoryService
232 * the repositoryService to set
234 public void setRepositoryService(RepositoryService repositoryService) {
235 _repositoryService = repositoryService;
239 * Get the stepService.
240 * @return the stepService
242 public StepService getStepService() {
247 * Set the stepService.
248 * @param stepService the stepService to set
250 public void setStepService(StepService stepService) {
251 _stepService = stepService;