1 package org.kuali.ole.select.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.kuali.ole.OLEConstants;
5 import org.kuali.ole.select.document.OLEEResourceRecordDocument;
6 import org.kuali.ole.select.form.OLEEResourceChangeDashboardForm;
7 import org.kuali.ole.select.gokb.*;
8 import org.kuali.ole.service.OLEEResourceHelperService;
9 import org.kuali.ole.service.OLEEResourceSearchService;
10 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
11 import org.kuali.rice.krad.service.BusinessObjectService;
12 import org.kuali.rice.krad.service.KRADServiceLocator;
13 import org.kuali.rice.krad.web.controller.UifControllerBase;
14 import org.kuali.rice.krad.web.form.UifFormBase;
15 import org.springframework.stereotype.Controller;
16 import org.springframework.validation.BindingResult;
17 import org.springframework.web.bind.annotation.ModelAttribute;
18 import org.springframework.web.bind.annotation.RequestMapping;
19 import org.springframework.web.servlet.ModelAndView;
20
21 import javax.servlet.http.HttpServletRequest;
22 import javax.servlet.http.HttpServletResponse;
23 import java.sql.Timestamp;
24 import java.util.*;
25
26
27
28
29 @Controller
30 @RequestMapping(value = "/oleEResourceChangeDashBoardController")
31
32 public class OLEEResourceChangeDashBoardController extends UifControllerBase {
33
34 private OLEEResourceSearchService oleEResourceSearchService = null;
35
36 private OLEEResourceHelperService oleeResourceHelperService = null;
37
38 private BusinessObjectService businessObjectService = null;
39
40 public OLEEResourceSearchService getOleEResourceSearchService() {
41 if (oleEResourceSearchService == null) {
42 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
43 }
44 return oleEResourceSearchService;
45 }
46 public OLEEResourceHelperService getOleeResourceHelperService() {
47 if(oleeResourceHelperService == null) {
48 oleeResourceHelperService = new OLEEResourceHelperService();
49 }
50 return oleeResourceHelperService;
51 }
52
53 public BusinessObjectService getBusinessObjectService() {
54 if (businessObjectService == null) {
55 businessObjectService = KRADServiceLocator.getBusinessObjectService();
56 }
57 return businessObjectService;
58 }
59
60 @Override
61 protected UifFormBase createInitialForm(HttpServletRequest request) {
62 return new OLEEResourceChangeDashboardForm();
63 }
64
65
66
67
68
69
70
71
72 @Override
73 @RequestMapping(params = "methodToCall=start")
74 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form ,BindingResult result,
75 HttpServletRequest request, HttpServletResponse response) {
76 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
77 List<OleGokbReview> gokbReviewList = (List<OleGokbReview>) KRADServiceLocator.getBusinessObjectService().findAll(OleGokbReview.class);
78 List<OleGokbChangeLog> oleGokbChangeLogs = (List<OleGokbChangeLog>) getBusinessObjectService().findAll(OleGokbChangeLog.class);
79 eResourceChangeDashboardForm.setOleGokbChangeLogs(oleGokbChangeLogs);
80 eResourceChangeDashboardForm.setOleGokbReviewList(gokbReviewList);
81 eResourceChangeDashboardForm.setOleGokbReviews(gokbReviewList);
82 List<String> dates = new ArrayList<>();
83 List<String> detailList = new ArrayList<>();
84 List<String> types = new ArrayList<>();
85 List<String> eresources = new ArrayList<>();
86 List<String> origins = new ArrayList<>();
87 List<String> titles = new ArrayList<>();
88 for(OleGokbReview oleGokbReview : eResourceChangeDashboardForm.getOleGokbReviewList()){
89 String date = oleGokbReview.getReviewDate().toString();
90 String details = oleGokbReview.getDetails();
91 String type = oleGokbReview.getType();
92 String resource = oleGokbReview.getOleERSIdentifier();
93
94
95 if (StringUtils.isNotEmpty(date))
96 dates.add(date);
97 if (StringUtils.isNotEmpty(type))
98 types.add(type);
99 if (StringUtils.isNotEmpty(details))
100 detailList.add(details);
101 if(StringUtils.isNotEmpty(resource))
102 eresources.add(resource);
103
104
105
106
107 }
108 eResourceChangeDashboardForm.setDate(dates);
109 eResourceChangeDashboardForm.setType(types);
110 eResourceChangeDashboardForm.setDetail(detailList);
111 eResourceChangeDashboardForm.setEresource(eresources);
112 eResourceChangeDashboardForm.setOrigin(origins);
113 eResourceChangeDashboardForm.setTitle(titles);
114 return super.start(eResourceChangeDashboardForm, result, request, response);
115 }
116
117
118 @RequestMapping(params = "methodToCall=submit")
119 public ModelAndView submit(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
120 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
121 List<OleGokbReview> oleGokbReviews = eResourceChangeDashboardForm.getOleGokbReviews();
122 ListIterator<OleGokbReview> oleGokbReviewListIterator = oleGokbReviews.listIterator();
123 while (oleGokbReviewListIterator.hasNext()){
124 OleGokbReview oleGokbReview = oleGokbReviewListIterator.next();
125 OLEEResourceRecordDocument oleeResourceRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, oleGokbReview.getOleERSIdentifier());
126 if(oleGokbReview.isApprove()){
127 if(oleGokbReview.getOleERSIdentifier()!=null){
128 List<OleGokbTipp> oleGokbTipps = new ArrayList<>();
129 OleGokbTipp oleGokbTipp = getBusinessObjectService().findBySinglePrimaryKey(OleGokbTipp.class, oleGokbReview.getGokbTippId());
130 oleGokbTipps.add(oleGokbTipp);
131 getOleeResourceHelperService().addTippToEresource(oleeResourceRecordDocument, oleGokbTipps, "");
132 createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(), "New E-Holdings", "E-Holdings added to OLE");
133 }
134 }
135 if(oleGokbReview.isClear()){
136 OleGokbChangeLog oleGokbChangeLog = createChangeLog(oleeResourceRecordDocument.getOleERSIdentifier(),oleGokbReview.getType(), oleGokbReview.getDetails());
137 getBusinessObjectService().delete(oleGokbReview);
138 oleGokbReviewListIterator.remove();
139 eResourceChangeDashboardForm.getOleGokbChangeLogs().add(oleGokbChangeLog);
140 }
141 }
142 return getUIFModelAndView(eResourceChangeDashboardForm);
143 }
144
145 private OleGokbChangeLog createChangeLog(String eResId, String type, String details){
146 OleGokbChangeLog oleGokbChangeLog = new OleGokbChangeLog();
147 oleGokbChangeLog.setType(type);
148 oleGokbChangeLog.setDetails(details);
149 oleGokbChangeLog.setOleERSIdentifier(eResId);
150 oleGokbChangeLog.setChangeLogDate(new Timestamp(System.currentTimeMillis()));
151 oleGokbChangeLog.setOrigin("Manual");
152 getBusinessObjectService().save(oleGokbChangeLog);
153 return oleGokbChangeLog;
154 }
155
156
157 @RequestMapping(params = "methodToCall=cancel")
158 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
159 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
160 return super.navigate(eResourceChangeDashboardForm, result, request, response);
161 }
162
163
164
165
166
167
168
169
170
171
172 @RequestMapping(params = "methodToCall=filterResults")
173 public ModelAndView filterResults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
174 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
175 String selectedDate = eResourceChangeDashboardForm.getSelectedDate();
176 String selectedDetails = eResourceChangeDashboardForm.getSelectedDetails();
177 String selectedType = eResourceChangeDashboardForm.getSelectedType();
178 String selectedEresource = eResourceChangeDashboardForm.getSelectedEresource();
179
180
181 List<OleGokbReview> gokbReviewList = new ArrayList<>();
182 List<OleGokbReview> oleGokbReviews = eResourceChangeDashboardForm.getOleGokbReviewList();
183 for (OleGokbReview oleGokbReview : oleGokbReviews) {
184 if (StringUtils.isNotEmpty(oleGokbReview.getReviewDate().toString()) && oleGokbReview.getReviewDate().toString().equalsIgnoreCase(selectedDate)) {
185 gokbReviewList.add(oleGokbReview);
186 eResourceChangeDashboardForm.setSelectedDate("");
187 eResourceChangeDashboardForm.setOleGokbReviews(gokbReviewList);
188 }
189 else if (StringUtils.isNotEmpty(oleGokbReview.getDetails()) && oleGokbReview.getDetails().equalsIgnoreCase(selectedDetails)) {
190 gokbReviewList.add(oleGokbReview);
191 eResourceChangeDashboardForm.setSelectedDetails("");
192 eResourceChangeDashboardForm.setOleGokbReviews(gokbReviewList);
193 }
194 else if (StringUtils.isNotEmpty(oleGokbReview.getType()) && oleGokbReview.getType().equalsIgnoreCase(selectedType)) {
195 gokbReviewList.add(oleGokbReview);
196 eResourceChangeDashboardForm.setSelectedType("");
197 eResourceChangeDashboardForm.setOleGokbReviews(gokbReviewList);
198 }
199 else if(StringUtils.isNotEmpty(oleGokbReview.getOleERSIdentifier()) && oleGokbReview.getOleERSIdentifier().equalsIgnoreCase(selectedEresource)) {
200 gokbReviewList.add(oleGokbReview);
201 eResourceChangeDashboardForm.setSelectedEresource("");
202 eResourceChangeDashboardForm.setOleGokbReviews(gokbReviewList);
203 }
204 }
205 return getUIFModelAndView(eResourceChangeDashboardForm);
206 }
207
208
209 @RequestMapping(params = "methodToCall=clear")
210 public ModelAndView clear(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
211 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
212 eResourceChangeDashboardForm.setSelectedEresource("");
213 eResourceChangeDashboardForm.setSelectedDate("");
214 eResourceChangeDashboardForm.setSelectedType("");
215 eResourceChangeDashboardForm.setSelectedDetails("");
216 eResourceChangeDashboardForm.setSelectedOrigin("");
217 return getUIFModelAndView(eResourceChangeDashboardForm);
218 }
219
220 @RequestMapping(params = "methodToCall=selectTab")
221 public ModelAndView selectTab(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
222 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
223 return super.navigate(eResourceChangeDashboardForm, result, request, response);
224 }
225
226 @RequestMapping(params = "methodToCall=approve")
227 public ModelAndView approve(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
228 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
229
230 return super.navigate(eResourceChangeDashboardForm, result, request, response);
231 }
232
233 @RequestMapping(params = "methodToCall=archive")
234 public ModelAndView archive(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) {
235 OLEEResourceChangeDashboardForm eResourceChangeDashboardForm = (OLEEResourceChangeDashboardForm)form;
236 if(eResourceChangeDashboardForm.getArchivedDate()!=null){
237 List<OleGokbChangeLog> oleGokbChangeLogs = (List<OleGokbChangeLog>)getBusinessObjectService().findAll(OleGokbChangeLog.class);
238 for(OleGokbChangeLog gokbChangeLog :oleGokbChangeLogs){
239 if(gokbChangeLog.getChangeLogDate().before(eResourceChangeDashboardForm.getArchivedDate())){
240 OleGokbArchive archive = new OleGokbArchive();
241 archive.setOleERSIdentifier(gokbChangeLog.getOleERSIdentifier());
242 archive.setOrigin(gokbChangeLog.getOrigin());
243 archive.setDetails(gokbChangeLog.getDetails());
244 archive.setGokbTippId(gokbChangeLog.getGokbTippId());
245 archive.setType(gokbChangeLog.getType());
246 archive.setArchivedDate(new Timestamp(System.currentTimeMillis()));
247 getBusinessObjectService().save(archive);
248 getBusinessObjectService().delete(gokbChangeLog);
249 }
250 }
251 }
252 return getUIFModelAndView(eResourceChangeDashboardForm);
253 }
254
255 }