1 package uk.ac.ebi.intenz.webapp.controller.modification;
2
3 import org.apache.log4j.Logger;
4 import org.apache.struts.action.*;
5 import org.apache.struts.taglib.html.Constants;
6 import uk.ac.ebi.intenz.webapp.dtos.*;
7 import uk.ac.ebi.intenz.webapp.utilities.ControlFlowToken;
8 import uk.ac.ebi.intenz.webapp.utilities.EntryLockSingleton;
9
10 import javax.servlet.http.HttpServletRequest;
11 import javax.servlet.http.HttpServletResponse;
12 import java.util.Map;
13
14
15
16
17
18
19
20
21 public class CurationAction extends Action {
22
23 private static final Logger LOGGER =
24 Logger.getLogger(CurationAction.class.getName());
25 private final static String SEARCH_BY_ID_ACTION_FWD = "searchId";
26
27 public ActionForward execute(ActionMapping mapping,
28 ActionForm form,
29 HttpServletRequest request,
30 HttpServletResponse response) throws Exception {
31 LOGGER.info("CurationAction");
32 ActionMessages errors = new ActionMessages();
33
34 EnzymeDTO enzymeDTO = (EnzymeDTO) form;
35 if(enzymeDTO.getId() == null || enzymeDTO.getId().equals("")) return null;
36 Long enzymeId = new Long(enzymeDTO.getId());
37
38
39 if (request.getParameter(Constants.TOKEN_KEY) != null && !ControlFlowToken.isValid(request)) {
40 Map tokenHashtable = (Map) request.getSession().getAttribute("tokenHashtable");
41 LOGGER.debug("Entry with ID " + enzymeId + " is being discarded ...");
42 enzymeId = (Long) tokenHashtable.get(request.getParameter(Constants.TOKEN_KEY));
43 LOGGER.debug("... entry with ID " + enzymeId + " will be loaded instead.");
44
45
46 errors.add(ActionMessages.GLOBAL_MESSAGE, new ActionMessage("errors.application.entry.reloaded.noec"));
47 saveErrors(request, errors);
48
49
50 ActionForward forward = mapping.findForward(SEARCH_BY_ID_ACTION_FWD);
51 StringBuffer path = new StringBuffer(forward.getPath());
52 boolean isQuery = (path.indexOf("?") > -1);
53 if (isQuery) {
54 path.append("&view=" + mapping.getInputForward().getPath() + "&reload=true&id=");
55 } else {
56 path.append("?view=" + mapping.getInputForward().getPath() + "&reload=true&id=");
57 }
58 path.append(enzymeId);
59
60 return new ActionForward(path.toString());
61 }
62
63 return null;
64 }
65
66
67
68
69
70
71
72 protected void keepToken(HttpServletRequest request) {
73 if (request == null) throw new NullPointerException("Parameter 'request' must not be null.");
74 if (request.getParameter(Constants.TOKEN_KEY) != null) request.setAttribute(Constants.TOKEN_KEY, request.getParameter(Constants.TOKEN_KEY));
75 }
76 }