1 package uk.ac.ebi.intenz.webapp.controller.search;
2
3 import org.apache.log4j.Logger;
4 import org.apache.struts.action.*;
5 import org.apache.struts.Globals;
6 import org.apache.struts.taglib.html.Constants;
7
8 import uk.ac.ebi.intenz.domain.constants.EnzymeViewConstant;
9 import uk.ac.ebi.intenz.domain.constants.EventConstant;
10 import uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry;
11 import uk.ac.ebi.intenz.domain.enzyme.EnzymeName;
12 import uk.ac.ebi.intenz.domain.exceptions.DomainException;
13 import uk.ac.ebi.intenz.domain.history.HistoryEvent;
14 import uk.ac.ebi.intenz.mapper.EnzymeEntryMapper;
15 import uk.ac.ebi.intenz.webapp.utilities.ControlFlowToken;
16 import uk.ac.ebi.intenz.webapp.utilities.IntEnzUtilities;
17 import uk.ac.ebi.intenz.webapp.dtos.GhostEnzymeListDTO;
18 import uk.ac.ebi.intenz.webapp.dtos.GhostEnzymeDTO;
19 import uk.ac.ebi.xchars.SpecialCharacters;
20 import uk.ac.ebi.xchars.domain.EncodingType;
21
22 import javax.servlet.http.HttpServletRequest;
23 import javax.servlet.http.HttpServletResponse;
24 import java.sql.Connection;
25 import java.sql.SQLException;
26 import java.util.Map;
27 import java.util.List;
28 import java.util.ArrayList;
29
30
31
32
33
34
35
36 public class SearchProposedAction extends Action {
37
38 private final static String PROPOSED_ENTRIES_JSP_FWD = "proposed_entries";
39
40 private static final Logger LOGGER =
41 Logger.getLogger(SearchProposedAction.class.getName());
42
43 public ActionForward execute(ActionMapping mapping,
44 ActionForm form,
45 HttpServletRequest request,
46 HttpServletResponse response) throws Exception {
47 Connection con = (Connection) request.getSession().getAttribute("connection");
48 EnzymeEntryMapper enzymeEntryMapper = new EnzymeEntryMapper();
49 GhostEnzymeListDTO ghostEnzymeListDTO = (GhostEnzymeListDTO) form;
50
51
52 SpecialCharacters encoding = (SpecialCharacters) request.getSession().getAttribute("characters");
53
54
55 ghostEnzymeListDTO.setGhostEnzymeList(getEnzymeDTOInstances(enzymeEntryMapper.findProposedList(con), encoding, null));
56
57 request.setAttribute("title", "Proposed Entries - IntEnz Curator Application");
58 return mapping.findForward(PROPOSED_ENTRIES_JSP_FWD);
59 }
60
61
62
63
64
65
66
67
68
69
70 private List getEnzymeDTOInstances(List proposedList, SpecialCharacters encoding, EncodingType encodingType) {
71 assert proposedList != null : "Parameter 'proposedList' must not be null.";
72 assert encoding != null : "Parameter 'encoding' must not be null.";
73
74 List ghostEntryList = new ArrayList();
75 for (int iii = 0; iii < proposedList.size(); iii++) {
76 EnzymeEntry enzymeEntry = (EnzymeEntry) proposedList.get(iii);
77 GhostEnzymeDTO ghostEnzymeDTO = new GhostEnzymeDTO();
78 ghostEnzymeDTO.setEnzymeId(enzymeEntry.getId().toString());
79 ghostEnzymeDTO.setEc(enzymeEntry.getEc().toString());
80 List commonNames = enzymeEntry.getCommonNames();
81 for (int jjj = 0; jjj < commonNames.size(); jjj++) {
82 EnzymeName commonName = (EnzymeName) commonNames.get(jjj);
83 if (commonName.getView().isInIntEnzView()) {
84 ghostEnzymeDTO.setName(encoding.xml2Display(commonName.getName(), encodingType));
85 break;
86 }
87 }
88 ghostEnzymeDTO.setSource(enzymeEntry.getSource().toString());
89 ghostEnzymeDTO.setStatus(enzymeEntry.getStatus().toString());
90 final HistoryEvent latestHistoryEventOfRoot = enzymeEntry.getHistory().getLatestHistoryEventOfRoot();
91 ghostEnzymeDTO.setEventClass(latestHistoryEventOfRoot.getEventClass().toString());
92
93
94 if (latestHistoryEventOfRoot.getEventClass() == EventConstant.TRANSFER &&
95 !enzymeEntry.getHistory().isTransferredRootNode())
96 ghostEnzymeDTO.setEventClass(EventConstant.CREATION.toString());
97 ghostEnzymeDTO.setEventNote(IntEnzUtilities.linkMarkedEC(enzymeEntry.getHistory().getLatestHistoryEventOfRoot().getNote(), true));
98 ghostEntryList.add(ghostEnzymeDTO);
99 }
100 return ghostEntryList;
101 }
102 }