View Javadoc

1   package org.kuali.ole.describe.controller;
2   
3   import org.apache.log4j.Logger;
4   import org.kuali.ole.describe.bo.OleWorkBibDocument;
5   import org.kuali.ole.describe.form.WorkbenchForm;
6   import org.kuali.ole.docstore.discovery.model.SearchCondition;
7   import org.kuali.ole.docstore.discovery.model.SearchParams;
8   import org.kuali.ole.docstore.discovery.service.QueryService;
9   import org.kuali.ole.docstore.discovery.service.QueryServiceImpl;
10  import org.kuali.ole.docstore.model.bo.WorkBibDocument;
11  import org.kuali.rice.krad.uif.UifParameters;
12  import org.kuali.rice.krad.web.controller.UifControllerBase;
13  import org.kuali.rice.krad.web.form.UifFormBase;
14  import org.springframework.stereotype.Controller;
15  import org.springframework.validation.BindingResult;
16  import org.springframework.web.bind.annotation.ModelAttribute;
17  import org.springframework.web.bind.annotation.RequestMapping;
18  import org.springframework.web.servlet.ModelAndView;
19  
20  import javax.servlet.http.HttpServletRequest;
21  import javax.servlet.http.HttpServletResponse;
22  import java.util.ArrayList;
23  import java.util.List;
24  
25  /**
26   * Created with IntelliJ IDEA.
27   * User: PP7788
28   * Date: 11/21/12
29   * Time: 2:45 PM
30   * To change this template use File | Settings | File Templates.
31   */
32  
33  @Controller
34  @RequestMapping(value = "/describeworkbenchcontroller")
35  public class WorkbenchController extends UifControllerBase {
36  
37      private static final Logger LOG = Logger.getLogger(WorkbenchController.class);
38  
39      @Override
40      protected UifFormBase createInitialForm(HttpServletRequest httpServletRequest) {
41          return new WorkbenchForm();
42      }
43  
44      /**
45       *  This method converts UifFormBase to WorkbenchForm
46       * @param form
47       * @param result
48       * @param request
49       * @param response
50       * @return ModelAndView
51       */
52      @Override
53      @RequestMapping(params = "methodToCall=start")
54      public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
55                                HttpServletRequest request, HttpServletResponse response) {
56          LOG.debug("Inside the workbenchForm start method");
57          WorkbenchForm workbenchForm = (WorkbenchForm) form;
58          workbenchForm.getSearchParams().setDocType("bibliographic");
59          //workbenchForm.getSearchParams().setDocType("holdings");
60          //workbenchForm.getSearchParams().setDocType("item");
61          return super.start(workbenchForm, result, request, response);
62      }
63  
64      /**
65       *  Used for Test-case
66       * @param result
67       * @param request
68       * @param response
69       * @param workbenchForm
70       * @return ModelAndView
71       */
72      protected ModelAndView callSuper(BindingResult result, HttpServletRequest request, HttpServletResponse response, WorkbenchForm workbenchForm) {
73          return super.updateComponent(workbenchForm, result, request, response);
74      }
75  
76      /**
77       *
78       * @param form
79       * @param result
80       * @param request
81       * @param response
82       * @return
83       */
84      @RequestMapping(params = "methodToCall=search")
85      public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
86                                          HttpServletRequest request, HttpServletResponse response) {
87          LOG.info("Inside Search Method");
88          WorkbenchForm workbenchForm = (WorkbenchForm) form;
89          try {
90  
91              //TODO: Modify the logic based on DocTYpe selection. Since dynamic refresh is not working, hard-coded DocType to bibliographic and showing Bib Results
92             /* SearchParams searchParams = new SearchParams();
93              searchParams.setDocCategory("work");
94              searchParams.setDocType("bibliographic");
95              searchParams.setDocFormat("marc");
96              List<WorkBibDocument> workBibDocumentList = QueryServiceImpl.getInstance().queryForDocs(searchParams);*/
97  
98              workbenchForm.getSearchParams().setDocCategory("work");
99              workbenchForm.getSearchParams().setDocFormat("marc");
100             workbenchForm.getSearchParams().setDocType("bibliographic");
101             QueryService queryService = QueryServiceImpl.getInstance();
102             SearchParams searchParams = workbenchForm.getSearchParams();
103 
104             List<WorkBibDocument> workBibDocumentList = queryService.getBibDocuments(searchParams);
105             List<OleWorkBibDocument> oleWorkBibDocumentList = new ArrayList<OleWorkBibDocument>();
106 
107             for (WorkBibDocument workBibDocument : workBibDocumentList) {
108                 OleWorkBibDocument oleWorkBibDocument = new OleWorkBibDocument();
109                 oleWorkBibDocument.setId(workBibDocument.getId());
110                 oleWorkBibDocument.setTitle(workBibDocument.getTitle());
111                 oleWorkBibDocument.setAuthor(workBibDocument.getAuthor());
112                 oleWorkBibDocument.setPublicationDate(workBibDocument.getPublicationDate());
113                 oleWorkBibDocumentList.add(oleWorkBibDocument);
114             }
115             workbenchForm.setWorkBibDocumentList(oleWorkBibDocumentList);
116 
117             /*workbenchForm.getSearchParams().setDocCategory("work");
118             workbenchForm.getSearchParams().setDocFormat("oleml");
119             workbenchForm.getSearchParams().setDocType("holdings");
120             QueryService queryService = QueryServiceImpl.getInstance();
121             SearchParams searchParams = workbenchForm.getSearchParams();
122             List<WorkHoldingsDocument> workHoldingsDocuments = queryService.getHoldingDocuments(searchParams);
123             workbenchForm.setWorkHoldingsDocumentList(workHoldingsDocuments);*/
124 
125             /*workbenchForm.getSearchParams().setDocCategory("work");
126             workbenchForm.getSearchParams().setDocFormat("oleml");
127             workbenchForm.getSearchParams().setDocType("item");
128             QueryService queryService = QueryServiceImpl.getInstance();
129             SearchParams searchParams = workbenchForm.getSearchParams();
130             List<WorkItemDocument> workItemDocuments = queryService.getItemDocuments(searchParams);
131             workbenchForm.setWorkItemDocumentList(workItemDocuments);*/
132         } catch (Exception e) {
133             e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
134         }
135         return getUIFModelAndView(workbenchForm);
136     }
137 
138     /**
139      *
140      * @param form
141      * @param result
142      * @param request
143      * @param response
144      * @return
145      */
146     @RequestMapping(params = "methodToCall=clearSearch")
147     public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
148                                HttpServletRequest request, HttpServletResponse response) {
149         LOG.info("Inside clearSearch Method");
150         WorkbenchForm workbenchForm = (WorkbenchForm) form;
151         workbenchForm.setSearchParams(new SearchParams());
152         List<SearchCondition> searchConditions = workbenchForm.getSearchParams().getSearchFieldsList();
153         searchConditions.add(new SearchCondition());
154         searchConditions.add(new SearchCondition());
155         workbenchForm.getSearchParams().setDocType("bibliographic");
156         workbenchForm.setWorkBibDocumentList(null);
157         return getUIFModelAndView(workbenchForm);
158     }
159 
160     @RequestMapping(params = "methodToCall=select")
161     public ModelAndView select(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
162                                         HttpServletRequest request, HttpServletResponse response) {
163         WorkbenchForm workbenchForm = (WorkbenchForm) form;
164         int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
165         String selectedRecord = workbenchForm.getWorkBibDocumentList().get(index).getId();
166         LOG.info("selectedRecord--->" + selectedRecord);
167         return super.updateComponent(workbenchForm, result, request, response);
168     }
169 
170     @RequestMapping(params = "methodToCall=selectRecords")
171     public ModelAndView selectRecords(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
172                                         HttpServletRequest request, HttpServletResponse response) {
173         WorkbenchForm workbenchForm = (WorkbenchForm) form;
174         List<String> selectedRecordIds = new ArrayList<String>();
175         List<OleWorkBibDocument> oleWorkBibDocuments = workbenchForm.getWorkBibDocumentList();
176         for (OleWorkBibDocument oleWorkBibDocument : oleWorkBibDocuments)  {
177             if (oleWorkBibDocument.isSelect()) {
178                selectedRecordIds.add(oleWorkBibDocument.getId());
179             }
180         }
181         LOG.info("selectedRecords--->" + selectedRecordIds);
182         return getUIFModelAndView(workbenchForm);
183     }
184 
185 }