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.technical.RepositoryService;
16 import org.splat.som.Step;
19 * Document modification action.
21 public class EditDocumentAction extends DisplayStudyStepAction {
26 private static final long serialVersionUID = 4573036736137033679L;
28 private String index = null;
29 private String title = null;
30 private String filename = null;
32 * Injected publication service.
34 private PublicationService _publicationService;
36 * Injected repository service.
38 private RepositoryService _repositoryService;
41 * Operations enumeration.
43 private enum Execute {
44 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
47 // ==============================================================================================================================
49 // ==============================================================================================================================
56 public String doInitialize() {
57 mystudy = getOpenStudy();
61 public String doSetDocument() {
62 // ------------------------------
63 Session connex = Database.getSession();
64 Transaction transax = connex.beginTransaction();
66 mystudy = getOpenStudy();
68 Execute todo = Execute.valueOf(action);
69 Step step = mystudy.getSelectedStep();
70 Publication doc = step.getDocument(Integer.valueOf(index));
72 if (todo == Execute.renameDocument) {
74 // Useless to update the document presentation
75 } else if (todo == Execute.accept) {
78 } else if (todo == Execute.promote) {
79 getPublicationService().promote(doc,
80 Calendar.getInstance().getTime());
82 } else if (todo == Execute.demote) {
83 getPublicationService().demote(doc);
85 } else if (todo == Execute.review) {
86 getPublicationService().review(doc,
87 Calendar.getInstance().getTime());
89 } else if (todo == Execute.invalidate) {
90 getPublicationService().invalidate(doc);
92 } else if (todo == Execute.approve) {
93 getPublicationService().approve(doc,
94 Calendar.getInstance().getTime());
96 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
100 } catch (RuntimeException saverror) {
101 logger.error("Reason:", saverror);
102 if (transax != null && transax.isActive()) {
103 // Second try-catch as the rollback could fail as well
106 } catch (HibernateException backerror) {
107 logger.debug("Error rolling back transaction", backerror);
111 } catch (InvalidPropertyException error) {
117 public String doAttach() {
118 // -------------------------
119 Session connex = Database.getSession();
120 Transaction transax = connex.beginTransaction();
122 // Getting user inputs
123 mystudy = getOpenStudy();
124 User user = getConnectedUser();
125 Step step = mystudy.getSelectedStep();
126 File updir = getRepositoryService().getDownloadDirectory(user);
127 File upfile = new File(updir.getPath() + "/" + filename);
128 String[] parse = filename.split("\\x2E");
130 Publication edited = step.getDocument(Integer.valueOf(index));
131 ConvertsRelation export = edited.attach(parse[parse.length - 1]);
133 if (logger.isInfoEnabled())
134 logger.info("Moving \"" + upfile.getName() + "\" to \""
135 + updir.getPath() + "\".");
136 upfile.renameTo(export.getTo().asFile());
138 mystudy.update(edited);
141 } catch (Exception error) {
142 logger.error("Reason:", error);
147 public String doDeleteDocument() {
148 // ---------------------------------
149 Session connex = Database.getSession();
150 Transaction transax = connex.beginTransaction();
152 mystudy = getOpenStudy();
154 Step step = mystudy.getSelectedStep();
155 Publication doctag = step.getDocument(Integer.valueOf(index));
157 step.removeDocument(doctag); // Updates the data structure
160 mystudy.remove(doctag); // Updates the presentation
162 } catch (RuntimeException saverror) {
163 logger.error("Reason:", saverror);
164 if (transax != null && transax.isActive()) {
165 // Second try-catch as the rollback could fail as well
168 } catch (HibernateException backerror) {
169 logger.debug("Error rolling back transaction", backerror);
176 // ==============================================================================================================================
177 // Getters and setters
178 // ==============================================================================================================================
180 public void setDocumentTitle(String title) {
181 // -------------------------------------------
185 public void setFileName(String filename) {
186 // -----------------------------------------
187 this.filename = filename;
190 public void setIndex(String index) {
191 // -----------------------------------
196 * Get the publicationService.
198 * @return the publicationService
200 public PublicationService getPublicationService() {
201 return _publicationService;
205 * Set the publicationService.
207 * @param publicationService
208 * the publicationService to set
210 public void setPublicationService(PublicationService publicationService) {
211 _publicationService = publicationService;
215 * Get the repositoryService.
217 * @return the repositoryService
219 public RepositoryService getRepositoryService() {
220 return _repositoryService;
224 * Set the repositoryService.
226 * @param repositoryService
227 * the repositoryService to set
229 public void setRepositoryService(RepositoryService repositoryService) {
230 _repositoryService = repositoryService;