1 package org.kuali.ole.select.controller;
2
3 import org.apache.commons.lang.StringUtils;
4 import org.apache.log4j.Logger;
5 import org.kuali.ole.OLEConstants;
6 import org.kuali.ole.alert.controller.OleTransactionalDocumentControllerBase;
7 import org.kuali.ole.batch.bo.OLEBatchProcessProfileBo;
8 import org.kuali.ole.coa.businessobject.*;
9 import org.kuali.ole.docstore.common.client.DocstoreClientLocator;
10 import org.kuali.ole.docstore.common.document.*;
11 import org.kuali.ole.docstore.common.document.content.bib.marc.BibMarcRecord;
12 import org.kuali.ole.docstore.common.document.content.instance.OleHoldings;
13 import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor;
14 import org.kuali.ole.gl.OJBUtility;
15 import org.kuali.ole.module.purap.PurapConstants;
16 import org.kuali.ole.module.purap.PurapKeyConstants;
17 import org.kuali.ole.module.purap.businessobject.PurchaseOrderType;
18 import org.kuali.ole.module.purap.document.service.RequisitionService;
19 import org.kuali.ole.select.bo.OLEEResourceOrderRecord;
20 import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService;
21 import org.kuali.ole.select.bo.*;
22 import org.kuali.ole.select.businessobject.OleCopy;
23 import org.kuali.ole.select.businessobject.OleDocstoreResponse;
24 import org.kuali.ole.select.document.*;
25 import org.kuali.ole.select.bo.OLECreatePO;
26 import org.kuali.ole.select.form.OLEEResourceRecordForm;
27 import org.kuali.ole.select.gokb.*;
28 import org.kuali.ole.select.service.OLEAccessActivationService;
29 import org.kuali.ole.select.service.OleReqPOCreateDocumentService;
30 import org.kuali.ole.select.service.impl.OLEAccessActivationServiceImpl;
31 import org.kuali.ole.service.*;
32 import org.kuali.ole.service.impl.OLEEResourceSearchServiceImpl;
33 import org.kuali.ole.sys.context.SpringContext;
34 import org.kuali.rice.core.api.config.property.ConfigContext;
35 import org.kuali.rice.core.api.config.property.ConfigurationService;
36 import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader;
37 import org.kuali.rice.core.api.util.RiceKeyConstants;
38 import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator;
39 import org.kuali.rice.coreservice.api.parameter.Parameter;
40 import org.kuali.rice.coreservice.api.parameter.ParameterKey;
41 import org.kuali.rice.kew.actionitem.ActionItem;
42 import org.kuali.rice.kew.actionrequest.ActionRequestValue;
43 import org.kuali.rice.kew.actionrequest.service.ActionRequestService;
44 import org.kuali.rice.kew.actiontaken.ActionTakenValue;
45 import org.kuali.rice.kew.api.KewApiServiceLocator;
46 import org.kuali.rice.kew.api.exception.WorkflowException;
47 import org.kuali.rice.kew.routeheader.DocumentRouteHeaderValue;
48 import org.kuali.rice.kew.service.KEWServiceLocator;
49 import org.kuali.rice.kim.api.identity.IdentityService;
50 import org.kuali.rice.kim.api.identity.Person;
51 import org.kuali.rice.kim.api.identity.PersonService;
52 import org.kuali.rice.kim.api.identity.principal.Principal;
53 import org.kuali.rice.kim.api.role.Role;
54 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
55 import org.kuali.rice.krad.bo.AdHocRoutePerson;
56 import org.kuali.rice.krad.bo.AdHocRouteRecipient;
57 import org.kuali.rice.krad.bo.DocumentHeader;
58 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
59 import org.kuali.rice.krad.maintenance.MaintenanceLock;
60 import org.kuali.rice.krad.service.*;
61 import org.kuali.rice.krad.service.impl.DocumentHeaderServiceImpl;
62 import org.kuali.rice.krad.uif.UifParameters;
63 import org.kuali.rice.krad.uif.container.CollectionGroup;
64 import org.kuali.rice.krad.uif.util.ObjectPropertyUtils;
65 import org.kuali.rice.krad.uif.view.View;
66 import org.kuali.rice.krad.util.GlobalVariables;
67 import org.kuali.rice.krad.util.KRADConstants;
68 import org.kuali.rice.krad.util.ObjectUtils;
69 import org.kuali.rice.krad.web.controller.TransactionalDocumentControllerBase;
70 import org.kuali.rice.krad.web.form.DocumentFormBase;
71 import org.kuali.rice.krad.web.form.TransactionalDocumentFormBase;
72 import org.kuali.rice.krad.web.form.UifFormBase;
73 import org.springframework.stereotype.Controller;
74 import org.springframework.validation.BindingResult;
75 import org.springframework.web.bind.annotation.ModelAttribute;
76 import org.springframework.web.bind.annotation.RequestMapping;
77 import org.springframework.web.bind.annotation.RequestMethod;
78 import org.springframework.web.servlet.ModelAndView;
79
80 import javax.servlet.http.HttpServletRequest;
81 import javax.servlet.http.HttpServletResponse;
82 import javax.servlet.http.HttpSession;
83 import java.io.IOException;
84 import java.io.OutputStream;
85 import java.sql.Timestamp;
86 import java.util.*;
87 import java.sql.Date;
88
89
90
91
92
93
94
95
96 @Controller
97 @RequestMapping(value = "/oleERSController")
98 public class OLEEResourceRecordController extends OleTransactionalDocumentControllerBase {
99
100
101
102
103
104 private static final Logger LOG = Logger.getLogger(OLEEResourceRecordController.class);
105
106 private OleLicenseRequestWebService oleLicenseRequestWebService = null;
107 private KualiRuleService kualiRuleService;
108 private BusinessObjectService businessObjectService;
109 private OLEEResourceSearchService oleEResourceSearchService = null;
110 private DocstoreClientLocator docstoreClientLocator;
111 private OLEEResourceHelperService oleeResourceHelperService = new OLEEResourceHelperService();
112 private OleReqPOCreateDocumentService oleReqPOCreateDocumentService;
113 private RequisitionCreateDocumentService requisitionCreateDocumentService;
114 private OLEAccessActivationService oleAccessActivationService;
115
116 public OLEEResourceHelperService getOleeResourceHelperService() {
117 if (oleeResourceHelperService == null) {
118 oleeResourceHelperService = new OLEEResourceHelperService();
119 }
120 return oleeResourceHelperService;
121 }
122
123 public DocstoreClientLocator getDocstoreClientLocator() {
124 if (docstoreClientLocator == null) {
125 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class);
126 }
127 return docstoreClientLocator;
128 }
129
130 public OleReqPOCreateDocumentService getOleReqPOCreateDocumentService() {
131 if (oleReqPOCreateDocumentService == null) {
132 oleReqPOCreateDocumentService = SpringContext.getBean(OleReqPOCreateDocumentService.class);
133 }
134 return oleReqPOCreateDocumentService;
135 }
136
137 public RequisitionCreateDocumentService getRequisitionCreateDocumentService() {
138 if (requisitionCreateDocumentService == null) {
139 requisitionCreateDocumentService = SpringContext.getBean(RequisitionCreateDocumentService.class);
140 }
141 return requisitionCreateDocumentService;
142 }
143
144 public OLEAccessActivationService getOleAccessActivationService() {
145 if(oleAccessActivationService == null){
146 oleAccessActivationService = new OLEAccessActivationServiceImpl();
147 }
148 return oleAccessActivationService;
149 }
150
151
152
153
154
155
156 @Override
157 protected TransactionalDocumentFormBase createInitialForm(HttpServletRequest request) {
158 OLEEResourceRecordForm oleeResourceRecordForm = new OLEEResourceRecordForm();
159 oleeResourceRecordForm.setStatusDate(new Date(System.currentTimeMillis()).toString());
160 oleeResourceRecordForm.setDocumentDescription(OLEConstants.OLEEResourceRecord.NEW_E_RESOURCE_REC);
161 oleeResourceRecordForm.setUrl(ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + "/ole-kr-krad/oleERSController?viewId=OLEEResourceRecordView&methodToCall=docHandler&command=initiate&documentClass=org.kuali.ole.select.document.OLEEResourceRecordDocument");
162 return oleeResourceRecordForm;
163 }
164
165
166 @Override
167 public ModelAndView docHandler(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
168 HttpServletRequest request, HttpServletResponse response) throws Exception {
169 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
170 oleeResourceRecordForm.setSearchUrl(ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + "/ole-kr-krad/oleERSController?viewId=OLEEResourceSearchView&methodToCall=start");
171
172 request.getSession().setAttribute("formKeyValue", oleeResourceRecordForm.getFormKey());
173
174 ModelAndView modelAndView = super.docHandler(oleeResourceRecordForm, result, request, response);
175 OLEEResourceRecordForm kualiForm = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm");
176 String backDoorUser = request.getParameter("backdoorId");
177 if (backDoorUser == null) {
178 backDoorUser = GlobalVariables.getUserSession().getPrincipalId();
179 } else {
180 if (backDoorUser.contains("=")) {
181 backDoorUser = backDoorUser.split("=")[1];
182 }
183 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(backDoorUser);
184 backDoorUser = person.getPrincipalId();
185 }
186
187
188 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) kualiForm.getDocument();
189 List<ActionItem> actionItems = (List<ActionItem>) KEWServiceLocator.getActionListService().findByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
190 if (actionItems != null && actionItems.size() > 0) {
191 for (ActionItem actionItem : actionItems) {
192 if (backDoorUser.equals(actionItem.getPrincipalId())) {
193 oleeResourceRecordForm.setCanApprove(true);
194 }
195 }
196 }
197 getOleEResourceSearchService().getPOInvoiceForERS(oleeResourceRecordDocument);
198
199
200 if (oleEResourceSearchService != null) {
201 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument);
202 }
203 if (oleeResourceRecordDocument.getOleERSIdentifier() == null) {
204 String noticePeriod = oleEResourceSearchService.getParameter("NOTICE_PERIOD", OLEConstants.ERESOURCE_CMPNT);
205 String alertEnabled = oleEResourceSearchService.getParameter("ALERT_ENABLED", OLEConstants.ERESOURCE_CMPNT);
206 String user = oleEResourceSearchService.getParameter("USER", OLEConstants.ERESOURCE_CMPNT);
207 oleeResourceRecordDocument.setRenewalNoticePeriod(noticePeriod);
208 if (alertEnabled.equalsIgnoreCase("Y")) {
209 oleeResourceRecordDocument.setRenewalAlertEnabled(true);
210 } else {
211 oleeResourceRecordDocument.setRenewalAlertEnabled(false);
212 }
213 oleeResourceRecordDocument.setRecipientId(user);
214 }
215 return modelAndView;
216 }
217
218
219
220
221
222
223
224 @Override
225 @RequestMapping(params = "methodToCall=start")
226 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
227 HttpServletRequest request, HttpServletResponse response) {
228 LOG.debug("Start -- Start Method of OlePatronRecordForm");
229 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
230 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument();
231 oleeResourceRecordDocument.setStatusDate(new Date(System.currentTimeMillis()).toString());
232 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList();
233 for (OLESearchCondition oleSearchCondition : oleSearchConditions) {
234 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND);
235 }
236 return super.start(oleeResourceRecordForm, result, request, response);
237 }
238
239
240
241
242
243
244
245
246
247
248 @RequestMapping(params = "methodToCall=addEventLogLine")
249 public ModelAndView addEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
250 HttpServletRequest request, HttpServletResponse response) {
251 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
252 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
253
254
255
256 CollectionGroup collectionGroup = uifForm.getPostedView().getViewIndex().getCollectionGroupByPath(
257 selectedCollectionPath);
258 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
259 Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath);
260 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
261 OLEEResourceEventLog oleERSEventLog = (OLEEResourceEventLog) eventObject;
262 if (!getOleEResourceSearchService().addAttachmentFile(oleERSEventLog, "OLEEResourceRecordView-EventLogSection")) {
263 return super.navigate(form, result, request, response);
264 }
265
266 if (oleERSEventLog.getLogTypeName().equalsIgnoreCase("Event")) {
267 oleERSEventLog.setProblemTypeId(null);
268 oleERSEventLog.setEventStatus(null);
269 oleERSEventLog.setEventResolvedDate(null);
270 oleERSEventLog.setEventResolution(null);
271 } else if (oleERSEventLog.getLogTypeName().equalsIgnoreCase("Problem")) {
272 oleERSEventLog.setEventTypeId(null);
273 }
274 oleERSEventLog.setCurrentTimeStamp();
275 oleERSEventLog.setOleERSIdentifier(oleeResourceRecordDocument.getDocumentNumber());
276 oleERSEventLog.setSaveFlag(true);
277 return addLine(uifForm, result, request, response);
278 }
279
280
281
282
283
284
285
286
287
288
289 @RequestMapping(params = "methodToCall=deleteEventLogLine")
290 public ModelAndView deleteEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
291 HttpServletRequest request, HttpServletResponse response) {
292 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
293 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
294 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
295 OLEEResourceEventLog oleERSEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(Integer.parseInt(selectedLineIndex));
296
297 return deleteLine(form, result, request, response);
298 }
299
300 @RequestMapping(params = "methodToCall=editEventLogLine")
301 public ModelAndView editEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
302 HttpServletRequest request, HttpServletResponse response) {
303 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
304 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
305 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
306 OLEEResourceEventLog oleERSEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(Integer.parseInt(selectedLineIndex));
307 oleERSEventLog.setSaveFlag(false);
308 return super.navigate(form, result, request, response);
309 }
310
311 @RequestMapping(params = "methodToCall=saveEvent")
312 public ModelAndView saveEvent(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
313 HttpServletRequest request, HttpServletResponse response) {
314 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
315 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
316 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
317 OLEEResourceEventLog oleERSEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(Integer.parseInt(selectedLineIndex));
318 return super.navigate(form, result, request, response);
319 }
320
321
322
323
324
325
326
327
328
329
330 @RequestMapping(params = "methodToCall=performCreateLicenseRequest")
331 public ModelAndView performCreateLicenseRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
332 HttpServletRequest request, HttpServletResponse response) {
333 LOG.debug("performCreateLicenseRequest method starts");
334 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
335 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument();
336 OleLicenseRequestBo oleLicenseRequestBo = getOleLicenseRequestService().createLicenseRequest(
337 oleeResourceRecordDocument.getDocumentNumber(), null);
338 OLEEResourceLicense oleeResourceLicense = new OLEEResourceLicense();
339 oleeResourceLicense.setLicenseDocumentNumber(oleLicenseRequestBo.getLicenseDocumentNumber());
340 oleeResourceLicense.setDocumentRouteHeaderValue(oleLicenseRequestBo.getDocumentRouteHeaderValue());
341
342
343
344
345
346
347
348 List<OLEEResourceInstance> listOfERInstances = oleeResourceRecordDocument.getOleERSInstances();
349 List<OleLicenseRequestItemTitle> oleLicenseRequestItemTitles = new ArrayList<>();
350 for (OLEEResourceInstance oleeResourceInstance : listOfERInstances) {
351 OleLicenseRequestItemTitle oleLicenseRequestItemTitle = new OleLicenseRequestItemTitle();
352 oleLicenseRequestItemTitle.setItemUUID(oleeResourceInstance.getBibId());
353 oleLicenseRequestItemTitle.setOleLicenseRequestId(oleLicenseRequestBo.getOleLicenseRequestId());
354 oleLicenseRequestItemTitle.setOleLicenseRequestBo(oleLicenseRequestBo);
355 oleLicenseRequestItemTitles.add(oleLicenseRequestItemTitle);
356 }
357 oleLicenseRequestBo.setOleLicenseRequestItemTitles(oleLicenseRequestItemTitles);
358 oleeResourceLicense.setOleLicenseRequestBo(oleLicenseRequestBo);
359 oleeResourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense);
360
361
362 return getUIFModelAndView(oleeResourceRecordForm);
363 }
364
365
366
367
368
369
370
371 @Override
372 @RequestMapping(params = "methodToCall=save")
373 public ModelAndView save(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
374 HttpServletRequest request, HttpServletResponse response) throws Exception {
375 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
376 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
377 String eResId = oleeResourceRecordDocument.getOleERSIdentifier();
378 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
379 if (oleeResourceRecordDocument.getTitle() != null) {
380 if (oleeResourceRecordDocument.getTitle().length() < 40) {
381 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
382 } else {
383 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
384 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
385 }
386 }
387 HttpSession session = request.getSession();
388 if (session.getAttribute("createChildEResource") != null) {
389 ModelAndView modelAndView = super.save(oleERSform, result, request, response);
390 oleERSform = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm");
391 oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
392 session.removeAttribute("createChildEResource");
393 String oleeResourceInstancesIdentifier = (String) session.getAttribute("oleeResourceInstancesIdentifier");
394 String[] identifiers = oleeResourceInstancesIdentifier.split(",");
395 List<OLEEResourceInstance> ersInstances = new ArrayList<>();
396 for (String identifier : identifiers) {
397 Map<String, String> criteriaMap = new HashMap<>();
398 criteriaMap.put(OLEConstants.INSTANCE_ID, identifier);
399 List<OLEEResourceInstance> instances = (List<OLEEResourceInstance>) getBusinessObjectService().findMatching(OLEEResourceInstance.class, criteriaMap);
400 ersInstances.add(instances.get(0));
401 criteriaMap = new HashMap<>();
402 criteriaMap.put(OLEConstants.INSTANCE_ID, identifier);
403 criteriaMap.put("oleERSIdentifier", (String) session.getAttribute("oleERSIdentifier"));
404 getBusinessObjectService().deleteMatching(OLEEResourceInstance.class, criteriaMap);
405 OLEEditorResponse oleEditorResponse = new OLEEditorResponse();
406 oleEditorResponse.setLinkedInstanceId(identifier);
407 oleEditorResponse.setTokenId(oleeResourceRecordDocument.getDocumentNumber());
408 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>();
409 oleEditorResponseMap.put(oleeResourceRecordDocument.getDocumentNumber(), oleEditorResponse);
410 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap);
411 String documentNumber = oleeResourceRecordDocument.getDocumentNumber();
412 oleeResourceRecordDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE);
413 try {
414 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, documentNumber);
415 } catch (Exception e) {
416 e.printStackTrace();
417 }
418 }
419 oleeResourceRecordDocument.setOleERSInstances(ersInstances);
420 String oleERSIdentifier = (String) session.getAttribute("oleERSIdentifier");
421 Map<String, String> tempId = new HashMap<String, String>();
422 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSIdentifier);
423 OLEEResourceRecordDocument parentDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
424 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
425 try {
426 parentDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(parentDocument.getDocumentNumber(), principalPerson));
427 } catch (WorkflowException e) {
428 e.printStackTrace();
429 }
430 OLELinkedEresource linkedEresource = new OLELinkedEresource();
431
432 linkedEresource.setOleeResourceRecordDocument(oleeResourceRecordDocument);
433 linkedEresource.setRelationShipType("parent");
434 linkedEresource.setLinkedERSIdentifier(oleERSIdentifier);
435
436
437 oleeResourceRecordDocument.getOleLinkedEresources().add(linkedEresource);
438 OLELinkedEresource eResource = new OLELinkedEresource();
439 eResource.setOleeResourceRecordDocument(oleeResourceRecordDocument);
440 eResource.setRelationShipType("child");
441 eResource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
442
443
444 parentDocument.getOleLinkedEresources().add(eResource);
445 oleEResourceSearchService.getPOInvoiceForERS(parentDocument);
446 KRADServiceLocatorWeb.getDocumentService().updateDocument(parentDocument);
447 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument);
448 KRADServiceLocatorWeb.getDocumentService().updateDocument(oleeResourceRecordDocument);
449 return super.reload(oleERSform, result, request, response);
450 }
451
452
453
454
455
456
457
458
459
460
461
462
463 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
464 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
465 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
466 List<String> instanceId = new ArrayList<String>();
467
468
469
470
471
472
473 boolean flag = false;
474 boolean datesFlag = true;
475 flag = getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
476 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument, oleERSform);
477 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument, oleERSform);
478 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument, oleERSform);
479 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument, oleERSform);
480 if (flag) {
481 return getUIFModelAndView(oleERSform);
482 }
483 if (!datesFlag) {
484 return getUIFModelAndView(oleERSform);
485 }
486 String fileName = oleeResourceRecordDocument.getDocumentNumber();
487 if (oleERSform.isCreateInstance()) {
488 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
489 oleERSform.setCreateInstance(false);
490 }
491 oleERSform.setBibId(null);
492 oleERSform.setInstanceId(null);
493 oleERSform.setLinkInstance(false);
494 boolean titleChange = false;
495 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
496 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
497 Map<String, String> tempId = new HashMap<String, String>();
498 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
499 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
500 if (!tempDocument.getTitle().equalsIgnoreCase(oleeResourceRecordDocument.getTitle())){
501 titleChange = true;
502 }
503 int instancesSize = tempDocument.getOleERSInstances().size();
504 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
505 if (!oleERSform.isDefaultDatesFlag() && oleERSform.getPageId() != null && oleERSform.getPageId().equalsIgnoreCase("OLEEResourceRecordView-E-ResourceInstanceTab")) {
506 if (tempDocument.iseInstanceFlag() && instancesSize >= instanceSize && !oleERSform.isRemoveInstanceFlag()) {
507 try {
508 super.reload(oleERSform, result, request, response);
509 } catch (Exception e) {
510 LOG.error("exception while reloading the e-resource document" + e.getMessage());
511 throw new RuntimeException("exception while reloading the e-resource document", e);
512 }
513 }
514 }
515 oleERSform.setRemoveInstanceFlag(false);
516 oleERSform.setDefaultDatesFlag(false);
517 }
518 getOleEResourceSearchService().processEventAttachments(oleeResourceRecordDocument.getOleERSEventLogs());
519 if (oleeResourceRecordDocument.getCurrentSubscriptionEndDate() != null) {
520 if (oleeResourceRecordDocument.isRenewalAlertEnabled()) {
521 if (oleeResourceRecordDocument.getRecipientId() == null) {
522 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.RECIPIENT_ID, OLEConstants.OLEEResourceRecord.ERROR_RECIPIENT_ID);
523 return getUIFModelAndView(oleERSform);
524 }
525 }
526 }
527 ModelAndView modelAndView = super.save(oleERSform, result, request, response);
528 OLEEResourceRecordForm kualiForm = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm");
529 OLEEResourceRecordDocument resourceRecordDocument = (OLEEResourceRecordDocument) kualiForm.getDocument();
530 resourceRecordDocument.geteRSInstances().clear();
531 resourceRecordDocument.geteRSInstances().addAll(resourceRecordDocument.getOleERSInstances());
532 for (OLELinkedEresource oleLinkedEresource : resourceRecordDocument.getOleLinkedEresources()) {
533 if (oleLinkedEresource.getRelationShipType().equalsIgnoreCase("child")) {
534
535 if (oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances() != null) {
536 resourceRecordDocument.geteRSInstances().addAll(oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances());
537 }
538 for (OLEEResourceLicense oleeResourceLicense : oleLinkedEresource.getOleeResourceRecordDocument().getOleERSLicenseRequests()) {
539 resourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense);
540 }
541 }
542 }
543 getOleEResourceSearchService().getPOInvoiceForERS(oleeResourceRecordDocument);
544 getOleeResourceHelperService().createOrUpdateAccessWorkflow(oleeResourceRecordDocument, titleChange);
545
546
547
548
549
550
551
552 return super.save(oleERSform, result, request, response);
553 }
554
555
556
557
558
559
560
561 @RequestMapping(params = "methodToCall=route")
562 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
563 HttpServletRequest request, HttpServletResponse response) {
564 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
565 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
566 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
567 if (oleeResourceRecordDocument.getTitle().length() < 40) {
568 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
569 } else {
570 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
571 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
572 }
573 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
574 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
575 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
576 List<String> instanceId = new ArrayList<String>();
577
578
579
580
581
582
583 boolean flag = false;
584 boolean datesFlag = true;
585 flag = getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
586 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument, oleERSform);
587 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument, oleERSform);
588 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument, oleERSform);
589 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument, oleERSform);
590 if (flag) {
591 return getUIFModelAndView(oleERSform);
592 }
593 if (!datesFlag) {
594 return getUIFModelAndView(oleERSform);
595 }
596 String fileName = oleeResourceRecordDocument.getDocumentNumber();
597 if (oleERSform.isCreateInstance()) {
598 try {
599 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
600 } catch (Exception e) {
601 e.printStackTrace();
602 }
603 oleERSform.setCreateInstance(false);
604 }
605 oleERSform.setBibId(null);
606 oleERSform.setInstanceId(null);
607 oleERSform.setLinkInstance(false);
608 boolean titleChange = false;
609 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
610 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
611 Map<String, String> tempId = new HashMap<String, String>();
612 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
613 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
614 if (!tempDocument.getTitle().equalsIgnoreCase(oleeResourceRecordDocument.getTitle())){
615 titleChange = true;
616 }
617 int instancesSize = tempDocument.getOleERSInstances().size();
618 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
619 if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) {
620 try {
621 super.reload(oleERSform, result, request, response);
622 } catch (Exception e) {
623 LOG.error("Exception while reloading the e-resource document" + e.getMessage());
624 }
625 }
626 oleERSform.setRemoveInstanceFlag(false);
627 }
628 getOleEResourceSearchService().processEventAttachments(oleeResourceRecordDocument.getOleERSEventLogs());
629 getOleeResourceHelperService().createOrUpdateAccessWorkflow(oleeResourceRecordDocument, titleChange);
630 return super.route(oleERSform, result, request, response);
631 }
632
633
634
635
636
637
638
639 @Override
640 @RequestMapping(params = "methodToCall=approve")
641 public ModelAndView approve(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
642 HttpServletRequest request, HttpServletResponse response) throws Exception {
643 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
644 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
645 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString());
646 if (oleeResourceRecordDocument.getTitle().length() < 40) {
647 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle());
648 } else {
649 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39);
650 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription);
651 }
652 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes();
653 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
654 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes();
655 List<String> instanceId = new ArrayList<String>();
656
657
658
659
660
661
662 boolean flag = false;
663 boolean datesFlag = true;
664 flag = getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument);
665 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument, oleERSform);
666 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument, oleERSform);
667 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument, oleERSform);
668 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument, oleERSform);
669 if (flag) {
670 return getUIFModelAndView(oleERSform);
671 }
672 if (!datesFlag) {
673 return getUIFModelAndView(oleERSform);
674 }
675 String fileName = oleeResourceRecordDocument.getDocumentNumber();
676 if (oleERSform.isCreateInstance()) {
677 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName);
678 oleERSform.setCreateInstance(false);
679 }
680 oleERSform.setBibId(null);
681 oleERSform.setInstanceId(null);
682 oleERSform.setLinkInstance(false);
683 boolean titleChange = false;
684 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) {
685 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument);
686 Map<String, String> tempId = new HashMap<String, String>();
687 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier());
688 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
689 if (!tempDocument.getTitle().equalsIgnoreCase(oleeResourceRecordDocument.getTitle())){
690 titleChange = true;
691 }
692 int instancesSize = tempDocument.getOleERSInstances().size();
693 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size();
694 if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) {
695 try {
696 super.reload(oleERSform, result, request, response);
697 } catch (Exception e) {
698 LOG.error("Exception while reloading the e-resource document" + e.getMessage());
699 }
700 }
701 oleERSform.setRemoveInstanceFlag(false);
702 }
703 getOleEResourceSearchService().processEventAttachments(oleeResourceRecordDocument.getOleERSEventLogs());
704 getOleeResourceHelperService().createOrUpdateAccessWorkflow(oleeResourceRecordDocument, titleChange);
705 super.approve(oleERSform, result, request, response);
706 if(oleeResourceRecordDocument.getDocumentHeader().getWorkflowDocument().getStatus().getCode().equals("F")){
707 DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(oleeResourceRecordDocument.getDocumentNumber());
708 documentBo.setDocRouteStatus("S");
709 KEWServiceLocator.getRouteHeaderService().saveRouteHeader(documentBo);
710 }
711 return getUIFModelAndView(oleERSform);
712 }
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747 @RequestMapping(params = "methodToCall=createInstance")
748 public ModelAndView createInstance(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
749 HttpServletRequest request, HttpServletResponse response) {
750 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
751 oleERSform.setSelectFlag(true);
752 oleERSform.setLinkInstance(false);
753 oleERSform.setCreateInstance(true);
754 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
755 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
756 }
757
758
759
760
761
762
763
764 @RequestMapping(params = "methodToCall=closePopup")
765 public ModelAndView closePopup(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
766 HttpServletRequest request, HttpServletResponse response) {
767 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
768 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
769 }
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=removeInstance")
804 public ModelAndView removeInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
805 HttpServletRequest request, HttpServletResponse response) {
806
807 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) uifForm;
808 OLEEResourceRecordDocument oleEResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
809 String selectedCollectionPath = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
810
811 if (StringUtils.isBlank(selectedCollectionPath)) {
812 throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX);
813 }
814 int selectedLineIndex = -1;
815 String selectedLine = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
816 if (StringUtils.isNotBlank(selectedLine)) {
817 OLEEResourceInstance oleERSInstance = oleEResourceRecordDocument.geteRSInstances().get(Integer.parseInt(selectedLine));
818 try {
819 Holdings holdings = new EHoldings();
820 OleHoldings oleHoldings = new OleHoldings();
821 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleERSInstance.getInstanceId());
822 if (holdings instanceof EHoldings) {
823 oleHoldings = new HoldingOlemlRecordProcessor().fromXML(holdings.getContent());
824 oleHoldings.setEResourceId(null);
825 holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings));
826 getDocstoreClientLocator().getDocstoreClient().updateHoldings(holdings);
827 }
828 } catch (Exception e) {
829 LOG.error("Illegal exception while updating instance record" + e.getMessage());
830 }
831 selectedLineIndex = Integer.parseInt(selectedLine);
832 OLEEResourceEventLog oleEResourceEventLog = new OLEEResourceEventLog();
833 oleEResourceEventLog.setCurrentTimeStamp();
834 oleEResourceEventLog.setEventUser(GlobalVariables.getUserSession().getPrincipalName());
835 oleEResourceEventLog.setEventNote(oleERSInstance.getInstanceTitle() + OLEConstants.OLEEResourceRecord.INSTANCE_ID_REMOVE_NOTE + oleERSInstance.getInstanceId() + OLEConstants.OLEEResourceRecord.REMOVE_NOTE);
836
837 oleEResourceEventLog.setLogTypeId("3");
838 oleEResourceRecordDocument.getOleERSEventLogs().add(oleEResourceEventLog);
839 }
840 if (selectedLineIndex == -1) {
841 throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX);
842 }
843 oleEResourceRecordForm.setRemoveInstanceFlag(true);
844 View view = oleEResourceRecordForm.getPostedView();
845 view.getViewHelperService().processCollectionDeleteLine(view, oleEResourceRecordForm, selectedCollectionPath,
846 selectedLineIndex);
847 oleEResourceRecordDocument.getOleERSInstances().remove(selectedLineIndex);
848 return getUIFModelAndView(oleEResourceRecordForm);
849 }
850
851
852
853
854
855
856
857 public OleLicenseRequestWebService getOleLicenseRequestService() {
858 if (oleLicenseRequestWebService == null) {
859 oleLicenseRequestWebService = GlobalResourceLoader.getService(OLEConstants.OleLicenseRequest.HELPER_SERVICE);
860 }
861 return oleLicenseRequestWebService;
862 }
863
864 public KualiRuleService getKualiRuleService() {
865 if (kualiRuleService == null) {
866 kualiRuleService = GlobalResourceLoader.getService(OLEConstants.KUALI_RULE_SERVICE);
867 }
868 return kualiRuleService;
869 }
870
871 public BusinessObjectService getBusinessObjectService() {
872 if (businessObjectService == null) {
873 businessObjectService = KRADServiceLocator.getBusinessObjectService();
874 }
875 return businessObjectService;
876 }
877
878 public OLEEResourceSearchService getOleEResourceSearchService() {
879 if (oleEResourceSearchService == null) {
880 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
881 }
882 return oleEResourceSearchService;
883 }
884
885
886
887
888
889
890
891
892 @RequestMapping(params = "methodToCall=editDefaultCoverage")
893 public ModelAndView editDefaultCoverage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
894 HttpServletRequest request, HttpServletResponse response) {
895 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
896 oleERSform.setCoverageFlag(true);
897 oleERSform.setPerpetualAccessFlag(false);
898 oleERSform.setDefaultDatesFlag(true);
899 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
900 String defaultCov = oleeResourceRecordDocument.getDummyDefaultCoverage();
901 if (defaultCov != null && !defaultCov.isEmpty()) {
902 oleeResourceRecordDocument.setCovEdited(true);
903 getOleEResourceSearchService().getDefaultCovDatesToPopup(oleeResourceRecordDocument, defaultCov);
904 }
905 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
906 }
907
908
909
910
911
912
913
914 @RequestMapping(params = "methodToCall=editDefaultPerpetualAccess")
915 public ModelAndView editDefaultPerpetualAccess(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
916 HttpServletRequest request, HttpServletResponse response) {
917 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
918 oleERSform.setCoverageFlag(false);
919 oleERSform.setPerpetualAccessFlag(true);
920 oleERSform.setDefaultDatesFlag(true);
921 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
922 String defaultPerAcc = oleeResourceRecordDocument.getDummyDefaultPerpetualAccess();
923 if (defaultPerAcc != null && !defaultPerAcc.isEmpty()) {
924 oleeResourceRecordDocument.setPerAccEdited(true);
925 getOleEResourceSearchService().getDefaultPerAccDatesToPopup(oleeResourceRecordDocument, defaultPerAcc);
926 }
927 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
928 }
929
930
931
932
933
934
935
936 @RequestMapping(params = "methodToCall=closeCoverageOrPerpetualAccessDate")
937 public ModelAndView closeCoverageOrPerpetualAccessDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
938 HttpServletRequest request, HttpServletResponse response) {
939 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
940 oleERSform.setDefaultDatesFlag(false);
941 oleERSform.setDefaultCovStartDateErrorMessage(null);
942 oleERSform.setDefaultCovEndDateErrorMessage(null);
943 oleERSform.setDefaultPerAccStartDateErrorMessage(null);
944 oleERSform.setDefaultPerAccEndDateErrorMessage(null);
945 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
946 }
947
948
949
950
951
952
953
954 @RequestMapping(params = "methodToCall=refreshDefaultDate")
955 public ModelAndView refreshDefaultDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
956 HttpServletRequest request, HttpServletResponse response) {
957 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form;
958 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument();
959 if (oleERSform.isCoverageFlag()) {
960 getOleEResourceSearchService().getDefaultCovergeDate(oleeResourceRecordDocument);
961 oleERSform.setCoverageFlag(false);
962 }
963 if (oleERSform.isPerpetualAccessFlag()) {
964 getOleEResourceSearchService().getDefaultPerpetualAccessDate(oleeResourceRecordDocument);
965 oleERSform.setPerpetualAccessFlag(false);
966 }
967 return getUIFModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB);
968 }
969
970 @RequestMapping(params = "methodToCall=addMaterialType")
971 public ModelAndView addMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
972 HttpServletRequest request, HttpServletResponse response) {
973 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
974 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
975 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
976 index++;
977 List<OLEMaterialTypeList> oleMaterialTypeLists = oleeResourceRecordDocument.getOleMaterialTypes();
978 oleeResourceRecordDocument.getOleMaterialTypes().add(index, new OLEMaterialTypeList());
979 oleeResourceRecordDocument.setOleMaterialTypes(oleMaterialTypeLists);
980 form.setDocument(oleeResourceRecordDocument);
981 return super.navigate(form, result, request, response);
982 }
983
984 @RequestMapping(params = "methodToCall=removeMaterialType")
985 public ModelAndView removeMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
986 HttpServletRequest request, HttpServletResponse response) {
987 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
988 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
989 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
990 List<OLEMaterialTypeList> oleMaterialTypeLists = oleeResourceRecordDocument.getOleMaterialTypes();
991 if (oleMaterialTypeLists.size() > 1) {
992 oleMaterialTypeLists.remove(index);
993 }
994 form.setDocument(oleeResourceRecordDocument);
995 return super.navigate(form, result, request, response);
996 }
997
998 @RequestMapping(params = "methodToCall=addFormatType")
999 public ModelAndView addFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1000 HttpServletRequest request, HttpServletResponse response) {
1001 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1002 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1003 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1004 index++;
1005 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
1006 oleeResourceRecordDocument.getOleFormatTypes().add(index, new OLEFormatTypeList());
1007 oleeResourceRecordDocument.setOleFormatTypes(oleFormatTypeLists);
1008 form.setDocument(oleeResourceRecordDocument);
1009 return super.navigate(form, result, request, response);
1010 }
1011
1012 @RequestMapping(params = "methodToCall=removeFormatType")
1013 public ModelAndView removeFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1014 HttpServletRequest request, HttpServletResponse response) {
1015 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1016 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1017 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1018 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes();
1019 if (oleFormatTypeLists.size() > 1) {
1020 oleFormatTypeLists.remove(index);
1021 }
1022 form.setDocument(oleeResourceRecordDocument);
1023 return super.navigate(form, result, request, response);
1024 }
1025
1026 @RequestMapping(params = "methodToCall=addContentType")
1027 public ModelAndView addContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1028 HttpServletRequest request, HttpServletResponse response) {
1029 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1030 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1031 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1032 index++;
1033 List<OLEContentTypes> oleContentTypes = oleeResourceRecordDocument.getOleContentTypes();
1034 oleeResourceRecordDocument.getOleContentTypes().add(index, new OLEContentTypes());
1035 oleeResourceRecordDocument.setOleContentTypes(oleContentTypes);
1036 form.setDocument(oleeResourceRecordDocument);
1037 return super.navigate(form, result, request, response);
1038 }
1039
1040 @RequestMapping(params = "methodToCall=removeContentType")
1041 public ModelAndView removeContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1042 HttpServletRequest request, HttpServletResponse response) {
1043 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1044 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1045 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1046 List<OLEContentTypes> oleContentTypes = oleeResourceRecordDocument.getOleContentTypes();
1047 if (oleContentTypes.size() > 1) {
1048 oleContentTypes.remove(index);
1049 }
1050 form.setDocument(oleeResourceRecordDocument);
1051 return super.navigate(form, result, request, response);
1052 }
1053
1054
1055 @RequestMapping(params = "methodToCall=addSelectorType")
1056 public ModelAndView addSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1057 HttpServletRequest request, HttpServletResponse response) {
1058 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1059 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1060 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1061 index++;
1062 List<OLEEResourceSelector> oleeResourceSelectors = oleeResourceRecordDocument.getSelectors();
1063 oleeResourceRecordDocument.getSelectors().add(index, new OLEEResourceSelector());
1064 oleeResourceRecordDocument.setSelectors(oleeResourceSelectors);
1065 form.setDocument(oleeResourceRecordDocument);
1066 return super.navigate(form, result, request, response);
1067 }
1068
1069 @RequestMapping(params = "methodToCall=removeSelectorType")
1070 public ModelAndView removeSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1071 HttpServletRequest request, HttpServletResponse response) {
1072 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1073 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1074 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1075 List<OLEEResourceSelector> oleeResourceSelectors = oleeResourceRecordDocument.getSelectors();
1076 if (oleeResourceSelectors.size() > 1) {
1077 oleeResourceSelectors.remove(index);
1078 }
1079 form.setDocument(oleeResourceRecordDocument);
1080 return super.navigate(form, result, request, response);
1081 }
1082
1083 @RequestMapping(params = "methodToCall=addRequestorType")
1084 public ModelAndView addRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1085 HttpServletRequest request, HttpServletResponse response) {
1086 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1087 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1088 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1089 index++;
1090 List<OLEEResourceRequestor> oleeResourceRequestors = oleeResourceRecordDocument.getRequestors();
1091 oleeResourceRecordDocument.getRequestors().add(index, new OLEEResourceRequestor());
1092 oleeResourceRecordDocument.setRequestors(oleeResourceRequestors);
1093 form.setDocument(oleeResourceRecordDocument);
1094 return super.navigate(form, result, request, response);
1095 }
1096
1097 @RequestMapping(params = "methodToCall=removeRequestorType")
1098 public ModelAndView removeRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1099 HttpServletRequest request, HttpServletResponse response) {
1100 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1101 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1102 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1103 List<OLEEResourceRequestor> oleeResourceRequestors = oleeResourceRecordDocument.getRequestors();
1104 if (oleeResourceRequestors.size() > 1) {
1105 oleeResourceRequestors.remove(index);
1106 }
1107 form.setDocument(oleeResourceRecordDocument);
1108 return super.navigate(form, result, request, response);
1109 }
1110
1111 @RequestMapping(params = "methodToCall=addVariantTitle")
1112 public ModelAndView addVariantTitle(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1113 HttpServletRequest request, HttpServletResponse response) {
1114 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1115 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1116 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1117 index++;
1118 List<OLEEResourceVariantTitle> oleEResourceVariantTitleList = oleeResourceRecordDocument.getOleEResourceVariantTitleList();
1119 oleeResourceRecordDocument.getOleEResourceVariantTitleList().add(index, new OLEEResourceVariantTitle());
1120 oleeResourceRecordDocument.setOleEResourceVariantTitleList(oleEResourceVariantTitleList);
1121 form.setDocument(oleeResourceRecordDocument);
1122 return super.navigate(form, result, request, response);
1123 }
1124
1125 @RequestMapping(params = "methodToCall=removeVariantTitle")
1126 public ModelAndView removeVariantTitle(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1127 HttpServletRequest request, HttpServletResponse response) {
1128 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1129 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1130 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1131 List<OLEEResourceVariantTitle> oleEResourceVariantTitleList = oleeResourceRecordDocument.getOleEResourceVariantTitleList();
1132 if (oleEResourceVariantTitleList.size() > 1) {
1133 oleEResourceVariantTitleList.remove(index);
1134 }
1135 form.setDocument(oleeResourceRecordDocument);
1136 return super.navigate(form, result, request, response);
1137 }
1138
1139 @RequestMapping(params = "methodToCall=addRequestorSelectorType")
1140 public ModelAndView addRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1141 HttpServletRequest request, HttpServletResponse response) {
1142 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1143 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1144 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1145 index++;
1146 List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses = oleeResourceRecordDocument.getReqSelComments();
1147 oleeResourceRecordDocument.getReqSelComments().add(index, new OLEEResourceReqSelComments());
1148 oleeResourceRecordDocument.setReqSelComments(oleeResourceReqSelCommentses);
1149 form.setDocument(oleeResourceRecordDocument);
1150 return super.navigate(form, result, request, response);
1151 }
1152
1153 @RequestMapping(params = "methodToCall=removeRequestorSelectorType")
1154 public ModelAndView removeRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1155 HttpServletRequest request, HttpServletResponse response) {
1156 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1157 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1158 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1159 List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses = oleeResourceRecordDocument.getReqSelComments();
1160 if (oleeResourceReqSelCommentses.size() > 1) {
1161 oleeResourceReqSelCommentses.remove(index);
1162 }
1163 form.setDocument(oleeResourceRecordDocument);
1164 return super.navigate(form, result, request, response);
1165 }
1166
1167 @RequestMapping(params = "methodToCall=addNoteTextSection")
1168 public ModelAndView addNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1169 HttpServletRequest request, HttpServletResponse response) {
1170 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1171 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1172 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1173 index++;
1174 List<OLEEResourceNotes> oleeResourceNoteses = oleeResourceRecordDocument.getEresNotes();
1175 oleeResourceRecordDocument.getEresNotes().add(index, new OLEEResourceNotes());
1176 oleeResourceRecordDocument.setEresNotes(oleeResourceNoteses);
1177 form.setDocument(oleeResourceRecordDocument);
1178 return super.navigate(form, result, request, response);
1179 }
1180
1181 @RequestMapping(params = "methodToCall=removeNoteTextSection")
1182 public ModelAndView removeNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1183 HttpServletRequest request, HttpServletResponse response) {
1184 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1185 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1186 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
1187 List<OLEEResourceNotes> oleeResourceNoteses = oleeResourceRecordDocument.getEresNotes();
1188 if (oleeResourceNoteses.size() > 1) {
1189 oleeResourceNoteses.remove(index);
1190 }
1191 form.setDocument(oleeResourceRecordDocument);
1192 return super.navigate(form, result, request, response);
1193 }
1194
1195 @RequestMapping(params = "methodToCall=saveGokbConfig")
1196 public ModelAndView saveGokbConfig(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1197 HttpServletRequest request, HttpServletResponse response) {
1198 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1199 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1200 KRADServiceLocatorWeb.getDocumentService().updateDocument(oleeResourceRecordDocument);
1201
1202 return super.navigate(form, result, request, response);
1203 }
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216 @RequestMapping(params = "methodToCall=getEResourcesAndInstances")
1217 public ModelAndView getEResourcesAndInstances(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1218 HttpServletRequest request, HttpServletResponse response) {
1219
1220 String oleERSIdentifier = request.getParameter(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER);
1221 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
1222 oleeResourceRecordForm.setPoSuccessMessage(null);
1223 oleeResourceRecordForm.setPoErrorMessage(null);
1224 OLEEResourceRecordDocument oleeResourceRecordDocument = null;
1225 if (StringUtils.isNotBlank(oleERSIdentifier)) {
1226 Map eResMap = new HashMap();
1227 eResMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSIdentifier);
1228 oleeResourceRecordDocument = getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, eResMap);
1229 }
1230 if (oleeResourceRecordDocument != null) {
1231 String purposeId = null;
1232 String purposeType = getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.PURPOSE_TYPE, OLEConstants.ERESOURCE_CMPNT);
1233 if (StringUtils.isNotBlank(purposeType)) {
1234 Map purposeMap = new HashMap();
1235 purposeMap.put(OLEConstants.OlePurchaseOrderPurpose.PURCHASE_ORDER_PURPOSE_CODE, purposeType);
1236 List<OlePurchaseOrderPurpose> purposeList = (List<OlePurchaseOrderPurpose>) getBusinessObjectService().findMatching(OlePurchaseOrderPurpose.class, purposeMap);
1237 if (purposeList != null && purposeList.size() > 0) {
1238 OlePurchaseOrderPurpose purpose = purposeList.get(0);
1239 purposeId = purpose.getPurchaseOrderPurposeId();
1240 }
1241 }
1242 List<OLECreatePO> eResources = getOleEResourceSearchService().getEresources(oleeResourceRecordDocument, purposeId);
1243 oleeResourceRecordForm.seteResourcePOs(eResources);
1244
1245 List<OLECreatePO> instancePOs = getOleEResourceSearchService().getInstances(oleeResourceRecordDocument, purposeId);
1246 oleeResourceRecordForm.setInstancePOs(instancePOs);
1247 }
1248 return super.navigate(oleeResourceRecordForm, result, request, response);
1249 }
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262 @RequestMapping(params = "methodToCall=getPlatformForEResource")
1263 public ModelAndView getPlatformForEResource(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1264 HttpServletRequest request, HttpServletResponse response) {
1265 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1266 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1267 List<OLEPlatformAdminUrl> olePlatformAdminUrlList = new ArrayList<OLEPlatformAdminUrl>();
1268 List<String> olePlatformIdList = new ArrayList<>();
1269 List<OLEEResourceInstance> oleERSInstances = oleeResourceRecordDocument.getOleERSInstances();
1270 for (OLEEResourceInstance oleeResourceInstance : oleERSInstances) {
1271 String olePlatformId = oleeResourceInstance.getPlatformId();
1272 if (olePlatformId != null && !olePlatformIdList.contains(olePlatformId)) {
1273 olePlatformIdList.add(olePlatformId);
1274 Map platformMap = new HashMap();
1275 platformMap.put(OLEConstants.OLE_PLATFORM_ID, olePlatformId);
1276 OLEPlatformRecordDocument olePlatformRecordDocument = (OLEPlatformRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEPlatformRecordDocument.class, platformMap);
1277 List<OLEPlatformAdminUrl> platformAdminUrlList = olePlatformRecordDocument.getAdminUrls();
1278 if (platformAdminUrlList.size() > 0) {
1279 olePlatformAdminUrlList.addAll(platformAdminUrlList);
1280 }
1281 }
1282 }
1283 oleeResourceRecordDocument.setOlePlatformAdminUrlList(olePlatformAdminUrlList);
1284 return super.navigate(form, result, request, response);
1285 }
1286
1287 private String getMask() {
1288 return "******";
1289 }
1290
1291
1292 public final String getParameter(String parameterName) {
1293 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT, parameterName);
1294 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey);
1295 return parameter != null ? parameter.getValue() : null;
1296 }
1297
1298
1299 @RequestMapping(params = "methodToCall=addPOForInstance")
1300 public ModelAndView addPOForInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1301 HttpServletRequest request, HttpServletResponse response) throws CloneNotSupportedException {
1302 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1303 form.setPoSuccessMessage(null);
1304 form.setPoErrorMessage(null);
1305 int index = form.getIndex();
1306 List<OLECreatePO> inOleCreatePOs = form.getInstancePOs();
1307 OLECreatePO instancePO1 = (OLECreatePO) inOleCreatePOs.get(index).clone();
1308 index++;
1309 instancePO1.setPoId(null);
1310 inOleCreatePOs.add(index, instancePO1);
1311 return super.navigate(form, result, request, response);
1312 }
1313
1314
1315 @RequestMapping(params = "methodToCall=addPOForEResource")
1316 public ModelAndView addPOForEResource(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1317 HttpServletRequest request, HttpServletResponse response) throws CloneNotSupportedException {
1318 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1319 form.setPoSuccessMessage(null);
1320 form.setPoErrorMessage(null);
1321 int index = form.getIndex();
1322 List<OLECreatePO> eResourceCreatePOs = form.geteResourcePOs();
1323 OLECreatePO eResourcePO1 = (OLECreatePO) eResourceCreatePOs.get(index).clone();
1324 List<OLECretePOAccountingLine> oleCretePOAccountingLineList = new ArrayList<>();
1325 for (OLECretePOAccountingLine oleCretePOAccountingLine : eResourcePO1.getAccountingLines()) {
1326 oleCretePOAccountingLineList.add((OLECretePOAccountingLine) oleCretePOAccountingLine.clone());
1327 }
1328 eResourcePO1.setAccountingLines(oleCretePOAccountingLineList);
1329 index++;
1330 eResourcePO1.setPoId(null);
1331 eResourceCreatePOs.add(index, eResourcePO1);
1332 return super.navigate(form, result, request, response);
1333 }
1334
1335
1336 @RequestMapping(params = "methodToCall=synchronizeWithGokb")
1337 public ModelAndView synchronizeWithGokb(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1338 HttpServletRequest request, HttpServletResponse response) {
1339 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1340 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1341 return super.navigate(form, result, request, response);
1342 }
1343
1344
1345 @RequestMapping(params = "methodToCall=createPOs")
1346 public ModelAndView createPOs(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1347 HttpServletRequest request, HttpServletResponse response) throws Exception {
1348 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
1349 boolean selectFlag = false;
1350 oleeResourceRecordForm.setPoSuccessMessage(null);
1351 oleeResourceRecordForm.setPoErrorMessage(null);
1352 StringBuffer poSuccessMessage = new StringBuffer();
1353 StringBuffer poErrorMessage = new StringBuffer();
1354 String selectedPOType = oleeResourceRecordForm.getSelectedPOType();
1355 List<OLECreatePO> posToCreateForEholdings = new ArrayList<>();
1356 List<OLECreatePO> posToCreateForHoldings = new ArrayList<>();
1357 List<OLECreatePO> posToCreateForEResources = new ArrayList<>();
1358 List<OLECreatePO> instancePOs = oleeResourceRecordForm.getInstancePOs();
1359 List<OLECreatePO> eResourcePOs = oleeResourceRecordForm.geteResourcePOs();
1360 for (OLECreatePO instancePO : instancePOs) {
1361 if (instancePO.isSelectFlag()) {
1362 selectFlag = true;
1363 String validationMsg = getOleEResourceSearchService().validateAccountngLinesVendorAndPrice(instancePO);
1364 if (validationMsg.length() == 0) {
1365 Map createPOMap = new HashMap();
1366 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, instancePO.getOleERSIdentifier());
1367 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID, instancePO.getInstanceId());
1368 getBusinessObjectService().deleteMatching(OLECreatePO.class, createPOMap);
1369 if (StringUtils.isNotBlank(instancePO.getInstanceFlag()) && instancePO.getInstanceFlag().equalsIgnoreCase("false")) {
1370 posToCreateForEholdings.add(instancePO);
1371 } else if (StringUtils.isNotBlank(instancePO.getInstanceFlag()) && instancePO.getInstanceFlag().equalsIgnoreCase("true")) {
1372 posToCreateForHoldings.add(instancePO);
1373 }
1374 } else {
1375 poErrorMessage.append(validationMsg.toString());
1376 }
1377 }
1378 }
1379 for (OLECreatePO eResourcePo : eResourcePOs) {
1380 if (eResourcePo.isSelectFlag()) {
1381 selectFlag = true;
1382 String validationMsg = getOleEResourceSearchService().validateAccountngLinesVendorAndPrice(eResourcePo);
1383 if (validationMsg.length() == 0) {
1384 Map createPOMap = new HashMap();
1385 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourcePo.getOleERSIdentifier());
1386 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) getBusinessObjectService().findMatching(OLECreatePO.class, createPOMap);
1387 if (oleCreatePOs != null) {
1388 for (OLECreatePO oleCreatePO : oleCreatePOs) {
1389 if (StringUtils.isBlank(oleCreatePO.getInstanceId())) {
1390 getBusinessObjectService().delete(oleCreatePO);
1391 }
1392 }
1393 }
1394 posToCreateForEResources.add(eResourcePo);
1395 } else {
1396 poErrorMessage.append(validationMsg.toString());
1397 }
1398 }
1399 }
1400 List<OLEEResourceOrderRecord> oleEResourceOrderRecordList = new ArrayList<>();
1401 if (posToCreateForEholdings.size() > 0) {
1402 oleEResourceOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForEholdings, OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_ELECTRONIC, getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.LOCATION, OLEConstants.ERESOURCE_CMPNT)));
1403 }
1404 if (posToCreateForHoldings.size() > 0) {
1405 oleEResourceOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForHoldings, OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_PRINT, getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.LOCATION, OLEConstants.ERESOURCE_CMPNT)));
1406 }
1407 if (posToCreateForEResources.size() > 0) {
1408 oleEResourceOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForEResources, "E-Resource", "E-Resource"));
1409 }
1410 if (selectedPOType.equals(OLEConstants.OLEEResourceRecord.ONE_PO_PER_TITLE)) {
1411 for (OLEEResourceOrderRecord oleEResourceOrderRecord : oleEResourceOrderRecordList) {
1412 if (oleEResourceOrderRecord.getOleEResourceTxnRecord() != null) {
1413 OleRequisitionDocument requisitionDocument = null;
1414 try {
1415 requisitionDocument = getOleReqPOCreateDocumentService().createRequisitionDocument();
1416 requisitionDocument.setRequisitionSourceCode(oleEResourceOrderRecord.getOleEResourceTxnRecord().getRequisitionSource());
1417 Map purchaseOrderTypeMap = new HashMap();
1418 purchaseOrderTypeMap.put(OLEConstants.PURCHASE_ORDER_TYPE_ID, oleEResourceOrderRecord.getOleEResourceTxnRecord().getOrderType());
1419 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) getBusinessObjectService().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
1420 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
1421 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId());
1422 }
1423 getOleEResourceSearchService().setDocumentValues(requisitionDocument, oleEResourceOrderRecord);
1424 requisitionDocument.setItems(getOleEResourceSearchService().generateItemList(oleEResourceOrderRecord, requisitionDocument));
1425
1426 RequisitionService requisitionService = SpringContext.getBean(RequisitionService.class);
1427 boolean apoRuleFlag = requisitionService.isAutomaticPurchaseOrderAllowed(requisitionDocument);
1428 if (!apoRuleFlag) {
1429 oleEResourceOrderRecord.getMessageMap().put(OLEConstants.IS_APO_RULE, true);
1430 }
1431 requisitionDocument.setApplicationDocumentStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
1432 getRequisitionCreateDocumentService().saveRequisitionDocuments(requisitionDocument);
1433 if (oleEResourceOrderRecord.getOleBibRecord() != null) {
1434 poSuccessMessage.append("Requisition Document created for title '" + oleEResourceOrderRecord.getOleBibRecord().getBib().getTitle() + "' - " + requisitionDocument.getPurapDocumentIdentifier());
1435 } else if (StringUtils.isNotBlank(oleEResourceOrderRecord.getOleERSIdentifier())) {
1436 OLEEResourceRecordDocument oleeResourceRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, oleEResourceOrderRecord.getOleERSIdentifier());
1437 if (oleeResourceRecordDocument != null) {
1438 poSuccessMessage.append("Requisition Document created for title '" + oleeResourceRecordDocument.getTitle() + "' - " + requisitionDocument.getPurapDocumentIdentifier());
1439 }
1440 }
1441 poSuccessMessage.append(OLEConstants.BREAK);
1442
1443 } catch (Exception e) {
1444 e.printStackTrace();
1445 oleEResourceOrderRecord.addMessageToMap(OLEConstants.IS_VALID_RECORD, false);
1446 }
1447 }
1448 }
1449 } else if (selectedPOType.equals(OLEConstants.OLEEResourceRecord.ONE_PO_WITH_ALL_TITLES)) {
1450 OleRequisitionDocument requisitionDocument = null;
1451 try {
1452 requisitionDocument = getOleReqPOCreateDocumentService().createRequisitionDocument();
1453 requisitionDocument.setRequisitionSourceCode(oleEResourceOrderRecordList.get(0).getOleEResourceTxnRecord().getRequisitionSource());
1454 Map purchaseOrderTypeMap = new HashMap();
1455 purchaseOrderTypeMap.put(OLEConstants.PURCHASE_ORDER_TYPE_ID, oleEResourceOrderRecordList.get(0).getOleEResourceTxnRecord().getOrderType());
1456 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) getBusinessObjectService().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap);
1457 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) {
1458 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId());
1459 }
1460 getOleEResourceSearchService().setDocumentValues(requisitionDocument, oleEResourceOrderRecordList.get(0));
1461 requisitionDocument.setItems(getOleEResourceSearchService().generateMultipleItemsForOneRequisition(oleEResourceOrderRecordList, requisitionDocument));
1462
1463 requisitionDocument.setApplicationDocumentStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS);
1464 getRequisitionCreateDocumentService().saveRequisitionDocuments(requisitionDocument);
1465 String tiles = new String();
1466 for (OLEEResourceOrderRecord oleEResourceOrderRecord : oleEResourceOrderRecordList) {
1467 if (oleEResourceOrderRecord.getOleBibRecord() != null) {
1468 tiles = tiles.concat("'");
1469 tiles = tiles.concat(oleEResourceOrderRecord.getOleBibRecord().getBib().getTitle());
1470 tiles = tiles.concat("'");
1471 tiles = tiles.concat(" ");
1472 } else if (StringUtils.isNotBlank(oleEResourceOrderRecord.getOleERSIdentifier())) {
1473 OLEEResourceRecordDocument oleeResourceRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, oleEResourceOrderRecord.getOleERSIdentifier());
1474 if (oleeResourceRecordDocument != null) {
1475 tiles = tiles.concat("'");
1476 tiles = tiles.concat(oleeResourceRecordDocument.getTitle());
1477 tiles = tiles.concat("'");
1478 tiles = tiles.concat(" ");
1479 }
1480 }
1481 }
1482 poSuccessMessage.append("Requisition Document created for titles " + tiles + " - " + requisitionDocument.getPurapDocumentIdentifier());
1483 } catch (Exception e) {
1484 e.printStackTrace();
1485 }
1486 }
1487 if (selectFlag) {
1488 if (poSuccessMessage.length() > 1) {
1489 oleeResourceRecordForm.setPoSuccessMessage(poSuccessMessage.toString());
1490 }
1491 if (poErrorMessage.length() > 1) {
1492 oleeResourceRecordForm.setPoErrorMessage(poErrorMessage.toString());
1493 }
1494 } else {
1495 oleeResourceRecordForm.setPoErrorMessage("Atleast one E-Resource/Holdings should be selected.");
1496 }
1497 return super.navigate(oleeResourceRecordForm, result, request, response);
1498 }
1499
1500 @RequestMapping(params = "methodToCall=savePoChanges")
1501 public ModelAndView savePoChanges(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1502 HttpServletRequest request, HttpServletResponse response) {
1503 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
1504 boolean selectFlag = false;
1505 oleeResourceRecordForm.setPoSuccessMessage(null);
1506 oleeResourceRecordForm.setPoErrorMessage(null);
1507 for (OLECreatePO eResourcePO : oleeResourceRecordForm.geteResourcePOs()) {
1508 if (eResourcePO.isSelectFlag()) {
1509 selectFlag = true;
1510 if (StringUtils.isNotBlank(eResourcePO.getCreatePOId())) {
1511 getBusinessObjectService().save(eResourcePO);
1512 } else {
1513 Map createPOMap = new HashMap();
1514 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, eResourcePO.getOleERSIdentifier());
1515 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) getBusinessObjectService().findMatching(OLECreatePO.class, createPOMap);
1516 if (oleCreatePOs != null && oleCreatePOs.size() > 0) {
1517 for (OLECreatePO oleCreatePO : oleCreatePOs) {
1518 if (oleCreatePO.getInstanceId() == null) {
1519 eResourcePO.setCreatePOId(oleCreatePO.getCreatePOId());
1520 eResourcePO.setObjectId(oleCreatePO.getObjectId());
1521 eResourcePO.setVersionNumber(oleCreatePO.getVersionNumber());
1522 }
1523 }
1524 }
1525 getBusinessObjectService().save(eResourcePO);
1526 }
1527 }
1528 }
1529 for (OLECreatePO instancePO : oleeResourceRecordForm.getInstancePOs()) {
1530 if (instancePO.isSelectFlag()) {
1531 selectFlag = true;
1532 if (StringUtils.isNotBlank(instancePO.getCreatePOId())) {
1533 getBusinessObjectService().save(instancePO);
1534 } else {
1535 Map createPOMap = new HashMap();
1536 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, instancePO.getOleERSIdentifier());
1537 createPOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID, instancePO.getInstanceId());
1538 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) getBusinessObjectService().findMatching(OLECreatePO.class, createPOMap);
1539 if (oleCreatePOs != null && oleCreatePOs.size() > 0) {
1540 OLECreatePO oleCreatePO = oleCreatePOs.get(0);
1541 instancePO.setCreatePOId(oleCreatePO.getCreatePOId());
1542 instancePO.setObjectId(oleCreatePO.getObjectId());
1543 instancePO.setVersionNumber(oleCreatePO.getVersionNumber());
1544 }
1545 getBusinessObjectService().save(instancePO);
1546 }
1547 }
1548 }
1549 if (selectFlag) {
1550 oleeResourceRecordForm.setPoSuccessMessage("Changes have been saved successfully");
1551 } else {
1552 oleeResourceRecordForm.setPoErrorMessage("Atleast one E-Resource/Holdings should be selected");
1553 }
1554 return super.navigate(oleeResourceRecordForm, result, request, response);
1555 }
1556
1557 @RequestMapping(params = "methodToCall=next")
1558 public ModelAndView next(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1559 HttpServletRequest request, HttpServletResponse response) {
1560 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1561 return getUIFModelAndView(form, "OLEEResourceRecordView");
1562 }
1563
1564
1565 @RequestMapping(params = "methodToCall=saveRelationship")
1566 public ModelAndView saveRelationship(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1567 HttpServletRequest request, HttpServletResponse response) {
1568 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1569 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1570 ListIterator<OLELinkedEresource> oleLinkedEresourceListIterator = oleeResourceRecordDocument.getOleLinkedEresources().listIterator();
1571 while (oleLinkedEresourceListIterator.hasNext()) {
1572 OLELinkedEresource linkedEresource = oleLinkedEresourceListIterator.next();
1573 Map<String, String> tempId = new HashMap<String, String>();
1574 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, linkedEresource.getLinkedERSIdentifier());
1575 OLEEResourceRecordDocument parentDocument = (OLEEResourceRecordDocument) getBusinessObjectService().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId);
1576 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId());
1577 try {
1578 parentDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(parentDocument.getDocumentNumber(), principalPerson));
1579 } catch (WorkflowException e) {
1580 e.printStackTrace();
1581 }
1582 String removeChild = form.getActionParamaterValue("removeChild");
1583 if (removeChild.equalsIgnoreCase("no")) {
1584 linkedEresource.setRemoveRelationShip(false);
1585 return getUIFModelAndView(form);
1586 }
1587 if (linkedEresource.getRelationShipType().equalsIgnoreCase("child") && linkedEresource.isRemoveRelationShip()) {
1588 if (oleeResourceRecordDocument.getRemoveOrRelinkToParent() != null && oleeResourceRecordDocument.getRemoveOrRelinkToParent().equalsIgnoreCase("relinkToParent")) {
1589 ListIterator<OLEEResourceInstance> oleErsInstanceIterator = parentDocument.getOleERSInstances().listIterator();
1590
1591 while(oleErsInstanceIterator.hasNext()){
1592 OLEEResourceInstance instance = oleErsInstanceIterator.next();
1593 Map criteriaMap = new HashMap();
1594 criteriaMap.put("oleEResourceInstanceId", instance.getOleEResourceInstanceId());
1595 OLEEResourceInstance oleeResourceInstance = getBusinessObjectService().findByPrimaryKey(OLEEResourceInstance.class, criteriaMap);
1596 oleeResourceInstance.setOleERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
1597 oleeResourceRecordDocument.getOleERSInstances().add(oleeResourceInstance);
1598
1599 }
1600
1601 Map criteriaMap = new HashMap();
1602 criteriaMap.put("linkedERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1603 criteriaMap.put("oleERSIdentifier", linkedEresource.getOleERSIdentifier());
1604 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1605 criteriaMap.clear();
1606 criteriaMap.put("oleERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1607 criteriaMap.put("linkedERSIdentifier", linkedEresource.getOleERSIdentifier());
1608 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1609 oleLinkedEresourceListIterator.remove();
1610 } else if (oleeResourceRecordDocument.getRemoveOrRelinkToParent() != null && oleeResourceRecordDocument.getRemoveOrRelinkToParent().equalsIgnoreCase("removelink")) {
1611 Map criteriaMap = new HashMap();
1612 criteriaMap.put("linkedERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1613 criteriaMap.put("oleERSIdentifier", linkedEresource.getOleERSIdentifier());
1614 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1615 criteriaMap.clear();
1616 criteriaMap.put("oleERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1617 criteriaMap.put("linkedERSIdentifier", linkedEresource.getOleERSIdentifier());
1618 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1619 oleLinkedEresourceListIterator.remove();
1620 }
1621 } else if (linkedEresource.getRelationShipType().equalsIgnoreCase("parent")) {
1622 String removeParent = form.getActionParamaterValue("removeParent");
1623 if (removeParent.equalsIgnoreCase("yes")) {
1624 Map criteriaMap = new HashMap();
1625 criteriaMap.put("linkedERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1626 criteriaMap.put("oleERSIdentifier", linkedEresource.getOleERSIdentifier());
1627 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1628 criteriaMap.clear();
1629 criteriaMap.put("oleERSIdentifier", linkedEresource.getLinkedERSIdentifier());
1630 criteriaMap.put("linkedERSIdentifier", linkedEresource.getOleERSIdentifier());
1631 getBusinessObjectService().deleteMatching(OLELinkedEresource.class, criteriaMap);
1632 oleLinkedEresourceListIterator.remove();
1633 }
1634 }
1635 linkedEresource.setRemoveRelationShip(false);
1636
1637 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument);
1638 }
1639 return getUIFModelAndView(form);
1640 }
1641
1642
1643 @RequestMapping(params = "methodToCall=saveResultToEventlog")
1644 public ModelAndView saveResultToEventlog(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1645 HttpServletRequest request, HttpServletResponse response) {
1646 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1647 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1648 OLEEResourceEventLog oleERSEventLog = new OLEEResourceEventLog();
1649
1650 oleERSEventLog.setLogTypeId("3");
1651 oleERSEventLog.setCurrentTimeStamp();
1652 oleERSEventLog.setOleERSIdentifier(oleeResourceRecordDocument.getDocumentNumber());
1653 oleERSEventLog.setEventNote("Price Increase Analysis: Last year's cost was " + oleeResourceRecordDocument.getFiscalYearCost() + ". This year's price quote is " + oleeResourceRecordDocument.getYearPriceQuote() + ". This is a price increase of " + oleeResourceRecordDocument.getCostIncrease() + " or " + oleeResourceRecordDocument.getPercentageIncrease());
1654 oleeResourceRecordDocument.getOleERSEventLogs().add(oleERSEventLog);
1655 return super.navigate(form, result, request, response);
1656 }
1657
1658
1659 @RequestMapping(params = "methodToCall=downloadCsv")
1660 public ModelAndView downloadCsv(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1661 HttpServletRequest request, HttpServletResponse response) {
1662 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1663 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1664 response.setHeader("Content-disposition", "attachment;filename=PriceIncreaseAnalysis.csv");
1665 response.setHeader("Expires", "0");
1666 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0");
1667 response.setHeader("Pragma", "public");
1668 response.setContentType("text");
1669 StringBuffer sb = new StringBuffer();
1670 sb.append("YearCost");
1671 sb.append(",");
1672 sb.append("quote");
1673 sb.append(",");
1674 sb.append("CostIncrease");
1675 sb.append(",");
1676 sb.append("PercentIncrease");
1677 sb.append("\n");
1678
1679 sb.append(oleeResourceRecordDocument.getFiscalYearCost());
1680 sb.append(",");
1681 sb.append(oleeResourceRecordDocument.getYearPriceQuote());
1682 sb.append(",");
1683 sb.append(oleeResourceRecordDocument.getCostIncrease());
1684 sb.append(",");
1685 sb.append(oleeResourceRecordDocument.getPercentageIncrease());
1686 sb.append("\n");
1687
1688 byte[] txt = sb.toString().getBytes();
1689 OutputStream out;
1690 try {
1691 out = response.getOutputStream();
1692 out.write(txt);
1693 out.flush();
1694 out.close();
1695 } catch (IOException e) {
1696 e.printStackTrace();
1697 }
1698 return getUIFModelAndView(form);
1699 }
1700
1701
1702 @RequestMapping(params = "methodToCall=generateEmailText")
1703 public ModelAndView generateEmailText(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1704 HttpServletRequest request, HttpServletResponse response) {
1705 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1706 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1707 form.setEmailFlag(true);
1708 oleeResourceRecordDocument.setEmailText(OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_APPROVAL_TEXT + oleeResourceRecordDocument.getTitle() + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_LAST_YEAR_COST + oleeResourceRecordDocument.getFiscalYearCost() + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_THIS_YEAR_QUOTE + oleeResourceRecordDocument.getYearPriceQuote() + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_PRICE_INCREASE + oleeResourceRecordDocument.getCostIncrease() + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_OR + oleeResourceRecordDocument.getPercentageIncrease() + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_PERCENT + OLEConstants.OLEEResourceRecord.ERESOURCE_EMAIL_CONFIRM);
1709 return getUIFModelAndView(form);
1710 }
1711
1712
1713 @RequestMapping(params = "methodToCall=calculateIncrease")
1714 public ModelAndView calculateIncrease(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1715 HttpServletRequest request, HttpServletResponse response) {
1716 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1717 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
1718 List<OLEEResourceInvoices> oleERSInvoices = oleeResourceRecordDocument.getOleERSInvoices();
1719 int fiscalYearCost = 0;
1720 for (OLEEResourceInvoices oleeResourceInvoices : oleERSInvoices) {
1721 fiscalYearCost = fiscalYearCost + (Double.valueOf(oleeResourceInvoices.getInvoicedAmount())).intValue();
1722 }
1723 double cost = oleeResourceRecordDocument.getYearPriceQuote() - oleeResourceRecordDocument.getFiscalYearCost();
1724 oleeResourceRecordDocument.setCostIncrease(Math.round(cost));
1725 double percentage = (cost / oleeResourceRecordDocument.getFiscalYearCost()) * 100;
1726 oleeResourceRecordDocument.setPercentageIncrease(Math.round(percentage));
1727 return super.navigate(form, result, request, response);
1728 }
1729
1730
1731 @RequestMapping(params = "methodToCall=closeDialog")
1732 public ModelAndView closeDialog(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1733 HttpServletRequest request, HttpServletResponse response) {
1734 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1735 form.setEmailFlag(false);
1736 return getUIFModelAndView(form);
1737 }
1738
1739 @RequestMapping(params = "methodToCall=search")
1740 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
1741 HttpServletRequest request, HttpServletResponse response) {
1742 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
1743 String formKey = (String) request.getSession().getValue("formKeyValue");
1744 List<String> oleEResIdentifiers = new ArrayList<>();
1745 if (StringUtils.isNotBlank(formKey)) {
1746 OLEEResourceRecordForm sessionForm = (OLEEResourceRecordForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
1747 OLEEResourceRecordDocument oleEResourceRecordDocument = (OLEEResourceRecordDocument) sessionForm.getDocument();
1748 oleEResIdentifiers.add(oleEResourceRecordDocument.getOleERSIdentifier());
1749 List<OLELinkedEresource> oleLinkedEresources = oleEResourceRecordDocument.getOleLinkedEresources();
1750 for (OLELinkedEresource oleLinkedEresource : oleLinkedEresources) {
1751 oleEResIdentifiers.add(oleLinkedEresource.getLinkedERSIdentifier());
1752 }
1753 }
1754 OLEEResourceSearchServiceImpl oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE);
1755 List<OLESearchCondition> oleSearchConditionsList = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList();
1756 List<OLEEResourceRecordDocument> eresourceDocumentList = new ArrayList<OLEEResourceRecordDocument>();
1757 List<OLEEResourceRecordDocument> eresourceList = new ArrayList<OLEEResourceRecordDocument>();
1758 try {
1759 eresourceList = oleEResourceSearchService.performSearch(oleSearchConditionsList);
1760 } catch (Exception e) {
1761 LOG.error("Exception while hitting the performSearch()" + e.getMessage());
1762 }
1763 if (oleEResIdentifiers != null && oleEResIdentifiers.size() > 0) {
1764 List<OLEEResourceRecordDocument> oleeResourceRecordDocumentList = new ArrayList<OLEEResourceRecordDocument>();
1765 for (OLEEResourceRecordDocument oleeResourceRecordDocument : eresourceList) {
1766 if (!oleEResIdentifiers.contains(oleeResourceRecordDocument.getOleERSIdentifier())) {
1767 oleeResourceRecordDocumentList.add(oleeResourceRecordDocument);
1768 oleeResourceRecordDocument.setRelationshipType("child");
1769 }
1770 }
1771 eresourceList = oleeResourceRecordDocumentList;
1772 for (OLEEResourceRecordDocument oleEResourceRecordDocument : eresourceList) {
1773 Map criteriaMap = new HashMap();
1774 criteriaMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleEResourceRecordDocument.getOleERSIdentifier());
1775 List<OLELinkedEresource> oleLinkedEresourceList = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, criteriaMap);
1776 oleEResourceRecordDocument.setOleLinkedEresources(oleLinkedEresourceList);
1777 }
1778 }
1779 if (oleeResourceRecordForm.getStatus() != null) {
1780 eresourceList = oleEResourceSearchService.statusNotNull(eresourceList, oleeResourceRecordForm.getStatus());
1781 }
1782 if (oleeResourceRecordForm.iseResStatusDate()) {
1783 eresourceDocumentList = oleEResourceSearchService.filterEResRecBystatusDate(oleeResourceRecordForm.getBeginDate(), oleeResourceRecordForm.getEndDate(), eresourceList);
1784 oleeResourceRecordForm.setEresourceDocumentList(eresourceDocumentList);
1785 } else {
1786 oleeResourceRecordForm.setEresourceDocumentList(eresourceList);
1787 }
1788 List<OLEEResourceRecordDocument> eresDocumentList = oleeResourceRecordForm.getEresourceDocumentList();
1789 oleEResourceSearchService.removeDuplicateEresDocumentsFromList(eresDocumentList);
1790 if (!GlobalVariables.getMessageMap().hasMessages()) {
1791 if (oleeResourceRecordForm.getEresourceDocumentList().size() == 0)
1792 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND);
1793 } else {
1794 oleeResourceRecordForm.setEresourceDocumentList(null);
1795 }
1796 return getUIFModelAndView(oleeResourceRecordForm);
1797 }
1798
1799
1800 @RequestMapping(params = "methodToCall=linkEResource")
1801 public ModelAndView linkEResource(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result,
1802 HttpServletRequest request, HttpServletResponse response) throws Exception {
1803 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form;
1804 oleeResourceRecordForm.setMessage(null);
1805 List<OLEEResourceRecordDocument> oleeResourceRecordDocumentList = oleeResourceRecordForm.getEresourceDocumentList();
1806 String formKey = (String) request.getSession().getValue("formKeyValue");
1807 OLEEResourceRecordForm sessionForm;
1808 if (StringUtils.isNotBlank(formKey)) {
1809 sessionForm = (OLEEResourceRecordForm) GlobalVariables.getUifFormManager().getSessionForm(formKey);
1810 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) sessionForm.getDocument();
1811 List<OLELinkedEresource> oleLinkedEresources = oleeResourceRecordDocument.getOleLinkedEresources();
1812 int parentCount = 0;
1813 int selectCount = 0;
1814 for (OLEEResourceRecordDocument eResourceRecordDocument : oleeResourceRecordDocumentList) {
1815 if (eResourceRecordDocument.isSelectEResFlag()) {
1816 selectCount++;
1817 if (eResourceRecordDocument.getRelationshipType().equals("parent")) {
1818 parentCount++;
1819 if (parentCount > 1) {
1820 break;
1821 }
1822 }
1823 }
1824 }
1825 if (selectCount == 0) {
1826 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_SELECT_ERESOURCE));
1827 return getUIFModelAndView(oleeResourceRecordForm);
1828 } else if (parentCount > 1) {
1829 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_ERESOURCE_ONLY_ONE_PARENT));
1830 return getUIFModelAndView(oleeResourceRecordForm);
1831 }
1832 int linkedParentCount = 0;
1833 for (OLELinkedEresource linkedEresource : oleLinkedEresources) {
1834 if (linkedEresource.getRelationShipType().equals("parent")) {
1835 linkedParentCount++;
1836 }
1837 }
1838 if (linkedParentCount > 0 && parentCount > 0) {
1839 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_ERESOURCE_ALREADY_HAS_PARENT));
1840 return getUIFModelAndView(oleeResourceRecordForm);
1841 }
1842 StringBuffer message = new StringBuffer();
1843 List<String> ids = new ArrayList<String>();
1844 boolean messageText = false;
1845 for (OLEEResourceRecordDocument selectedeResourceRecordDocument : oleeResourceRecordDocumentList) {
1846 if (selectedeResourceRecordDocument.isSelectEResFlag()) {
1847 for (OLELinkedEresource linkedEresource : selectedeResourceRecordDocument.getOleLinkedEresources()) {
1848 if (linkedEresource.getRelationShipType().equalsIgnoreCase("parent")) {
1849 message.append(selectedeResourceRecordDocument.getTitle());
1850 message.append(", ");
1851 ids.add(selectedeResourceRecordDocument.getOleERSIdentifier());
1852 } else {
1853 Map map = new HashMap();
1854 map.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
1855 map.put("relationShipType", "child");
1856 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, map);
1857 OLELinkedEresource oleLinkedEresource = eResource.get(0);
1858 String chain = oleLinkedEresource.getChainString();
1859 if (chain.contains(selectedeResourceRecordDocument.getOleERSIdentifier())) {
1860 message.append(selectedeResourceRecordDocument.getTitle());
1861 message.append(", ");
1862 messageText = true;
1863 ids.add(selectedeResourceRecordDocument.getOleERSIdentifier());
1864 }
1865 }
1866 }
1867 }
1868 }
1869 Iterator<OLEEResourceRecordDocument> iterator = oleeResourceRecordDocumentList.iterator();
1870 for (String id : ids) {
1871 while (iterator.hasNext()) {
1872 if (id.equalsIgnoreCase(iterator.next().getOleERSIdentifier())) {
1873 iterator.remove();
1874 break;
1875 }
1876 }
1877 }
1878 for (OLEEResourceRecordDocument selectedeResourceRecordDocument : oleeResourceRecordDocumentList) {
1879 if (selectedeResourceRecordDocument.isSelectEResFlag()) {
1880
1881 Map map = new HashMap();
1882 map.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
1883 map.put("relationShipType", "child");
1884 List<OLELinkedEresource> eResource1 = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, map);
1885 if (eResource1.size() > 0) {
1886 OLELinkedEresource oleLinkedEresource1 = eResource1.get(0);
1887 String chain = oleLinkedEresource1.getChainString();
1888 if (!chain.contains(selectedeResourceRecordDocument.getOleERSIdentifier())) {
1889 OLELinkedEresource oleLinkedEresource = new OLELinkedEresource();
1890 oleLinkedEresource.setLinkedERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier());
1891 oleLinkedEresource.setRelationShipType(selectedeResourceRecordDocument.getRelationshipType());
1892 if (selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("child")) {
1893 Map linkedEresourceMap = new HashMap();
1894 linkedEresourceMap.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
1895 linkedEresourceMap.put("relationShipType", "child");
1896 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, linkedEresourceMap);
1897 if (eResource.size() > 0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())) {
1898 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1899 } else {
1900 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1901 }
1902 }
1903 oleLinkedEresources.add(oleLinkedEresource);
1904 OLELinkedEresource linkedEresource = new OLELinkedEresource();
1905 linkedEresource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
1906 linkedEresource.setOleERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier());
1907 if (selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("parent")) {
1908 linkedEresource.setRelationShipType("child");
1909 Map eResourceMap = new HashMap();
1910 eResourceMap.put("oleERSIdentifier", selectedeResourceRecordDocument.getOleERSIdentifier());
1911 eResourceMap.put("relationShipType", "child");
1912 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, eResourceMap);
1913 if (eResource.size() > 0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())) {
1914 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1915 } else {
1916 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1917 }
1918 } else {
1919 linkedEresource.setRelationShipType("parent");
1920 }
1921 getBusinessObjectService().save(linkedEresource);
1922 }
1923 } else {
1924 OLELinkedEresource oleLinkedEresource = new OLELinkedEresource();
1925 oleLinkedEresource.setLinkedERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier());
1926 oleLinkedEresource.setRelationShipType(selectedeResourceRecordDocument.getRelationshipType());
1927 if (selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("child")) {
1928 Map linkedEresourceMap = new HashMap();
1929 linkedEresourceMap.put("oleERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
1930 linkedEresourceMap.put("relationShipType", "child");
1931 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, linkedEresourceMap);
1932 if (eResource.size() > 0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())) {
1933 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1934 } else {
1935 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1936 }
1937 }
1938 oleLinkedEresources.add(oleLinkedEresource);
1939 OLELinkedEresource linkedEresource = new OLELinkedEresource();
1940 linkedEresource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
1941 linkedEresource.setOleERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier());
1942 if (selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("parent")) {
1943 linkedEresource.setRelationShipType("child");
1944 Map eResourceMap = new HashMap();
1945 eResourceMap.put("oleERSIdentifier", selectedeResourceRecordDocument.getOleERSIdentifier());
1946 eResourceMap.put("relationShipType", "child");
1947 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) getBusinessObjectService().findMatching(OLELinkedEresource.class, eResourceMap);
1948 if (eResource.size() > 0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())) {
1949 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1950 } else {
1951 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" + selectedeResourceRecordDocument.getOleERSIdentifier());
1952 }
1953 } else {
1954 linkedEresource.setRelationShipType("parent");
1955 }
1956 getBusinessObjectService().save(linkedEresource);
1957 }
1958
1959 }
1960 }
1961 if (message.length() > 0 && !messageText) {
1962 String format = String.format("The following documents (%s) can not be linked, since it already has parent. ", message.substring(0, message.lastIndexOf(",")));
1963 oleeResourceRecordForm.setMessage(format);
1964 } else if (message.length() > 0 && messageText) {
1965 String format = String.format("The following documents (%s) can not be linked, since it is already a parent in the hierarchy. ", message.substring(0, message.lastIndexOf(",")));
1966 oleeResourceRecordForm.setMessage(format);
1967 }
1968 }
1969 return getUIFModelAndView(oleeResourceRecordForm);
1970 }
1971
1972
1973 @RequestMapping(params = "methodToCall=delete")
1974 public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1975 HttpServletRequest request, HttpServletResponse response) {
1976 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1977 OLEEResourceRecordDocument document = (OLEEResourceRecordDocument) form.getDocument();
1978 List<OLEEResourceInstance> oleeResourceInstances = document.getOleERSInstances();
1979 List<OLEEResourceLicense> oleERSLicenses = document.getOleERSLicenseRequests();
1980 List<OLELinkedEresource> oleLikedEResources = document.getOleLinkedEresources();
1981 List<OLEEResourcePO> oleEResourcePOList = document.getOleERSPOItems();
1982
1983 if (oleeResourceInstances.size() > 0 || oleERSLicenses.size() > 0 || oleLikedEResources.size() > 0 || oleEResourcePOList.size() > 0) {
1984 document.setAccessStatus("Active");
1985 } else {
1986 document.setAccessStatus("Inactive");
1987 getBusinessObjectService().save(document);
1988 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OLEEResourceRecord.ERESOURCE_HAS_BEEN_DELETED);
1989 }
1990 return getUIFModelAndView(form);
1991 }
1992
1993
1994 @RequestMapping(params = "methodToCall=deleteInstance")
1995 public ModelAndView deleteInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
1996 HttpServletRequest request, HttpServletResponse response) {
1997 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
1998
1999 OLEEResourceRecordDocument document = (OLEEResourceRecordDocument) form.getDocument();
2000 List<OLEEResourceInstance> oleInstancesDeleteList = new ArrayList<>();
2001 List<OLEEResourceInstance> oleInstancesAddList = new ArrayList<>();
2002 List<OLEEResourceInstance> oleERSInstances = document.getOleERSInstances();
2003 if (oleERSInstances != null) {
2004 for (OLEEResourceInstance oleeResourceInstance : oleERSInstances) {
2005 int purchaseOrderCount = 0;
2006 if (oleeResourceInstance.isSelect()) {
2007 String instanceId = oleeResourceInstance.getInstanceId();
2008 Map instanceMap = new HashMap();
2009 instanceMap.put("instanceId", instanceId);
2010 List<OleCopy> oleCopyList = (List<OleCopy>) getBusinessObjectService().findMatching(OleCopy.class, instanceMap);
2011 for (OleCopy oleCopy : oleCopyList) {
2012 if (oleCopy.getPoItemId() != null) {
2013 purchaseOrderCount++;
2014 }
2015 }
2016
2017 if (purchaseOrderCount == 0) {
2018 oleInstancesDeleteList.add(oleeResourceInstance);
2019 } else {
2020 oleInstancesAddList.add(oleeResourceInstance);
2021 }
2022 }
2023 }
2024 }
2025 document.setDeletedInstances(oleInstancesDeleteList);
2026 document.setPurchaseOrderInstances(oleInstancesAddList);
2027
2028 BibTrees bibTrees = new BibTrees();
2029
2030 for (OLEEResourceInstance oleeResourceInstance : oleInstancesDeleteList) {
2031
2032
2033 BibTree bibTree = new BibTree();
2034 Bib bib = new Bib();
2035 bib.setId(oleeResourceInstance.getBibId());
2036 bibTree.setBib(bib);
2037 bibTrees.getBibTrees().add(bibTree);
2038 HoldingsTree holdingsTree = new HoldingsTree();
2039 Holdings holdings = new Holdings();
2040 holdings.setOperation(DocstoreDocument.OperationType.DELETE);
2041 holdings.setId(oleeResourceInstance.getInstanceId());
2042 holdingsTree.setHoldings(holdings);
2043 bibTree.getHoldingsTrees().add(holdingsTree);
2044 getBusinessObjectService().delete(oleeResourceInstance);
2045 Map<String, String> criteriaMap = new HashMap<>();
2046 criteriaMap.put(OLEConstants.INSTANCE_ID, oleeResourceInstance.getInstanceId());
2047 getBusinessObjectService().deleteMatching(OleCopy.class, criteriaMap);
2048 }
2049 try {
2050 getDocstoreClientLocator().getDocstoreClient().processBibTrees(bibTrees);
2051 } catch (Exception e) {
2052
2053 }
2054
2055
2056
2057
2058
2059 return getUIFModelAndView(form);
2060 }
2061
2062 @RequestMapping(params = "methodToCall=addSearchCriteria")
2063 public ModelAndView addSearchCriteria(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2064 HttpServletRequest request, HttpServletResponse response) {
2065 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
2066 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList();
2067 oleSearchConditions.add(new OLESearchCondition());
2068 for (OLESearchCondition oleSearchCondition : oleSearchConditions) {
2069 if (oleSearchCondition.getOperator() == null) {
2070 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND);
2071 }
2072 }
2073 return super.navigate(oleeResourceRecordForm, result, request, response);
2074 }
2075
2076 @RequestMapping(params = "methodToCall=clearSearch")
2077 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2078 HttpServletRequest request, HttpServletResponse response) {
2079 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
2080 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList();
2081 int searchConditionSize = oleSearchConditions.size();
2082 oleeResourceRecordForm.setOleSearchParams(new OLESearchParams());
2083 oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList();
2084 for (int ersCount = 0; ersCount < searchConditionSize; ersCount++) {
2085 oleSearchConditions.add(new OLESearchCondition());
2086 }
2087 for (OLESearchCondition oleSearchCondition : oleSearchConditions) {
2088 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND);
2089 }
2090 oleeResourceRecordForm.setEresourceDocumentList(null);
2091 oleeResourceRecordForm.seteResStatusDate(false);
2092 oleeResourceRecordForm.setBeginDate(null);
2093 oleeResourceRecordForm.setEndDate(null);
2094 oleeResourceRecordForm.setStatus(null);
2095 return super.navigate(oleeResourceRecordForm, result, request, response);
2096 }
2097
2098 @RequestMapping(params = "methodToCall=cancelSearch")
2099 public ModelAndView cancelSearch(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2100 HttpServletRequest request, HttpServletResponse response) {
2101 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
2102 return getUIFModelAndView(oleeResourceRecordForm, "OLEEResourceRecordView-Related-E-ResourceTab");
2103 }
2104
2105
2106 @RequestMapping(params = "methodToCall=linkEResourceInstance")
2107 public ModelAndView linkEResourceInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2108 HttpServletRequest request, HttpServletResponse response) {
2109 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
2110 List<OLEEResourceInstance> oleeResourceInstances = new ArrayList<>();
2111
2112 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
2113 List<OLEEResourceInstance> oleeResourceInstanceList = oleeResourceRecordDocument.getOleERSInstances();
2114
2115 HttpSession session = request.getSession();
2116 session.setAttribute("oleERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
2117 session.setAttribute("createChildEResource", Boolean.TRUE);
2118 StringBuffer instanceIds = new StringBuffer();
2119 for (OLEEResourceInstance oleeResourceInstance : oleeResourceInstanceList) {
2120 if (oleeResourceInstance.isSelect()) {
2121 instanceIds.append(oleeResourceInstance.getInstanceId());
2122 instanceIds.append(",");
2123 }
2124 }
2125 session.setAttribute("oleeResourceInstancesIdentifier", instanceIds.toString());
2126 form.setOleeResourceInstances(oleeResourceInstances);
2127
2128 String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") +
2129 "/ole-kr-krad/oleERSController?viewId=OLEEResourceRecordView&methodToCall=docHandler&command=initiate&documentClass=org.kuali.ole.select.document.OLEEResourceRecordDocument";
2130
2131 return performRedirect(form, url);
2132
2133 }
2134
2135
2136 @RequestMapping(params = "methodToCall=packageSearch")
2137 public ModelAndView packageSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2138 HttpServletRequest request, HttpServletResponse response) {
2139
2140 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2141 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2142 oleeResourceRecordDocument.setGoKbPlatformList(null);
2143 oleEResourceRecordForm.setShowMultiplePlatforms(false);
2144 oleeResourceRecordDocument.setGoKbPackageList(null);
2145 String packageName = oleEResourceRecordForm.getPackageName();
2146 String platformName = oleEResourceRecordForm.getPlatformName();
2147 String title = oleEResourceRecordForm.getTitle();
2148 String platformProvider = oleEResourceRecordForm.getPlatformProvider();
2149 String publisher = oleEResourceRecordForm.getPublisher();
2150 String titleInstanceType = oleEResourceRecordForm.getTitleInstanceType();
2151
2152 List<String> packageStatusList = new ArrayList<>();
2153 packageStatusList.add("Current");
2154 packageStatusList.add("Excepted");
2155
2156 List<String> platformStatusList = new ArrayList<>();
2157 platformStatusList.add("Current");
2158 platformStatusList.add("Excepted");
2159
2160 List<String> tippStatus = new ArrayList<>();
2161 tippStatus.add("Current");
2162 tippStatus.add("Excepted");
2163
2164
2165 List<String> platformProviderList = oleEResourceRecordForm.getPlatformProviderList();
2166 if (StringUtils.isNotEmpty(platformProvider)) {
2167 platformProviderList.add(platformProvider);
2168 }
2169 if (StringUtils.isNotEmpty(publisher)) {
2170 platformProviderList.add(publisher);
2171 }
2172
2173 StringBuilder stringBuilder = new StringBuilder();
2174 stringBuilder.append(packageName);
2175 stringBuilder.append(platformName);
2176 stringBuilder.append(title);
2177 stringBuilder.append(titleInstanceType);
2178
2179 List<OleGokbView> oleGokbViews = null;
2180 List<OleGokbTipp> oleGokbTipps = new ArrayList<>();
2181 List<String> isbnList = new ArrayList<>();
2182 for (OLEStandardIdentifier oleStandardIdentifier : oleeResourceRecordDocument.getStandardIdentifiers()) {
2183 if (oleStandardIdentifier.getIdentifier() != null && oleStandardIdentifier.getIdentifierType() != null && oleStandardIdentifier.getIdentifierType().equalsIgnoreCase("issn") && StringUtils.isNotEmpty(oleStandardIdentifier.getIdentifier())) {
2184 isbnList.add(oleStandardIdentifier.getIdentifier());
2185 }
2186 }
2187
2188 if (stringBuilder != null && stringBuilder.length() > 0 || isbnList.size() > 0 || platformProviderList.size() > 0 || packageStatusList.size() > 0) {
2189
2190 OLEGOKBSearchDaoOjb olegokbSearchDaoOjb = (OLEGOKBSearchDaoOjb) SpringContext.getBean("oleGOKBSearchDaoOjb");
2191 oleGokbTipps = olegokbSearchDaoOjb.packageSearch(packageName, platformName, platformProviderList, title, isbnList, titleInstanceType, packageStatusList, platformStatusList, tippStatus);
2192
2193 } else {
2194 oleGokbViews = (List<OleGokbView>) getBusinessObjectService().findAll(OleGokbView.class);
2195 }
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229 List<OLEGOKbPackage> olegoKbPackages = getOleeResourceHelperService().searchGokbForPackagess(oleGokbTipps, oleEResourceRecordForm);
2230 if (olegoKbPackages.size() == 0) {
2231 oleEResourceRecordForm.setShowMultiplePlatforms(false);
2232 oleeResourceRecordDocument.setGoKbPlatformList(null);
2233 oleeResourceRecordDocument.setGoKbTIPPList(null);
2234 oleeResourceRecordDocument.setGoKbPlatforms(null);
2235 oleeResourceRecordDocument.setGoKbPackageList(null);
2236
2237 }
2238 oleeResourceRecordDocument.setGoKbPackageList(olegoKbPackages);
2239
2240 return getUIFModelAndView(oleEResourceRecordForm);
2241 }
2242
2243 @RequestMapping(params = "methodToCall=showTipps")
2244 public ModelAndView showTipps(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2245 HttpServletRequest request, HttpServletResponse response) {
2246 return super.navigate(form, result, request, response);
2247 }
2248
2249
2250 @RequestMapping(params = "methodToCall=getPlatforms")
2251 public ModelAndView getPlatforms(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2252 HttpServletRequest request, HttpServletResponse response) {
2253 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2254 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2255 List<OLEGOKbPlatform> olegoKbPlatforms = getOleeResourceHelperService().getPlatformByPlackage(oleEResourceRecordForm.getPackageId());
2256 oleEResourceRecordForm.setShowMultiplePlatforms(true);
2257 oleeResourceRecordDocument.setGoKbPlatformList(olegoKbPlatforms);
2258 return super.navigate(form, result, request, response);
2259 }
2260
2261
2262 @RequestMapping(params = "methodToCall=getTipps")
2263 public ModelAndView getTipps(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2264 HttpServletRequest request, HttpServletResponse response) {
2265 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2266 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2267 String title = oleEResourceRecordForm.getTitle();
2268 String platformProvider = oleEResourceRecordForm.getPlatformProvider();
2269 String publisher = oleEResourceRecordForm.getPublisher();
2270 String titleInstanceType = oleEResourceRecordForm.getTitleInstanceType();
2271 List<String> platformProviderList = oleEResourceRecordForm.getPlatformProviderList();
2272 if (StringUtils.isNotEmpty(platformProvider)) {
2273 platformProviderList.add(platformProvider);
2274 }
2275 if (StringUtils.isNotEmpty(publisher)) {
2276 platformProviderList.add(publisher);
2277 }
2278 List<OLEGOKbPlatform> goKbPlatformList = new ArrayList<>();
2279 for (OLEGOKbPlatform gokbPlatform : oleeResourceRecordDocument.getGoKbPlatformList()) {
2280 if (gokbPlatform.isSelect() || goKbPlatformList.size() == 1) {
2281 OLEGOKBSearchDaoOjb olegokbSearchDaoOjb = (OLEGOKBSearchDaoOjb) SpringContext.getBean("oleGOKBSearchDaoOjb");
2282 Integer resultSetSize = OJBUtility.getResultLimit();
2283 oleeResourceRecordDocument.setGokbPackageId(Integer.valueOf(gokbPlatform.getPackageId()));
2284 List<String> isbnList = new ArrayList<>();
2285 for (OLEStandardIdentifier oleStandardIdentifier : oleeResourceRecordDocument.getStandardIdentifiers()) {
2286 if (oleStandardIdentifier.getIdentifier() != null && oleStandardIdentifier.getIdentifierType() != null && oleStandardIdentifier.getIdentifierType().equalsIgnoreCase("issn") && StringUtils.isNotEmpty(oleStandardIdentifier.getIdentifier())) {
2287 isbnList.add(oleStandardIdentifier.getIdentifier());
2288 }
2289 }
2290 List<OleGokbTipp> oleGokbTippList = olegokbSearchDaoOjb.getTippsByPlatform(gokbPlatform.getPlatformId(), gokbPlatform.getPackageId(), title, titleInstanceType, platformProviderList, isbnList);
2291 List<OLEGOKbTIPP> olegoKbTIPP;
2292 if (oleGokbTippList != null && resultSetSize != null && oleGokbTippList.size() > resultSetSize) {
2293 olegoKbTIPP = getOleeResourceHelperService().buildOLEGOKBTIPP(oleGokbTippList.subList(0, resultSetSize));
2294 } else {
2295 olegoKbTIPP = getOleeResourceHelperService().buildOLEGOKBTIPP(oleGokbTippList);
2296 }
2297 gokbPlatform.setGoKbTIPPList(olegoKbTIPP);
2298 }
2299 goKbPlatformList.add(gokbPlatform);
2300
2301 }
2302
2303 oleeResourceRecordDocument.setSelectedGoKbPlatforms(goKbPlatformList);
2304 oleEResourceRecordForm.setShowTippsWithMorePlatform(true);
2305 return super.navigate(form, result, request, response);
2306 }
2307
2308
2309 @RequestMapping(params = "methodToCall=platformSearch")
2310 public ModelAndView platformSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2311 HttpServletRequest request, HttpServletResponse response) {
2312 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2313 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2314 List<OLEGOKbTIPP> goKbTIPPs = new ArrayList<>();
2315 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP();
2316 goKbTIPPs.add(olegoKbTIPP);
2317 goKbTIPPs.add(olegoKbTIPP);
2318 goKbTIPPs.add(olegoKbTIPP);
2319 oleeResourceRecordDocument.setGoKbTIPPList(goKbTIPPs);
2320 return super.navigate(form, result, request, response);
2321 }
2322
2323
2324 @RequestMapping(params = "methodToCall=tiipResults")
2325 public ModelAndView tiipResults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2326 HttpServletRequest request, HttpServletResponse response) {
2327 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2328 oleEResourceRecordForm.setShowTiipResults(true);
2329 return super.navigate(form, result, request, response);
2330 }
2331
2332
2333 @RequestMapping(params = "methodToCall=importData")
2334 public ModelAndView importData(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2335 HttpServletRequest request, HttpServletResponse response) {
2336 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2337 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2338 KRADServiceLocatorWeb.getDocumentService().updateDocument(oleeResourceRecordDocument);
2339 OLEBatchProcessProfileBo gokbImportProfile = getOleeResourceHelperService().getGOKBImportProfile(oleeResourceRecordDocument.getProfile());
2340 if (gokbImportProfile == null) {
2341 oleEResourceRecordForm.setProfileErrorMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.N0_PROFILE_SELECTED));
2342 } else {
2343 List<BibMarcRecord> bibMarcRecords = getOleeResourceHelperService().buildBibMarcRecords(oleeResourceRecordDocument.getGoKbPlatformList(), oleeResourceRecordDocument.getOleERSIdentifier(), gokbImportProfile);
2344 if (oleEResourceRecordForm.isImportPackageMetaDataOnly() || (bibMarcRecords != null && bibMarcRecords.size() > 0)) {
2345 OleGokbPackage oleGokbPackage = KRADServiceLocator.getBusinessObjectService().findBySinglePrimaryKey(OleGokbPackage.class, oleeResourceRecordDocument.getGokbPackageId());
2346 getOleeResourceHelperService().overwriteEresourceWithPackage(oleeResourceRecordDocument, oleGokbPackage, "");
2347 getOleeResourceHelperService().insertOrUpdateGokbElementsForEResource(oleeResourceRecordDocument, false);
2348 getOleeResourceHelperService().createOrUpdateVendorAndPlatform(oleeResourceRecordDocument);
2349 }
2350
2351 if (bibMarcRecords != null && bibMarcRecords.size() > 0) {
2352 getOleeResourceHelperService().importTipps(gokbImportProfile, bibMarcRecords);
2353 }
2354 }
2355 return getUIFModelAndView(oleEResourceRecordForm);
2356 }
2357
2358
2359 @RequestMapping(params = "methodToCall=setDefaults")
2360 public ModelAndView setDefaults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2361 HttpServletRequest request, HttpServletResponse response) {
2362 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2363 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2364 if (oleeResourceRecordDocument.getTitle() != null && StringUtils.isNotEmpty(oleeResourceRecordDocument.getTitle())) {
2365 oleEResourceRecordForm.setPackageName(oleeResourceRecordDocument.getTitle());
2366 }
2367
2368
2369
2370
2371 List<String> platformProviderList = getOleeResourceHelperService().getPlatformProvidersForInstance(oleeResourceRecordDocument.getOleERSInstances());
2372
2373 oleEResourceRecordForm.setPlatformProviderList(platformProviderList);
2374
2375 if (oleeResourceRecordDocument.getIsbn() != null && StringUtils.isNotEmpty(oleeResourceRecordDocument.getIsbn())) {
2376 oleeResourceRecordDocument.getStandardIdentifiers().get(0).setIdentifier(oleeResourceRecordDocument.getIsbn());
2377 }
2378 this.packageSearch(oleEResourceRecordForm, result, request, response);
2379
2380 return super.navigate(oleEResourceRecordForm, result, request, response);
2381 }
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393 @RequestMapping(params = "methodToCall=getManageGOKbDataOnEIns")
2394 public ModelAndView getManageGOKbDataOnEIns(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2395 HttpServletRequest request, HttpServletResponse response) {
2396 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2397 String selectedLine = request.getParameter("lineIndex");
2398 String eResId = request.getParameter("eResId");
2399 OLEEResourceRecordDocument oleeResourceRecordDocument = getBusinessObjectService().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, eResId);
2400 oleeResourceRecordDocument.setOleGOKbMappingValueList(new ArrayList<OLEGOKbMappingValue>());
2401
2402 if (StringUtils.isNotBlank(selectedLine)) {
2403 OLEEResourceInstance oleERSInstance = oleeResourceRecordDocument.getOleERSInstances().get(Integer.parseInt(selectedLine));
2404 Map map = new HashMap();
2405 map.put("recordId", oleERSInstance.getInstanceId());
2406 map.put("recordType", "E-Instance");
2407 List<OLEGOKbMappingValue> goKbMappingValueList = (List<OLEGOKbMappingValue>) getBusinessObjectService().findMatching(OLEGOKbMappingValue.class, map);
2408 if (goKbMappingValueList != null && goKbMappingValueList.size() > 0) {
2409 for (OLEGOKbMappingValue olegoKbMappingValue : goKbMappingValueList) {
2410 if (StringUtils.isNotEmpty(olegoKbMappingValue.getLocalValue())) {
2411 olegoKbMappingValue.setGokbFlag(false);
2412 } else {
2413 olegoKbMappingValue.setGokbFlag(true);
2414 }
2415 oleEResourceRecordForm.getOleGOKbMappingValueList().add(olegoKbMappingValue);
2416 }
2417 }
2418 }
2419 oleEResourceRecordForm.setFlagPop(true);
2420 return getUIFModelAndView(oleEResourceRecordForm);
2421 }
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433 @RequestMapping(params = "methodToCall=getManageGOKbDataOnERes")
2434 public ModelAndView getManageGOKbDataOnERes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2435 HttpServletRequest request, HttpServletResponse response) {
2436 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2437 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2438 oleeResourceRecordDocument.setOleGOKbMappingValueList(new ArrayList<OLEGOKbMappingValue>());
2439 Map map = new HashMap();
2440 map.put("recordId", oleeResourceRecordDocument.getOleERSIdentifier());
2441 map.put("recordType", "E-Resource");
2442 List<OLEGOKbMappingValue> goKbMappingValueList = (List<OLEGOKbMappingValue>) getBusinessObjectService().findMatching(OLEGOKbMappingValue.class, map);
2443 if (goKbMappingValueList != null && goKbMappingValueList.size() > 0) {
2444 for (OLEGOKbMappingValue olegoKbMappingValue : goKbMappingValueList) {
2445 if (StringUtils.isNotEmpty(olegoKbMappingValue.getLocalValue())) {
2446 olegoKbMappingValue.setGokbFlag(false);
2447 } else {
2448 olegoKbMappingValue.setGokbFlag(true);
2449 }
2450 oleeResourceRecordDocument.getOleGOKbMappingValueList().add(olegoKbMappingValue);
2451 }
2452 }
2453 oleEResourceRecordForm.setFlagPop(true);
2454 return getUIFModelAndView(oleEResourceRecordForm);
2455 }
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467 @RequestMapping(params = "methodToCall=showMultipleContacts")
2468 public ModelAndView showMultipleContacts(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2469 HttpServletRequest request, HttpServletResponse response) {
2470 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2471 String eResourceId = request.getParameter("eResourceId");
2472 Map map = new HashMap();
2473 map.put("oleERSIdentifier", eResourceId);
2474 List<OLEEResourceRecordDocument> oleeResourceRecordDocuments = (List<OLEEResourceRecordDocument>) getBusinessObjectService().findMatching(OLEEResourceRecordDocument.class, map);
2475 OLEEResourceRecordDocument oleeResourceRecordDocument = null;
2476 if (oleeResourceRecordDocuments != null && oleeResourceRecordDocuments.size() > 0) {
2477 oleeResourceRecordDocument = oleeResourceRecordDocuments.get(0);
2478 int index = Integer.parseInt(request.getParameter("index"));
2479 getOleeResourceHelperService().updateVendorInfo(oleeResourceRecordDocument);
2480
2481 if (oleeResourceRecordDocument.getOleERSContacts() != null && oleeResourceRecordDocument.getOleERSContacts().size() >= index) {
2482 OLEEResourceContacts oleeResourceContacts = oleeResourceRecordDocument.getOleERSContacts().get(index);
2483 oleEResourceRecordForm.setVendorNameForContacts(oleeResourceContacts.getOrganization());
2484 oleEResourceRecordForm.setPhoneNos(oleeResourceContacts.getOlePhoneNumbers());
2485 }
2486 }
2487
2488 return getUIFModelAndView(oleEResourceRecordForm);
2489 }
2490
2491
2492 @RequestMapping(params = "methodToCall=deleteEresource")
2493 public ModelAndView deleteEresource(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2494 HttpServletRequest request, HttpServletResponse response) {
2495 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2496 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2497 if (oleeResourceRecordDocument.geteRSInstances().size() == 0 && oleeResourceRecordDocument.getOleLinkedEresources().size() == 0 && oleeResourceRecordDocument.getOleERSPOItems().size() == 0 && oleeResourceRecordDocument.getOleERSLicenseRequests().size() == 0) {
2498 getBusinessObjectService().delete(oleeResourceRecordDocument);
2499 } else {
2500 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_INFO, OLEConstants.OLEEResourceRecord.ERROR_LINKED_RECORD);
2501 return getUIFModelAndView(oleEResourceRecordForm);
2502 }
2503 String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + "?selectedTab=oleSelectAcquire";
2504 return performRedirect(oleEResourceRecordForm, url);
2505 }
2506
2507 @RequestMapping(params = "methodToCall=refreshPOSection")
2508 public ModelAndView refreshPOSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2509 HttpServletRequest request, HttpServletResponse response) {
2510 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm;
2511 return getUIFModelAndView(oleeResourceRecordForm);
2512 }
2513
2514
2515 @RequestMapping(params = "methodToCall=populateAccountingLinesToEResource")
2516 public ModelAndView populateAccountingLinesToEResource(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2517 HttpServletRequest request, HttpServletResponse response) {
2518 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2519 oleEResourceRecordForm.setPoSuccessMessage(null);
2520 oleEResourceRecordForm.setPoErrorMessage(null);
2521 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2522
2523
2524 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
2525 selectedCollectionPath);
2526 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
2527 Object eventObject = ObjectPropertyUtils.getPropertyValue(oleEResourceRecordForm, addLinePath);
2528 OleFundCode oleFundCode = (OleFundCode) eventObject;
2529 if (oleFundCode != null) {
2530 if (StringUtils.isBlank(oleFundCode.getFundCode())) {
2531 oleEResourceRecordForm.setPoErrorMessage("Fund Code is required.");
2532 return getUIFModelAndView(oleEResourceRecordForm);
2533 } else {
2534 Map fundMap = new HashMap();
2535 fundMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleFundCode.getFundCode());
2536 OleFundCode fundCode = getBusinessObjectService().findByPrimaryKey(OleFundCode.class, fundMap);
2537 if (fundCode == null) {
2538 oleEResourceRecordForm.setPoErrorMessage("Fund Code is invalid.");
2539 return getUIFModelAndView(oleEResourceRecordForm);
2540 } else {
2541 if (fundCode.getOleFundCodeAccountingLineList() != null) {
2542 Map<String, String> actionParameters = form.getActionParameters();
2543 String mainCollectionIndex = StringUtils.substringBefore(StringUtils.substringAfter(actionParameters.get(UifParameters.SELLECTED_COLLECTION_PATH), "["), "]");
2544 int mainIndex = Integer.parseInt(mainCollectionIndex);
2545 OLECreatePO oleCreatePO = oleEResourceRecordForm.geteResourcePOs().get(mainIndex);
2546 if (oleCreatePO != null) {
2547 oleFundCode.setFundCode(null);
2548 for (OleFundCodeAccountingLine oleFundCodeAccountingLine : fundCode.getOleFundCodeAccountingLineList()) {
2549 OLECretePOAccountingLine oleCretePOAccountingLine = new OLECretePOAccountingLine();
2550 oleCretePOAccountingLine.setChartOfAccountsCode(oleFundCodeAccountingLine.getChartCode());
2551 oleCretePOAccountingLine.setAccountNumber(oleFundCodeAccountingLine.getAccountNumber());
2552 oleCretePOAccountingLine.setSubAccountNumber(oleFundCodeAccountingLine.getSubAccount());
2553 oleCretePOAccountingLine.setFinancialObjectCode(oleFundCodeAccountingLine.getObjectCode());
2554 oleCretePOAccountingLine.setFinancialSubObjectCode(oleFundCodeAccountingLine.getSubObject());
2555 oleCretePOAccountingLine.setProjectCode(oleFundCodeAccountingLine.getProject());
2556 oleCretePOAccountingLine.setOrganizationReferenceId(oleFundCodeAccountingLine.getOrgRefId());
2557 oleCretePOAccountingLine.setAccountLinePercent(oleFundCodeAccountingLine.getPercentage());
2558 oleCreatePO.getAccountingLines().add(oleCretePOAccountingLine);
2559 }
2560 }
2561 }
2562 }
2563 }
2564 }
2565 return getUIFModelAndView(oleEResourceRecordForm);
2566 }
2567
2568
2569 @RequestMapping(params = "methodToCall=populateAccountingLinesToInstance")
2570 public ModelAndView populateAccountingLinesToInstance(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2571 HttpServletRequest request, HttpServletResponse response) {
2572 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2573 oleEResourceRecordForm.setPoSuccessMessage(null);
2574 oleEResourceRecordForm.setPoErrorMessage(null);
2575 String selectedCollectionId = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2576
2577
2578 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
2579 selectedCollectionId);
2580 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
2581 Object eventObject = ObjectPropertyUtils.getPropertyValue(oleEResourceRecordForm, addLinePath);
2582 OleFundCode oleFundCode = (OleFundCode) eventObject;
2583 if (oleFundCode != null) {
2584 if (StringUtils.isBlank(oleFundCode.getFundCode())) {
2585 oleEResourceRecordForm.setPoErrorMessage("Fund Code is required.");
2586 return getUIFModelAndView(oleEResourceRecordForm);
2587 } else {
2588 Map fundMap = new HashMap();
2589 fundMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleFundCode.getFundCode());
2590 OleFundCode fundCode = getBusinessObjectService().findByPrimaryKey(OleFundCode.class, fundMap);
2591 if (fundCode == null) {
2592 oleEResourceRecordForm.setPoErrorMessage("Fund Code is invalid.");
2593 return getUIFModelAndView(oleEResourceRecordForm);
2594 } else {
2595 if (fundCode.getOleFundCodeAccountingLineList() != null) {
2596 Map<String, String> actionParameters = form.getActionParameters();
2597 String mainCollectionIndex = StringUtils.substringBefore(StringUtils.substringAfter(actionParameters.get(UifParameters.SELLECTED_COLLECTION_PATH), "["), "]");
2598 int mainIndex = Integer.parseInt(mainCollectionIndex);
2599 OLECreatePO oleCreatePO = oleEResourceRecordForm.getInstancePOs().get(mainIndex);
2600 if (oleCreatePO != null) {
2601 oleFundCode.setFundCode(null);
2602 for (OleFundCodeAccountingLine oleFundCodeAccountingLine : fundCode.getOleFundCodeAccountingLineList()) {
2603 OLECretePOAccountingLine oleCretePOAccountingLine = new OLECretePOAccountingLine();
2604 oleCretePOAccountingLine.setChartOfAccountsCode(oleFundCodeAccountingLine.getChartCode());
2605 oleCretePOAccountingLine.setAccountNumber(oleFundCodeAccountingLine.getAccountNumber());
2606 oleCretePOAccountingLine.setSubAccountNumber(oleFundCodeAccountingLine.getSubAccount());
2607 oleCretePOAccountingLine.setFinancialObjectCode(oleFundCodeAccountingLine.getObjectCode());
2608 oleCretePOAccountingLine.setFinancialSubObjectCode(oleFundCodeAccountingLine.getSubObject());
2609 oleCretePOAccountingLine.setProjectCode(oleFundCodeAccountingLine.getProject());
2610 oleCretePOAccountingLine.setOrganizationReferenceId(oleFundCodeAccountingLine.getOrgRefId());
2611 oleCretePOAccountingLine.setAccountLinePercent(oleFundCodeAccountingLine.getPercentage());
2612 oleCreatePO.getAccountingLines().add(oleCretePOAccountingLine);
2613 }
2614 }
2615 }
2616 }
2617 }
2618 }
2619 return getUIFModelAndView(oleEResourceRecordForm);
2620 }
2621
2622
2623 @RequestMapping(params = "methodToCall=addAccountingLine")
2624 public ModelAndView addAccountingLine(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2625 HttpServletRequest request, HttpServletResponse response) {
2626 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2627 oleEResourceRecordForm.setPoSuccessMessage(null);
2628 oleEResourceRecordForm.setPoErrorMessage(null);
2629 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2630 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
2631 selectedCollectionPath);
2632 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
2633 Object eventObject = ObjectPropertyUtils.getPropertyValue(oleEResourceRecordForm, addLinePath);
2634 OLECretePOAccountingLine accountingLine = (OLECretePOAccountingLine) eventObject;
2635 if (StringUtils.isEmpty(accountingLine.getChartOfAccountsCode()) || StringUtils.isEmpty(accountingLine.getAccountNumber()) || StringUtils.isEmpty(accountingLine.getFinancialObjectCode()) || ObjectUtils.isNull(accountingLine.getAccountLinePercent())) {
2636 oleEResourceRecordForm.setPoErrorMessage("Please fill all mandatory fields.");
2637 return getUIFModelAndView(oleEResourceRecordForm);
2638 } else {
2639 String errorMessage = new String();
2640 errorMessage = getOleEResourceSearchService().validateAccountingLines(errorMessage, accountingLine);
2641 if (errorMessage.length() > 0) {
2642 Map<String, String> actionParameters = form.getActionParameters();
2643 String mainCollectionIndex = StringUtils.substringBefore(StringUtils.substringAfter(actionParameters.get(UifParameters.SELLECTED_COLLECTION_PATH), "["), "]");
2644 int mainIndex = Integer.parseInt(mainCollectionIndex);
2645 OLECreatePO oleCreatePO = oleEResourceRecordForm.getInstancePOs().get(mainIndex);
2646 errorMessage = errorMessage.concat(" for '" + oleCreatePO.getTitle() + "'");
2647 errorMessage = errorMessage.concat(OLEConstants.BREAK);
2648 oleEResourceRecordForm.setPoErrorMessage(errorMessage);
2649 return getUIFModelAndView(oleEResourceRecordForm);
2650 }
2651 }
2652 return addLine(oleEResourceRecordForm, result, request, response);
2653 }
2654
2655
2656 @RequestMapping(params = "methodToCall=deleteAccountingLine")
2657 public ModelAndView deleteAccountingLine(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2658 HttpServletRequest request, HttpServletResponse response) {
2659 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2660 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2661
2662 int selectedPoIndex = Integer.parseInt(selectedCollectionPath.split("\\[")[1].substring(0, 1));
2663
2664 OLECreatePO selectedPo = oleEResourceRecordForm.geteResourcePOs().get(selectedPoIndex);
2665
2666 int selectedLineIndex = -1;
2667 String selectedLine = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX);
2668 if (StringUtils.isNotBlank(selectedLine)) {
2669 selectedLineIndex = Integer.parseInt(selectedLine);
2670 }
2671 if (selectedLineIndex == -1) {
2672 throw new RuntimeException("Selected line index was not set for delete line action, cannot delete line");
2673 }
2674 selectedPo.getAccountingLines().remove(selectedLineIndex);
2675 return getUIFModelAndView(oleEResourceRecordForm);
2676 }
2677
2678 @RequestMapping(params = "methodToCall=addEResAccountingLine")
2679 public ModelAndView addEResAccountingLine(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2680 HttpServletRequest request, HttpServletResponse response) {
2681 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2682 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELLECTED_COLLECTION_PATH);
2683 CollectionGroup collectionGroup = form.getPostedView().getViewIndex().getCollectionGroupByPath(
2684 selectedCollectionPath);
2685 String addLinePath = collectionGroup.getAddLineBindingInfo().getBindingPath();
2686 Object eventObject = ObjectPropertyUtils.getPropertyValue(oleEResourceRecordForm, addLinePath);
2687 OLEEResourceAccountingLine accountingLine = (OLEEResourceAccountingLine) eventObject;
2688 if (StringUtils.isEmpty(accountingLine.getChartOfAccountsCode()) || StringUtils.isEmpty(accountingLine.getAccountNumber()) || StringUtils.isEmpty(accountingLine.getFinancialObjectCode()) || ObjectUtils.isNull(accountingLine.getAccountLinePercent())) {
2689 GlobalVariables.getMessageMap().putErrorForSectionId("OLEEResourceMainTab-AccountingLines", OLEConstants.OLEEResourceRecord.ERROR_FILL_MANDATORY_FIELDS);
2690 return getUIFModelAndView(oleEResourceRecordForm);
2691 } else {
2692 if (getOleEResourceSearchService().validateAccountingLines(accountingLine, "OLEEResourceMainTab-AccountingLines")) {
2693 return getUIFModelAndView(oleEResourceRecordForm);
2694 }
2695 }
2696 return addLine(oleEResourceRecordForm, result, request, response);
2697 }
2698
2699 @RequestMapping(params = "methodToCall=populateAccountingLines")
2700 public ModelAndView populateAccountingLines(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2701 HttpServletRequest request, HttpServletResponse response) {
2702 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2703 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2704 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())) {
2705 Map fundMap = new HashMap();
2706 fundMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleeResourceRecordDocument.getFundCode());
2707 OleFundCode fundCode = getBusinessObjectService().findByPrimaryKey(OleFundCode.class, fundMap);
2708 if (fundCode == null) {
2709 GlobalVariables.getMessageMap().putErrorForSectionId("OLEEResourceMainTab-FundCode", OLEConstants.OLEEResourceRecord.ERROR_INVALID_FUND_CODE);
2710 return getUIFModelAndView(oleEResourceRecordForm);
2711 } else {
2712 if (fundCode.getOleFundCodeAccountingLineList() != null) {
2713 oleeResourceRecordDocument.setFundCode(null);
2714 for (OleFundCodeAccountingLine oleFundCodeAccountingLine : fundCode.getOleFundCodeAccountingLineList()) {
2715 OLEEResourceAccountingLine oleeResourceAccountingLine = new OLEEResourceAccountingLine();
2716 oleeResourceAccountingLine.setChartOfAccountsCode(oleFundCodeAccountingLine.getChartCode());
2717 oleeResourceAccountingLine.setAccountNumber(oleFundCodeAccountingLine.getAccountNumber());
2718 oleeResourceAccountingLine.setSubAccountNumber(oleFundCodeAccountingLine.getSubAccount());
2719 oleeResourceAccountingLine.setFinancialObjectCode(oleFundCodeAccountingLine.getObjectCode());
2720 oleeResourceAccountingLine.setFinancialSubObjectCode(oleFundCodeAccountingLine.getSubObject());
2721 oleeResourceAccountingLine.setProjectCode(oleFundCodeAccountingLine.getProject());
2722 oleeResourceAccountingLine.setOrganizationReferenceId(oleFundCodeAccountingLine.getOrgRefId());
2723 oleeResourceAccountingLine.setAccountLinePercent(oleFundCodeAccountingLine.getPercentage());
2724 oleeResourceRecordDocument.getAccountingLines().add(oleeResourceAccountingLine);
2725 }
2726 }
2727 }
2728 }
2729 return getUIFModelAndView(oleEResourceRecordForm);
2730 }
2731
2732 @RequestMapping(params = "methodToCall=startAccessWorkflow")
2733 public ModelAndView startAccessWorkflow(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
2734 HttpServletRequest request, HttpServletResponse response) {
2735 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
2736 oleEResourceRecordForm.setMessage(null);
2737 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
2738 OLEAccessActivationWorkFlow accessActivationWorkFlow = null;
2739 MaintenanceDocument newDocument = null;
2740 getOleeResourceHelperService().deleteMaintenanceLock();
2741 org.kuali.rice.krad.service.DocumentService documentService = GlobalResourceLoader.getService(OLEConstants.DOCUMENT_HEADER_SERVICE);
2742 try {
2743 newDocument = (MaintenanceDocument) documentService.getNewDocument("OLE_ERES_ACCESS_MD");
2744 } catch (Exception e) {
2745 e.printStackTrace();
2746 }
2747 newDocument.getDocumentHeader().setDocumentDescription(OLEConstants.ACCESS_ACTIVATION_DESCRIPTION + " for E-Resource Name : "+oleeResourceRecordDocument.getTitle());
2748 OLEEResourceAccessActivation oleeResourceAccess = (OLEEResourceAccessActivation) newDocument.getNewMaintainableObject().getDataObject();
2749 oleeResourceAccess.setDateAccessConfirmed(oleeResourceRecordDocument.getDateAccessConfirmed());
2750 oleeResourceAccess.setWorkflowId(oleeResourceRecordDocument.getWorkflowConfigurationId());
2751 oleeResourceAccess.setOleERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier());
2752 Map<String, String> accessConfigMap = new HashMap<String, String>();
2753 accessConfigMap.put("accessActivationConfigurationId", oleeResourceRecordDocument.getWorkflowConfigurationId());
2754 List<OLEAccessActivationWorkFlow> oleAccessActivationWorkFlows = (List<OLEAccessActivationWorkFlow>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(OLEAccessActivationWorkFlow.class, accessConfigMap, "orderNo", true);
2755 if (oleAccessActivationWorkFlows != null && oleAccessActivationWorkFlows.size() > 0) {
2756 OLEEResourceAccessWorkflow oleeResourceAccessWorkflow = new OLEEResourceAccessWorkflow();
2757 oleeResourceAccessWorkflow.setDescription(oleeResourceRecordDocument.getAccessDescription());
2758 oleeResourceAccessWorkflow.setLastApproved(new Timestamp(System.currentTimeMillis()));
2759 oleeResourceAccess.getOleERSAccessWorkflows().add(oleeResourceAccessWorkflow);
2760 boolean found = false;
2761 for (int i = 0; i < oleAccessActivationWorkFlows.size(); i++) {
2762 accessActivationWorkFlow = oleAccessActivationWorkFlows.get(i);
2763 oleeResourceAccess.setAccessStatus(accessActivationWorkFlow.getStatus());
2764 List<Principal> principals = getOleAccessActivationService().getPrincipals(accessActivationWorkFlow);
2765 StringBuffer currentOwnerBuffer = new StringBuffer();
2766 if (principals != null && principals.size() > 0) {
2767 oleeResourceAccessWorkflow.setStatus(accessActivationWorkFlow.getStatus());
2768 found = true;
2769 List<AdHocRouteRecipient> adHocRouteRecipientList = new ArrayList<AdHocRouteRecipient>();
2770 for (Principal principal : principals) {
2771 currentOwnerBuffer.append(principal.getPrincipalName() + ",");
2772 AdHocRoutePerson adHocRoutePerson = new AdHocRoutePerson();
2773 adHocRoutePerson.setId(principal.getPrincipalId());
2774 adHocRoutePerson.setName(principal.getPrincipalName());
2775 adHocRoutePerson.setActionRequested("A");
2776 adHocRoutePerson.setdocumentNumber(newDocument.getDocumentNumber());
2777 adHocRoutePerson.setType(0);
2778 adHocRouteRecipientList.add(adHocRoutePerson);
2779 }
2780 if (currentOwnerBuffer.length() > 0) {
2781 oleeResourceAccessWorkflow.setCurrentOwner(currentOwnerBuffer.substring(0, currentOwnerBuffer.length() - 1));
2782 }
2783 try {
2784 if(StringUtils.isNotEmpty(accessActivationWorkFlow.getRoleId())) {
2785 Role role = KimApiServiceLocator.getRoleService().getRole(accessActivationWorkFlow.getRoleId());
2786 getDocumentService().routeDocument(newDocument, "Needed Approval for the status : " + accessActivationWorkFlow.getStatus() + " from the members of the Role : " + role.getName(), adHocRouteRecipientList);
2787 } else {
2788 getDocumentService().routeDocument(newDocument, "Needed Approval for the status : " + accessActivationWorkFlow.getStatus() + " from the members of the Role : " + "", adHocRouteRecipientList);
2789 }
2790 List<ActionTakenValue> actionTakenList = (List<ActionTakenValue>) KEWServiceLocator.getActionTakenService().getActionsTaken(newDocument.getDocumentNumber());
2791 ActionTakenValue actionTakenValue = (ActionTakenValue) actionTakenList.get(actionTakenList.size() - 1);
2792 actionTakenValue.setAnnotation("Initiated the access activation workflow");
2793 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
2794 oleeResourceRecordDocument.setOleAccessActivationDocumentNumber(newDocument.getDocumentNumber());
2795 getOleeResourceHelperService().deleteMaintenanceLock();
2796 } catch (Exception e) {
2797 e.printStackTrace();
2798 }
2799 break;
2800 }
2801 }
2802 if (!found) {
2803 try {
2804 getOleeResourceHelperService().setWorkflowCompletedStatus(oleeResourceAccess, newDocument, true);
2805 oleeResourceRecordDocument.setOleAccessActivationDocumentNumber(newDocument.getDocumentNumber());
2806 return getUIFModelAndView(form);
2807 } catch (Exception e) {
2808 e.printStackTrace();
2809 }
2810 }
2811 } else {
2812 oleEResourceRecordForm.setMessage(ConfigContext.getCurrentContextConfig().getProperty(OLEConstants.NO_WORKFLOW_SELECTED));
2813 return getUIFModelAndView(form);
2814 }
2815 return getUIFModelAndView(form);
2816 }
2817
2818
2819
2820
2821 @RequestMapping(params = "methodToCall=renewOrCancelEresourceDocument")
2822 public ModelAndView renewOrCancelEresourceDocument(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2823 HttpServletRequest request, HttpServletResponse response) {
2824 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
2825 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
2826 OLEAccessActivationWorkFlow accessActivationWorkFlow = null;
2827 Map<String, String> accessConfigMap = new HashMap<String, String>();
2828 accessConfigMap.put("accessActivationConfigurationId", oleeResourceRecordDocument.getEresourceWorkflowIndication());
2829 List<OLEAccessActivationWorkFlow> oleAccessActivationWorkFlows = (List<OLEAccessActivationWorkFlow>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(OLEAccessActivationWorkFlow.class, accessConfigMap, "orderNo", true);
2830 if (oleAccessActivationWorkFlows != null && oleAccessActivationWorkFlows.size() > 0) {
2831 boolean found = false;
2832 for (int i = 0; i < oleAccessActivationWorkFlows.size(); i++) {
2833 accessActivationWorkFlow = oleAccessActivationWorkFlows.get(i);
2834 oleeResourceRecordDocument.setWorkflowStatus(accessActivationWorkFlow.getStatus());
2835 List<AdHocRoutePerson> adHocRouteRecipients = new ArrayList<AdHocRoutePerson>();
2836 List<Principal> principals = getOleAccessActivationService().getPrincipals(accessActivationWorkFlow);
2837 AdHocRoutePerson adHocRoutePerson;
2838 StringBuffer currentOwnerBuffer = new StringBuffer();
2839 if (principals != null && principals.size() > 0) {
2840 found = true;
2841 for (Principal principal : principals) {
2842 currentOwnerBuffer.append(principal.getPrincipalName() + ",");
2843 adHocRoutePerson = new AdHocRoutePerson();
2844 adHocRoutePerson.setId(principal.getPrincipalId());
2845 adHocRoutePerson.setName(principal.getPrincipalName());
2846 adHocRoutePerson.setActionRequested("A");
2847 adHocRoutePerson.setdocumentNumber(oleeResourceRecordDocument.getDocumentNumber());
2848 adHocRoutePerson.setType(0);
2849 adHocRouteRecipients.add(adHocRoutePerson);
2850 } List<AdHocRouteRecipient> adHocRouteRecipientList = new ArrayList<AdHocRouteRecipient>();
2851 adHocRouteRecipientList.addAll(adHocRouteRecipients);
2852 try {
2853 if(StringUtils.isNotEmpty(accessActivationWorkFlow.getRoleId())) {
2854 Role role = KimApiServiceLocator.getRoleService().getRole(accessActivationWorkFlow.getRoleId());
2855 getDocumentService().routeDocument(oleeResourceRecordDocument, "Needed Approval for the status : " + accessActivationWorkFlow.getStatus() + " from the members of the Role : " + role.getName(), adHocRouteRecipientList);
2856 } else {
2857 getDocumentService().routeDocument(oleeResourceRecordDocument, "Needed Approval for the status : " + accessActivationWorkFlow.getStatus() + " from the members of the Role : " + "", adHocRouteRecipientList);
2858 }
2859
2860
2861 List<ActionTakenValue> actionTakenList = (List<ActionTakenValue>) KEWServiceLocator.getActionTakenService().getActionsTaken(oleeResourceRecordDocument.getDocumentNumber());
2862 ActionTakenValue actionTakenValue = (ActionTakenValue) actionTakenList.get(actionTakenList.size() - 1);
2863 actionTakenValue.setAnnotation("Initiated the Renew/Cancel workflow");
2864 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
2865 } catch (Exception e) {
2866 e.printStackTrace();
2867 }
2868 break;
2869 }
2870 }
2871 if (!found) {
2872 try {
2873 DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(oleeResourceRecordDocument.getDocumentNumber());
2874 documentBo.setDocRouteStatus("S");
2875 getBusinessObjectService().save(documentBo);
2876 getDocumentService().saveDocument(oleeResourceRecordDocument);
2877 List<ActionRequestValue> actionRequestValueList = KEWServiceLocator.getActionRequestService().findAllPendingRequests(oleeResourceRecordDocument.getDocumentNumber());
2878 KEWServiceLocator.getActionRequestService().deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2879 KEWServiceLocator.getActionListService().deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2880 ActionTakenValue actionTakenValue;
2881 for (ActionRequestValue actionRequestValue : actionRequestValueList) {
2882 if (actionRequestValue.getPrincipalId().equalsIgnoreCase(GlobalVariables.getUserSession().getPrincipalId())) {
2883 actionTakenValue = new ActionTakenValue();
2884 actionTakenValue.setAnnotation("Approved status : " + oleeResourceRecordDocument.getWorkflowStatus());
2885 actionTakenValue.setActionDate(new Timestamp(System.currentTimeMillis()));
2886 actionTakenValue.setActionTaken("A");
2887 actionTakenValue.setDocumentId(actionRequestValue.getDocumentId());
2888 actionTakenValue.setPrincipalId(actionRequestValue.getPrincipalId());
2889 actionTakenValue.setDocVersion(1);
2890 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
2891 }
2892 }
2893
2894 return getUIFModelAndView(form);
2895 } catch (Exception e) {
2896 e.printStackTrace();
2897 }
2898 }
2899 String backDoorUser = request.getParameter("backdoorId");
2900 if(backDoorUser == null){
2901 backDoorUser = GlobalVariables.getUserSession().getPrincipalId();
2902 }else{
2903 if(backDoorUser.contains("=")){
2904 backDoorUser=backDoorUser.split("=")[1];
2905 }
2906 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(backDoorUser);
2907 backDoorUser = person.getPrincipalId();
2908 }
2909 List<ActionItem> actionItems = (List<ActionItem>)KEWServiceLocator.getActionListService().findByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2910 if(actionItems!=null && actionItems.size()>0){
2911 for(ActionItem actionItem : actionItems){
2912 if(backDoorUser.equals(actionItem.getPrincipalId())){
2913 form.setCanApprove(true);
2914 }else{
2915 form.setCanApprove(false);
2916 }
2917 }
2918 }
2919 } else {
2920 GlobalVariables.getMessageMap().putError("accessActivationConfigurationId", OLEConstants.OLEEResourceRecord.ERROR_INVALID_WORKFLOW);
2921 return getUIFModelAndView(form);
2922 }
2923 return getUIFModelAndView(form);
2924 }
2925
2926
2927
2928
2929 @RequestMapping(params = "methodToCall=approveRenewOrCancelEresource")
2930 public ModelAndView approveRenewOrCancelEresource(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
2931 HttpServletRequest request, HttpServletResponse response) {
2932 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
2933 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
2934 String backDoorUser = request.getParameter("backdoorId");
2935 if(backDoorUser == null){
2936 backDoorUser = GlobalVariables.getUserSession().getPrincipalId();
2937 }else{
2938 if(backDoorUser.contains("=")){
2939 backDoorUser=backDoorUser.split("=")[1];
2940 }
2941 Person person = KimApiServiceLocator.getPersonService().getPersonByPrincipalName(backDoorUser);
2942 backDoorUser = person.getPrincipalId();
2943 }
2944 String previousStatus = oleeResourceRecordDocument.getWorkflowStatus();
2945 ActionRequestService actionRequestService = KEWServiceLocator.getActionRequestService();
2946 Map<String, String> accessConfigMap = new HashMap<String, String>();
2947 accessConfigMap.put("accessActivationConfigurationId", oleeResourceRecordDocument.getEresourceWorkflowIndication());
2948 List<OLEAccessActivationWorkFlow> oleAccessActivationWorkFlows = (List<OLEAccessActivationWorkFlow>) KRADServiceLocator.getBusinessObjectService().findMatchingOrderBy(OLEAccessActivationWorkFlow.class, accessConfigMap, "orderNo", true);
2949 OLEAccessActivationWorkFlow accessActivationWorkFlow = null;
2950 if (oleAccessActivationWorkFlows != null && oleAccessActivationWorkFlows.size() > 0) {
2951 for (int i = 0; i < oleAccessActivationWorkFlows.size(); i++) {
2952 if (oleAccessActivationWorkFlows.get(i).getStatus().equals(oleeResourceRecordDocument.getWorkflowStatus())) {
2953 if (i + 1 < oleAccessActivationWorkFlows.size()) {
2954 accessActivationWorkFlow = oleAccessActivationWorkFlows.get(i + 1);
2955 oleeResourceRecordDocument.setWorkflowStatus(accessActivationWorkFlow.getStatus());
2956 List<AdHocRoutePerson> adHocRouteRecipients = new ArrayList<AdHocRoutePerson>();
2957 List<Principal> principals = getOleAccessActivationService().getPrincipals(accessActivationWorkFlow);
2958 StringBuffer currentOwnerBuffer = new StringBuffer();
2959 List<String> principalIds = new ArrayList<String>();
2960 AdHocRoutePerson adHocRoutePerson;
2961 if (principals != null && principals.size() > 0) {
2962 for (Principal principal : principals) {
2963 currentOwnerBuffer.append(principal.getPrincipalName() + ",");
2964 adHocRoutePerson = new AdHocRoutePerson();
2965 adHocRoutePerson.setId(principal.getPrincipalId());
2966 adHocRoutePerson.setName(principal.getPrincipalName());
2967 adHocRoutePerson.setActionRequested("A");
2968 adHocRoutePerson.setdocumentNumber(form.getDocument().getDocumentNumber());
2969 adHocRoutePerson.setType(0);
2970 adHocRouteRecipients.add(adHocRoutePerson);
2971 principalIds.add(principal.getPrincipalId());
2972 }
2973 List<AdHocRouteRecipient> adHocRouteRecipientList = combineAdHocRecipients(form);
2974 adHocRouteRecipientList.addAll(adHocRouteRecipients);
2975 actionRequestService.deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2976 try{
2977 if(StringUtils.isNotEmpty(accessActivationWorkFlow.getRoleId())) {
2978 Role role = KimApiServiceLocator.getRoleService().getRole(accessActivationWorkFlow.getRoleId());
2979 getDocumentService().approveDocument(form.getDocument(), "Needed Approval for the status : " + oleeResourceRecordDocument.getWorkflowStatus() + " from the members of the Role :" + role.getName(), adHocRouteRecipientList);
2980 } else {
2981 getDocumentService().approveDocument(form.getDocument(), "Needed Approval for the status : " + oleeResourceRecordDocument.getWorkflowStatus() + " from the members of the Role :" + "", adHocRouteRecipientList);
2982 }
2983 List<ActionTakenValue> actionTakenList = (List<ActionTakenValue>) KEWServiceLocator.getActionTakenService().getActionsTaken(oleeResourceRecordDocument.getDocumentNumber());
2984 ActionTakenValue actionTakenValue = (ActionTakenValue) actionTakenList.get(actionTakenList.size() - 1);
2985 actionTakenValue.setAnnotation("Approved Status : " + previousStatus);
2986 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
2987 KEWServiceLocator.getActionListService().deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2988 }catch(Exception e){
2989
2990 }
2991 break;
2992 }
2993 } else {
2994 try{
2995 getDocumentService().saveDocument(oleeResourceRecordDocument);
2996 List<ActionRequestValue> actionRequestValueList = KEWServiceLocator.getActionRequestService().findAllPendingRequests(oleeResourceRecordDocument.getDocumentNumber());
2997 KEWServiceLocator.getActionRequestService().deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2998 KEWServiceLocator.getActionListService().deleteByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
2999 ActionTakenValue actionTakenValue;
3000 for (ActionRequestValue actionRequestValue : actionRequestValueList) {
3001 if (backDoorUser.equalsIgnoreCase(GlobalVariables.getUserSession().getPrincipalId())) {
3002 actionTakenValue = new ActionTakenValue();
3003 actionTakenValue.setAnnotation("Approved status : " + oleeResourceRecordDocument.getWorkflowStatus());
3004 actionTakenValue.setActionDate(new Timestamp(System.currentTimeMillis()));
3005 actionTakenValue.setActionTaken("A");
3006 actionTakenValue.setDocumentId(actionRequestValue.getDocumentId());
3007 actionTakenValue.setPrincipalId(actionRequestValue.getPrincipalId());
3008 actionTakenValue.setDocVersion(1);
3009 KEWServiceLocator.getActionTakenService().saveActionTaken(actionTakenValue);
3010 }
3011 }
3012 }catch(Exception e){
3013 e.printStackTrace();
3014 }
3015 form.setCanApprove(false);
3016 DocumentRouteHeaderValue documentBo = KEWServiceLocator.getRouteHeaderService().getRouteHeader(oleeResourceRecordDocument.getDocumentNumber());
3017 documentBo.setDocRouteStatus("S");
3018 getBusinessObjectService().save(documentBo);
3019
3020 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, RiceKeyConstants.MESSAGE_ROUTE_APPROVED);
3021 return getUIFModelAndView(form);
3022 }
3023 }
3024 }
3025 }
3026 List<ActionItem> actionItems = (List<ActionItem>)KEWServiceLocator.getActionListService().findByDocumentId(oleeResourceRecordDocument.getDocumentNumber());
3027
3028 if(actionItems!=null && actionItems.size()>0){
3029 for(ActionItem actionItem : actionItems){
3030 if(backDoorUser.equals(actionItem.getPrincipalId())){
3031 form.setCanApprove(true);
3032 }else{
3033 form.setCanApprove(false);
3034 }
3035 }
3036 }
3037 GlobalVariables.getMessageMap().putInfo(KRADConstants.GLOBAL_MESSAGES, RiceKeyConstants.MESSAGE_ROUTE_APPROVED);
3038 return super.navigate(form, result, request, response);
3039
3040 }
3041
3042 @RequestMapping(params = "methodToCall=downloadEventAttachment1")
3043 public ModelAndView downloadEventAttachment1(@ModelAttribute("KualiForm") TransactionalDocumentFormBase form, BindingResult result,
3044 HttpServletRequest request, HttpServletResponse response) throws Exception {
3045 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
3046 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
3047 int index = Integer.parseInt(oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
3048 OLEEResourceEventLog oleeResourceEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(index);
3049 getOleEResourceSearchService().downloadAttachment(response, oleeResourceEventLog.getOleEResEventLogID(), oleeResourceEventLog.getAttachmentFileName1(), oleeResourceEventLog.getAttachmentContent1(), oleeResourceEventLog.getAttachmentMimeType1());
3050 return super.navigate(oleEResourceRecordForm, result, request, response);
3051 }
3052
3053 @RequestMapping(params = "methodToCall=downloadEventAttachment2")
3054 public ModelAndView downloadEventAttachment2(@ModelAttribute("KualiForm") TransactionalDocumentFormBase form, BindingResult result,
3055 HttpServletRequest request, HttpServletResponse response) throws Exception {
3056 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
3057 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
3058 int index = Integer.parseInt(oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX));
3059 OLEEResourceEventLog oleeResourceEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(index);
3060 getOleEResourceSearchService().downloadAttachment(response, oleeResourceEventLog.getOleEResEventLogID(), oleeResourceEventLog.getAttachmentFileName2(), oleeResourceEventLog.getAttachmentContent2(), oleeResourceEventLog.getAttachmentMimeType2());
3061 return super.navigate(oleEResourceRecordForm, result, request, response);
3062 }
3063
3064 @RequestMapping(params = "methodToCall=saveGokbData")
3065 public ModelAndView saveGokbData(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result,
3066 HttpServletRequest request, HttpServletResponse response) {
3067 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm;
3068 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument();
3069 for (OLEGOKbMappingValue olegoKbMappingValue : oleeResourceRecordDocument.getOleGOKbMappingValueList()) {
3070 if (olegoKbMappingValue.isReset()) {
3071 getBusinessObjectService().delete(olegoKbMappingValue);
3072 }
3073 }
3074 return getUIFModelAndView(form);
3075 }
3076
3077
3078 @RequestMapping(params = "methodToCall=selectAll")
3079 public ModelAndView selectAll(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3080 HttpServletRequest request, HttpServletResponse response) {
3081 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
3082 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
3083 for (OLEGOKbPlatform olegoKbPlatform : oleeResourceRecordDocument.getGoKbPlatformList()) {
3084 for (OLEGOKbTIPP olegoKbTIPP : olegoKbPlatform.getGoKbTIPPList()) {
3085 olegoKbTIPP.setSelect(true);
3086 }
3087 }
3088 return getUIFModelAndView(oleEResourceRecordForm);
3089 }
3090
3091 @RequestMapping(params = "methodToCall=loadEHoldings")
3092 public ModelAndView loadEHoldings(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result,
3093 HttpServletRequest request, HttpServletResponse response) {
3094 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form;
3095 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument();
3096 if (oleeResourceRecordDocument.getOleERSIdentifier() != null) {
3097 Map ids = new HashMap();
3098 ids.put("oleERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier());
3099 List<OLEEResourceInstance> oleeResourceInstances = (List<OLEEResourceInstance>) getBusinessObjectService().findMatching(OLEEResourceInstance.class, ids);
3100 oleeResourceRecordDocument.geteRSInstances().clear();
3101 oleeResourceRecordDocument.geteRSInstances().addAll(oleeResourceInstances);
3102 oleeResourceRecordDocument.setOleERSInstances(oleeResourceInstances);
3103
3104 ids = new HashMap();
3105 List<OLEEResourceInstance> linkedResourceInstances = new ArrayList<>();
3106 for (OLELinkedEresource linkedEresource : oleeResourceRecordDocument.getOleLinkedEresources()) {
3107 if (linkedEresource.getRelationShipType().equalsIgnoreCase("child")) {
3108 ids.put("oleEResourceInstanceId", linkedEresource.getLinkedERSIdentifier());
3109 linkedResourceInstances.addAll(getBusinessObjectService().findMatching(OLEEResourceInstance.class, ids));
3110 for (OLEEResourceLicense oleeResourceLicense : linkedEresource.getOleeResourceRecordDocument().getOleERSLicenseRequests()) {
3111 oleeResourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense);
3112 }
3113 }
3114 }
3115 oleeResourceRecordDocument.geteRSInstances().addAll(linkedResourceInstances);
3116 }
3117 return super.navigate(oleEResourceRecordForm, result, request, response);
3118 }
3119 }
3120
3121