View Javadoc
1   package uk.ac.ebi.intenz.webapp.controller.modification;
2   
3   import java.sql.Connection;
4   import java.sql.SQLException;
5   
6   import javax.servlet.http.HttpServletRequest;
7   import javax.servlet.http.HttpServletResponse;
8   
9   import org.apache.log4j.Logger;
10  import org.apache.struts.action.ActionForm;
11  import org.apache.struts.action.ActionForward;
12  import org.apache.struts.action.ActionMapping;
13  import org.apache.struts.action.ActionMessage;
14  import org.apache.struts.action.ActionMessages;
15  
16  import uk.ac.ebi.intenz.domain.constants.Status;
17  import uk.ac.ebi.intenz.domain.exceptions.EcException;
18  import uk.ac.ebi.intenz.mapper.AuditPackageMapper;
19  import uk.ac.ebi.intenz.mapper.EventPackageMapper;
20  import uk.ac.ebi.intenz.webapp.dtos.EcSearchForm;
21  import uk.ac.ebi.intenz.webapp.dtos.EnzymeDTO;
22  import uk.ac.ebi.intenz.webapp.exceptions.DeregisterException;
23  import uk.ac.ebi.intenz.webapp.utilities.EntryLockSingleton;
24  import uk.ac.ebi.intenz.webapp.utilities.UnitOfWork;
25  
26  /**
27   * This Action ...
28   *
29   * @author Michael Darsow
30   * @version $Revision: 1.3 $ $Date: 2008/11/17 17:14:10 $
31   */
32  public class AmendEntryUpdateAction extends CurationAction {
33    private static final Logger LOGGER =
34  	  Logger.getLogger(AmendEntryUpdateAction.class.getName());
35    private final static String SEARCH_BY_EC_ACTION_FWD = "searchEc";
36  
37      @Override
38    public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request,
39                                 HttpServletResponse response) throws Exception {
40      // Do standard checks in the parent's execute method.
41      ActionForward forward = super.execute(mapping, form, request, response);
42      if (forward != null) return forward;
43  
44      ActionMessages errors = new ActionMessages();
45      EnzymeDTO enzymeDTO = (EnzymeDTO) form;
46  
47      // Validate the entry's lists.
48  //    IntEnzValidations.validateEnzymeDTOLists(enzymeDTO, errors);
49  //    if (!errors.isEmpty()) {
50  //      saveErrors(request, errors);
51  //      return mapping.getInputForward();
52  //    }
53      
54      Connection con = (Connection) request.getSession().getAttribute("connection");
55      EntryLockSingleton els = (EntryLockSingleton) request.getSession().getServletContext().getAttribute("entryLock");
56      UnitOfWork unitOfWork = (UnitOfWork) request.getSession().getAttribute("uow");
57      try {
58        // Set the standard remark in the audit tables.
59        AuditPackageMapper auditPackageMapper = new AuditPackageMapper();
60        auditPackageMapper.setRemark(AuditPackageMapper.STANDARD_REMARK, con);
61  
62        // Store event.
63        if (!enzymeDTO.getStatusCode().equals(Status.PRELIMINARY.getCode())){
64            EventPackageMapper eventPackageMapper = new EventPackageMapper();
65            eventPackageMapper.updateFutureModificationEvent(Integer.parseInt(enzymeDTO.getLatestHistoryEventGroupId()),
66                                                         Integer.parseInt(enzymeDTO.getLatestHistoryEventId()),
67                                                         enzymeDTO.getStatusCode(), con);
68        }
69        // Commit
70        LOGGER.info("Committing form data.");
71        unitOfWork.commit(enzymeDTO, con);
72        LOGGER.info("Data subimtted");
73  
74        con.commit();
75        
76        LOGGER.info("Amend event (update) finished.");
77      } catch (SQLException e){
78          con.rollback();
79          throw e;
80      } catch (EcException e) {
81        errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.application.ec.invalid", enzymeDTO.getTransferredEc()));
82        saveErrors(request, errors);
83        keepToken(request);
84        return mapping.getInputForward();
85      } catch (DeregisterException e) {
86        LOGGER.error(e.getMessage());
87        // Create standard error message (see 'struts_config.xml').
88        throw e;
89      } finally { // release lock
90        els.releaseLock(enzymeDTO.getId());
91        LOGGER.info("Lock of EC " + enzymeDTO.getEc() + " (ID: " + enzymeDTO.getEc() + " released.");
92      }
93  
94      // Forward to 'searchEc' Action to show both entries.
95      LOGGER.info("Searching for EC " + enzymeDTO.getEc());
96      EcSearchForm ecSearchForm = new EcSearchForm();
97      ecSearchForm.setEc(enzymeDTO.getEc());
98      request.setAttribute("ecSearchForm", ecSearchForm);
99      return mapping.findForward(SEARCH_BY_EC_ACTION_FWD);
100   }
101 
102 }