import org.splat.dal.bo.som.Publication;
import org.splat.dal.bo.som.ConvertsRelation;
import org.splat.service.PublicationService;
+import org.splat.service.technical.RepositoryService;
import org.splat.som.Step;
-
+/**
+ * Document modification action.
+ */
public class EditDocumentAction extends DisplayStudyStepAction {
- private String index = null;
- private String title = null;
- private String filename = null;
+ /**
+ * Serial version ID.
+ */
+ private static final long serialVersionUID = 4573036736137033679L;
+
+ private String index = null;
+ private String title = null;
+ private String filename = null;
+ /**
+ * Injected publication service.
+ */
private PublicationService _publicationService;
+ /**
+ * Injected repository service.
+ */
+ private RepositoryService _repositoryService;
- private static final long serialVersionUID = 4573036736137033679L;
+ /**
+ * Operations enumeration.
+ */
+ private enum Execute {
+ renameDocument, accept, promote, demote, review, invalidate, approve, disapprove
+ };
+
+ // ==============================================================================================================================
+ // Action methods
+ // ==============================================================================================================================
+
+ /**
+ * Open a study.
+ *
+ * @return SUCCESS
+ */
+ public String doInitialize() {
+ mystudy = getOpenStudy();
+ return SUCCESS;
+ }
+
+ public String doSetDocument() {
+ // ------------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ mystudy = getOpenStudy();
+
+ Execute todo = Execute.valueOf(action);
+ Step step = mystudy.getSelectedStep();
+ Publication doc = step.getDocument(Integer.valueOf(index));
+
+ if (todo == Execute.renameDocument) {
+ doc.rename(title);
+ // Useless to update the document presentation
+ } else if (todo == Execute.accept) {
+ doc.actualize();
+ mystudy.update(doc);
+ } else if (todo == Execute.promote) {
+ getPublicationService().promote(doc,
+ Calendar.getInstance().getTime());
+ mystudy.update(doc);
+ } else if (todo == Execute.demote) {
+ getPublicationService().demote(doc);
+ mystudy.update(doc);
+ } else if (todo == Execute.review) {
+ getPublicationService().review(doc,
+ Calendar.getInstance().getTime());
+ mystudy.update(doc);
+ } else if (todo == Execute.invalidate) {
+ getPublicationService().invalidate(doc);
+ mystudy.update(doc);
+ } else if (todo == Execute.approve) {
+ getPublicationService().approve(doc,
+ Calendar.getInstance().getTime());
+ mystudy.update(doc);
+ mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
+ }
+ transax.commit();
+ return SUCCESS;
+ } catch (RuntimeException saverror) {
+ logger.error("Reason:", saverror);
+ if (transax != null && transax.isActive()) {
+ // Second try-catch as the rollback could fail as well
+ try {
+ transax.rollback();
+ } catch (HibernateException backerror) {
+ logger.debug("Error rolling back transaction", backerror);
+ }
+ }
+ return ERROR;
+ } catch (InvalidPropertyException error) {
+ transax.commit();
+ return INPUT;
+ }
+ }
+
+ public String doAttach() {
+ // -------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ // Getting user inputs
+ mystudy = getOpenStudy();
+ User user = getConnectedUser();
+ Step step = mystudy.getSelectedStep();
+ File updir = getRepositoryService().getDownloadDirectory(user);
+ File upfile = new File(updir.getPath() + "/" + filename);
+ String[] parse = filename.split("\\x2E");
+
+ Publication edited = step.getDocument(Integer.valueOf(index));
+ ConvertsRelation export = edited.attach(parse[parse.length - 1]);
+
+ if (logger.isInfoEnabled())
+ logger.info("Moving \"" + upfile.getName() + "\" to \""
+ + updir.getPath() + "\".");
+ upfile.renameTo(export.getTo().asFile());
+
+ mystudy.update(edited);
+ transax.commit();
+ return SUCCESS;
+ } catch (Exception error) {
+ logger.error("Reason:", error);
+ return ERROR;
+ }
+ }
+
+ public String doDeleteDocument() {
+ // ---------------------------------
+ Session connex = Database.getSession();
+ Transaction transax = connex.beginTransaction();
+ try {
+ mystudy = getOpenStudy();
+
+ Step step = mystudy.getSelectedStep();
+ Publication doctag = step.getDocument(Integer.valueOf(index));
+
+ step.removeDocument(doctag); // Updates the data structure
+ transax.commit();
+
+ mystudy.remove(doctag); // Updates the presentation
+ return SUCCESS;
+ } catch (RuntimeException saverror) {
+ logger.error("Reason:", saverror);
+ if (transax != null && transax.isActive()) {
+ // Second try-catch as the rollback could fail as well
+ try {
+ transax.rollback();
+ } catch (HibernateException backerror) {
+ logger.debug("Error rolling back transaction", backerror);
+ }
+ }
+ return ERROR;
+ }
+ }
+
+ // ==============================================================================================================================
+ // Getters and setters
+ // ==============================================================================================================================
+
+ public void setDocumentTitle(String title) {
+ // -------------------------------------------
+ this.title = title;
+ }
+
+ public void setFileName(String filename) {
+ // -----------------------------------------
+ this.filename = filename;
+ }
+
+ public void setIndex(String index) {
+ // -----------------------------------
+ this.index = index;
+ }
- private enum Execute { renameDocument, accept, promote, demote, review, invalidate, approve, disapprove };
-
-// ==============================================================================================================================
-// Action methods
-// ==============================================================================================================================
-
- public String doInitialize () {
-// -----------------------------
-// Session connex = Database.getSession();
-// Transaction transax = connex.beginTransaction();
-
- mystudy = getOpenStudy();
-
-// transax.commit();
- return SUCCESS;
- }
-
- public String doSetDocument () {
-// ------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- mystudy = getOpenStudy();
-
- Execute todo = Execute.valueOf(action);
- Step step = mystudy.getSelectedStep();
- Publication doc = step.getDocument(Integer.valueOf(index));
-
- if (todo == Execute.renameDocument) {
- doc.rename(title);
-// Useless to update the document presentation
- } else
- if (todo == Execute.accept) {
- doc.actualize();
- mystudy.update(doc);
- } else
- if (todo == Execute.promote) {
- getPublicationService().promote(doc, Calendar.getInstance().getTime());
- mystudy.update(doc);
- } else
- if (todo == Execute.demote) {
- getPublicationService().demote(doc);
- mystudy.update(doc);
- } else
- if (todo == Execute.review) {
- getPublicationService().review(doc, Calendar.getInstance().getTime());
- mystudy.update(doc);
- } else
- if (todo == Execute.invalidate) {
- getPublicationService().invalidate(doc);
- mystudy.update(doc);
- } else
- if (todo == Execute.approve) {
- getPublicationService().approve(doc, Calendar.getInstance().getTime());
- mystudy.update(doc);
- mystudy.getMenu().refreshSelectedItem(); // Updates the menu icon, in case of other documents in approved state
- }
- transax.commit();
- return SUCCESS;
- }
- catch (RuntimeException saverror) {
- logger.error("Reason:", saverror);
- if (transax != null && transax.isActive()) {
-// Second try-catch as the rollback could fail as well
- try {
- transax.rollback();
- } catch (HibernateException backerror) {
- logger.debug("Error rolling back transaction", backerror);
- }
- }
- return ERROR;
- }
- catch (InvalidPropertyException error) {
- transax.commit();
- return INPUT;
- }
- }
-
- public String doAttach () {
-// -------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
-// Getting user inputs
- mystudy = getOpenStudy();
- User user = getConnectedUser();
- Step step = mystudy.getSelectedStep();
- File updir = Database.getDownloadDirectory(user);
- File upfile = new File(updir.getPath() + "/" + filename);
- String[] parse = filename.split("\\x2E");
-
- Publication edited = step.getDocument(Integer.valueOf(index));
- ConvertsRelation export = edited.attach(parse[parse.length-1]);
-
- if (logger.isInfoEnabled()) logger.info("Moving \"" + upfile.getName() + "\" to \"" + updir.getPath() + "\".");
- upfile.renameTo(export.getTo().asFile());
-
- mystudy.update(edited);
- transax.commit();
- return SUCCESS;
- }
- catch (Exception error) {
- logger.error("Reason:", error);
- return ERROR;
- }
- }
-
- public String doDeleteDocument () {
-// ---------------------------------
- Session connex = Database.getSession();
- Transaction transax = connex.beginTransaction();
- try {
- mystudy = getOpenStudy();
-
- Step step = mystudy.getSelectedStep();
- Publication doctag = step.getDocument(Integer.valueOf(index));
-
- step.removeDocument(doctag); // Updates the data structure
- transax.commit();
-
- mystudy.remove(doctag); // Updates the presentation
- return SUCCESS;
- }
- catch (RuntimeException saverror) {
- logger.error("Reason:", saverror);
- if (transax != null && transax.isActive()) {
-// Second try-catch as the rollback could fail as well
- try {
- transax.rollback();
- } catch (HibernateException backerror) {
- logger.debug("Error rolling back transaction", backerror);
- }
- }
- return ERROR;
- }
- }
-
-// ==============================================================================================================================
-// Getters and setters
-// ==============================================================================================================================
-
- public void setDocumentTitle (String title) {
-// -------------------------------------------
- this.title = title;
- }
- public void setFileName (String filename) {
-// -----------------------------------------
- this.filename = filename;
- }
- public void setIndex (String index) {
-// -----------------------------------
- this.index = index;
- }
/**
* Get the publicationService.
*
public void setPublicationService(PublicationService publicationService) {
_publicationService = publicationService;
}
+
+ /**
+ * Get the repositoryService.
+ *
+ * @return the repositoryService
+ */
+ public RepositoryService getRepositoryService() {
+ return _repositoryService;
+ }
+
+ /**
+ * Set the repositoryService.
+ *
+ * @param repositoryService
+ * the repositoryService to set
+ */
+ public void setRepositoryService(RepositoryService repositoryService) {
+ _repositoryService = repositoryService;
+ }
}
\ No newline at end of file