View Javadoc
1   // license-header java merge-point
2   package org.andromda.timetracker.web.timecardsearch;
3   
4   import java.util.ArrayList;
5   import java.util.Arrays;
6   import java.util.List;
7   
8   import org.andromda.timetracker.domain.TimecardStatus;
9   import org.andromda.timetracker.service.TimeTrackingServiceDelegate;
10  import org.andromda.timetracker.service.UserServiceDelegate;
11  import org.andromda.timetracker.vo.TimecardSearchCriteriaVO;
12  import org.andromda.timetracker.vo.TimecardSummaryVO;
13  import org.andromda.timetracker.vo.UserVO;
14  import org.andromda.timetracker.vo.UserVOComparator;
15  import org.apache.commons.logging.Log;
16  import org.apache.commons.logging.LogFactory;
17  
18  /**
19   * @see org.andromda.timetracker.web.timecardsearch.SearchController
20   */
21  public class SearchControllerImpl
22      extends SearchController
23  {
24      private static final long serialVersionUID = 1465722497189650491L;
25  
26      private Log logger = LogFactory.getLog(SearchControllerImpl.class);
27      private static final String ALL_STRING = "-- All --";
28  
29      /**
30       * @see org.andromda.timetracker.web.timecardsearch.SearchController#populateSearchScreen(java.lang.Long submitter, java.lang.Long approver, java.lang.String status, java.util.Date startDateMinimum, java.util.Date startDateMaximum)
31       */
32      public void populateSearchScreen(PopulateSearchScreenForm form)
33      {
34  //        form.setSubmitterValueList(new Object[] {"submitter-1", "submitter-2", "submitter-3", "submitter-4", "submitter-5"});
35  //        form.setSubmitterLabelList(form.getSubmitterValueList());
36  //        form.setApproverValueList(new Object[] {"approver-1", "approver-2", "approver-3", "approver-4", "approver-5"});
37  //        form.setApproverLabelList(form.getApproverValueList());
38  //        form.setStatusValueList(new Object[] {"status-1", "status-2", "status-3", "status-4", "status-5"});
39  //        form.setStatusLabelList(form.getStatusValueList());
40  
41  
42          if (logger.isDebugEnabled())
43          {
44              logger.debug("form: " + form);
45          }
46  
47          // Get the list of users and add the "All" option at the top
48          UserVO[] users = null;
49          UserServiceDelegate usd = null;
50          try
51          {
52              usd = new UserServiceDelegate();
53              users = usd.getAllUsers();
54          }
55          finally
56          {
57              usd.close();
58          }
59  
60          if (users != null)
61          {
62              Arrays.sort(users, new UserVOComparator());
63              List userList = new ArrayList(Arrays.asList(users));
64              userList.add(0, new UserVO(Long.valueOf(0), ALL_STRING, null, null));
65  
66              // Populate the submitter and approver dropdowns
67              form.setSubmitterBackingList(userList, "id", "username");
68              form.setApproverBackingList(userList, "id", "username");
69          }
70  
71          // Populate the status dropdown
72          List statusLabels = new ArrayList(TimecardStatus.literals());
73          List statusValues = new ArrayList(TimecardStatus.literals());
74          statusLabels.add(0, ALL_STRING);
75          statusValues.add(0, "");
76          form.setStatusLabelList(statusLabels.toArray());
77          form.setStatusValueList(statusValues.toArray());
78  
79          TimecardStatus status = null;
80          if (form.getStatus() != null && form.getStatus().length() > 0)
81          {
82              status = TimecardStatus.fromString(form.getStatus());
83          }
84  
85          // Populate timecard summaries
86          TimecardSearchCriteriaVO criteria = new TimecardSearchCriteriaVO(
87                  form.getSubmitter(),
88                  form.getApprover(),
89                  status,
90                  form.getStartDateMinimum(),
91                  form.getStartDateMaximum());
92  
93          TimeTrackingServiceDelegate tsd = null;
94          try
95          {
96              tsd = new TimeTrackingServiceDelegate();
97              TimecardSummaryVO[] timecards = tsd.findTimecards(criteria);
98              form.setTimecardSummaries(timecards);
99          }
100         catch (Exception e)
101         {
102             logger.error("failed finding timecards", e);
103         }
104         finally
105         {
106             tsd.close();
107         }
108     }
109 
110     /**
111      * @see org.andromda.timetracker.web.timecardsearch.SearchController#initializeTimecardId(org.andromda.timetracker.web.timecardsearch.InitializeTimecardIdForm)
112      */
113     public void initializeTimecardId(InitializeTimecardIdForm form)
114     {
115         form.setTimecardId(form.getId());
116     }
117 
118 }