View Javadoc

1   package uk.ac.ebi.intenz.webapp.controller.helper.dtoinit;
2   
3   import org.apache.log4j.Logger;
4   import org.apache.struts.action.Action;
5   import org.apache.struts.action.ActionForm;
6   import org.apache.struts.action.ActionForward;
7   import org.apache.struts.action.ActionMapping;
8   import org.apache.struts.util.TokenProcessor;
9   import org.apache.struts.Globals;
10  import org.apache.struts.taglib.html.Constants;
11  
12  import uk.ac.ebi.intenz.domain.constants.EnzymeNameTypeConstant;
13  import uk.ac.ebi.intenz.domain.enzyme.*;
14  import uk.ac.ebi.intenz.domain.history.HistoryGraph;
15  import uk.ac.ebi.intenz.domain.reference.Book;
16  import uk.ac.ebi.intenz.domain.reference.Journal;
17  import uk.ac.ebi.intenz.domain.reference.Patent;
18  import uk.ac.ebi.intenz.domain.reference.Reference;
19  import uk.ac.ebi.intenz.webapp.dtos.*;
20  import uk.ac.ebi.intenz.webapp.utilities.IntEnzUtilities;
21  import uk.ac.ebi.intenz.webapp.utilities.IntEnzUtilities;
22  import uk.ac.ebi.xchars.SpecialCharacters;
23  import uk.ac.ebi.xchars.domain.EncodingType;
24  
25  import javax.servlet.http.HttpServletRequest;
26  import javax.servlet.http.HttpServletResponse;
27  import java.util.ArrayList;
28  import java.util.Iterator;
29  import java.util.List;
30  import java.util.SortedSet;
31  
32  /**
33   * This Action ...
34   *
35   * @author Michael Darsow
36   * @version $Revision: 1.2 $ $Date: 2008/01/28 12:33:00 $
37   */
38  public class PopulateEnzymeListDTOAction extends Action {
39    private final static String ALL_ENTRIES_JSP_FWD = "entries";
40  
41    private static final Logger LOGGER =
42  	  Logger.getLogger(PopulateEnzymeListDTOAction.class.getName());
43  
44    public ActionForward execute(ActionMapping mapping,
45                                 ActionForm form,
46                                 HttpServletRequest request,
47                                 HttpServletResponse response) throws Exception {
48      LOGGER.debug("PopulateEnzymeListDTOAction");
49  
50      // Get special characters instance (set in the servlet handler's process method).
51      SpecialCharacters encoding = (SpecialCharacters) request.getSession().getAttribute("characters");
52  
53      // TODO: provide means to choose the view and the corresponding encoding type.
54      EncodingType encodingType = null;
55  
56      // Populate form.
57      populateForm((List) request.getAttribute("result"), form, encoding, encodingType);
58  
59      return mapping.findForward(ALL_ENTRIES_JSP_FWD);
60    }
61  
62    private void populateForm(List result, ActionForm form, SpecialCharacters encoding, EncodingType encodingType) {
63      LOGGER.debug("Populating EnzymeListDTO ...");
64      EnzymeListDTO enzymeListDTO = (EnzymeListDTO) form;
65      List ghostEntryList = new ArrayList();
66      for (int iii = 0; iii < result.size(); iii++) {
67        EnzymeEntry enzymeEntry = (EnzymeEntry) result.get(iii);
68        GhostEnzymeDTO ghostEnzymeDTO = new GhostEnzymeDTO();
69        ghostEnzymeDTO.setEnzymeId(enzymeEntry.getId().toString());
70        ghostEnzymeDTO.setEc(enzymeEntry.getEc().toString());
71        List commonNames = enzymeEntry.getCommonNames();
72        for (int jjj = 0; jjj < commonNames.size(); jjj++) {
73          EnzymeName commonName = (EnzymeName) commonNames.get(jjj);
74          if(commonName.getView().isInIntEnzView()) {
75            ghostEnzymeDTO.setName(encoding.xml2Display(commonName.getName(), encodingType));
76            break;
77          }
78        }
79        ghostEnzymeDTO.setSource(enzymeEntry.getSource().toString());
80        ghostEnzymeDTO.setStatus(enzymeEntry.getStatus().toString());
81        ghostEnzymeDTO.setActive(enzymeEntry.isActive());
82        ghostEnzymeDTO.setEventClass(getEventClass(enzymeEntry));
83        ghostEnzymeDTO.setEventNote(IntEnzUtilities.linkMarkedEC(enzymeEntry.getHistory().getLatestRelevantHistoryEventOfRoot().getNote(), true));
84        ghostEntryList.add(ghostEnzymeDTO);
85      }
86      enzymeListDTO.setResult(ghostEntryList);
87      LOGGER.debug("... EnzymeListDTO populated.");
88    }
89  
90     private String getEventClass(EnzymeEntry enzymeEntry){
91        return enzymeEntry.getHistory().getLatestRelevantHistoryEventOfRoot()
92      		  .getEventClass().toString();
93     }
94  
95  }