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
27
28
29
30
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
46
47
48
49
50
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
60
61 return super.start(workbenchForm, result, request, response);
62 }
63
64
65
66
67
68
69
70
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
79
80
81
82
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
92
93
94
95
96
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132 } catch (Exception e) {
133 e.printStackTrace();
134 }
135 return getUIFModelAndView(workbenchForm);
136 }
137
138
139
140
141
142
143
144
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 }