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 String index = null;
26 private String title = null;
27 private 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 * Value of the menu property.
43 * It can be: none, create, open, study, knowledge, sysadmin, help.
45 private String _menuProperty;
48 * Value of the title bar property.
49 * It can be: study, knowledge.
51 private String _titleProperty;
54 * Value of the tool bar property.
55 * It can be: none, standard, study, back.
57 private String _toolProperty;
60 * Property that indicates whether the current open study is editable or not.
61 * On the screen it looks like pen on the status icon, pop-up menu also can be called.
62 * It is necessary for correct building the title bar.
64 private String _editDisabledProperty = "false";
67 * Operations enumeration.
69 private enum Execute {
70 renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
73 // ==============================================================================================================================
75 // ==============================================================================================================================
82 public String doInitialize() {
83 mystudy = getOpenStudy();
85 setMenuProperty("study");
86 setTitleProperty("study");
87 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
88 setToolProperty("study");
90 setToolProperty("standard");
92 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
97 public String doSetDocument() {
99 setMenuProperty("study");
100 setTitleProperty("study");
101 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
102 setToolProperty("study");
104 setToolProperty("standard");
106 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
109 mystudy = getOpenStudy();
111 Execute todo = Execute.valueOf(action);
112 Step step = mystudy.getSelectedStep();
113 Publication doc = step.getDocument(Integer.valueOf(index));
115 if (todo == Execute.renameDocument) {
116 getPublicationService().rename(doc, title);
117 // Useless to update the document presentation
118 } else if (todo == Execute.accept) {
119 getPublicationService().actualize(doc);
121 } else if (todo == Execute.promote) {
122 getPublicationService().promote(doc,
123 Calendar.getInstance().getTime());
125 } else if (todo == Execute.demote) {
126 getPublicationService().demote(doc);
128 } else if (todo == Execute.review) {
129 getPublicationService().review(doc,
130 Calendar.getInstance().getTime());
132 } else if (todo == Execute.invalidate) {
133 getPublicationService().invalidate(doc);
135 } else if (todo == Execute.approve) {
136 getPublicationService().approve(doc,
137 Calendar.getInstance().getTime());
139 mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
142 } catch (RuntimeException saverror) {
143 logger.error("Reason:", saverror);
145 } catch (InvalidPropertyException error) {
150 public String doAttach() {
151 // -------------------------
152 // Session connex = Database.getCurSession();
153 // Transaction transax = connex.beginTransaction();
155 setMenuProperty("study");
156 setTitleProperty("study");
157 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
158 setToolProperty("study");
160 setToolProperty("standard");
162 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
165 // Getting user inputs
166 mystudy = getOpenStudy();
167 User user = getConnectedUser();
168 Step step = mystudy.getSelectedStep();
169 File updir = getRepositoryService().getDownloadDirectory(user);
170 File upfile = new File(updir.getPath() + "/" + filename);
171 String[] parse = filename.split("\\x2E");
173 Publication edited = step.getDocument(Integer.valueOf(index));
174 ConvertsRelation export = getPublicationService().attach(edited, parse[parse.length - 1]);
176 if (logger.isInfoEnabled())
177 logger.info("Moving \"" + upfile.getName() + "\" to \""
178 + updir.getPath() + "\".");
179 upfile.renameTo(export.getTo().asFile());
181 mystudy.update(edited);
184 } catch (Exception error) {
185 logger.error("Reason:", error);
190 public String doDeleteDocument() {
192 setMenuProperty("study");
193 setTitleProperty("study");
194 if ("true".equals(getWriteAccess()) && getUserRights().canCreateDocument()) {
195 setToolProperty("study");
197 setToolProperty("standard");
199 initializationScreenContext(_menuProperty, _titleProperty, _editDisabledProperty, _toolProperty);
202 mystudy = getOpenStudy();
204 Step step = mystudy.getSelectedStep();
205 Publication doctag = step.getDocument(Integer.valueOf(index));
207 getStepService().removeDocument(step, doctag); // Updates the data structure
209 mystudy.remove(doctag); // Updates the presentation
211 } catch (RuntimeException saverror) {
212 logger.error("Reason:", saverror);
217 // ==============================================================================================================================
218 // Getters and setters
219 // ==============================================================================================================================
221 public void setDocumentTitle(String title) {
222 // -------------------------------------------
226 public void setFileName(String filename) {
227 // -----------------------------------------
228 this.filename = filename;
231 public void setIndex(String index) {
232 // -----------------------------------
237 * Get the publicationService.
239 * @return the publicationService
241 public PublicationService getPublicationService() {
242 return _publicationService;
246 * Set the publicationService.
248 * @param publicationService
249 * the publicationService to set
251 public void setPublicationService(PublicationService publicationService) {
252 _publicationService = publicationService;
256 * Get the repositoryService.
258 * @return the repositoryService
260 public RepositoryService getRepositoryService() {
261 return _repositoryService;
265 * Set the repositoryService.
267 * @param repositoryService
268 * the repositoryService to set
270 public void setRepositoryService(RepositoryService repositoryService) {
271 _repositoryService = repositoryService;
275 * Get the stepService.
276 * @return the stepService
278 public StepService getStepService() {
283 * Set the stepService.
284 * @param stepService the stepService to set
286 public void setStepService(StepService stepService) {
287 _stepService = stepService;
291 * Get the menuProperty.
292 * @return the menuProperty
294 public String getMenuProperty() {
295 return _menuProperty;
299 * Set the menuProperty.
300 * @param menuProperty the menuProperty to set
302 public void setMenuProperty(String menuProperty) {
303 this._menuProperty = menuProperty;
307 * Get the _titleProperty.
308 * @return the _titleProperty
310 public String getTitleProperty() {
311 return _titleProperty;
315 * Set the _titleProperty.
316 * @param _titleProperty the titleProperty to set
318 public void setTitleProperty(String titleProperty) {
319 _titleProperty = titleProperty;
323 * Get the editDisabledProperty.
324 * @return the editDisabledProperty
326 public String getEditDisabledProperty() {
327 return _editDisabledProperty;
331 * Set the editDisabledProperty.
332 * @param editDisabledProperty the editDisabledProperty to set
334 public void setEditDisabledProperty(String editDisabledProperty) {
335 _editDisabledProperty = editDisabledProperty;
340 * Get the toolProperty.
341 * @return the toolProperty
343 public String getToolProperty() {
344 return _toolProperty;
348 * Set the toolProperty.
349 * @param toolProperty the toolProperty to set
351 public void setToolProperty(final String toolProperty) {
352 _toolProperty = toolProperty;