View Javadoc

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   * This Action retreives all proposed entries and forwards to a page to display them.
32   *
33   * @author Michael Darsow
34   * @version $Revision: 1.3 $ $Date: 2008/11/17 17:14:10 $
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      // Get special characters instance (set in the servlet handler's process method).
52      SpecialCharacters encoding = (SpecialCharacters) request.getSession().getAttribute("characters");
53  
54      // Populate form.
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     * Populates {@link uk.ac.ebi.intenz.webapp.dtos.GhostEnzymeDTO} instances and adds the to an
63     * {@link java.util.ArrayList}.
64     *
65     * @param proposedList List of {@link uk.ac.ebi.intenz.domain.enzyme.EnzymeEntry} instances.
66     * @param encoding An instance of {@link uk.ac.ebi.xchars.SpecialCharacters}.
67     * @param encodingType The {@link uk.ac.ebi.xchars.domain.EncodingType} to be used to create the display string.
68     * @return an {@link java.util.ArrayList} of {@link uk.ac.ebi.intenz.webapp.dtos.GhostEnzymeDTO} instances.  
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        // Check whether this node has been transferred (set event class to 'TRA') or
93        // if it is the new enzyme in a transfer process (set event class NOT to 'TRA' but 'NEW').
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 }