001package org.kuali.ole.select.controller; 002 003import org.apache.commons.lang.StringUtils; 004import org.apache.commons.lang.time.DateUtils; 005import org.apache.log4j.Logger; 006import org.kuali.ole.OLEConstants; 007import org.kuali.ole.alert.bo.AlertBo; 008import org.kuali.ole.alert.controller.OleTransactionalDocumentControllerBase; 009import org.kuali.ole.coa.businessobject.OleFundCode; 010import org.kuali.ole.docstore.common.client.DocstoreClientLocator; 011import org.kuali.ole.docstore.common.document.EHoldings; 012import org.kuali.ole.docstore.common.document.Holdings; 013import org.kuali.ole.docstore.common.document.content.instance.OleHoldings; 014import org.kuali.ole.docstore.common.document.content.instance.xstream.HoldingOlemlRecordProcessor; 015import org.kuali.ole.module.purap.PurapConstants; 016import org.kuali.ole.module.purap.PurapKeyConstants; 017import org.kuali.ole.module.purap.businessobject.PurchaseOrderType; 018import org.kuali.ole.module.purap.document.service.RequisitionService; 019import org.kuali.ole.pojo.OleOrderRecord; 020import org.kuali.ole.select.batch.service.RequisitionCreateDocumentService; 021import org.kuali.ole.select.bo.*; 022import org.kuali.ole.select.businessobject.OleCopy; 023import org.kuali.ole.select.businessobject.OleDocstoreResponse; 024import org.kuali.ole.select.document.*; 025import org.kuali.ole.select.bo.OLECreatePO; 026import org.kuali.ole.select.form.OLEEResourceRecordForm; 027import org.kuali.ole.select.service.OleReqPOCreateDocumentService; 028import org.kuali.ole.service.OLEEResourceHelperService; 029import org.kuali.ole.service.OLEEResourceSearchService; 030import org.kuali.ole.service.OleLicenseRequestWebService; 031import org.kuali.ole.service.impl.OLEEResourceSearchServiceImpl; 032import org.kuali.ole.sys.context.SpringContext; 033import org.kuali.rice.core.api.config.property.ConfigContext; 034import org.kuali.rice.core.api.config.property.ConfigurationService; 035import org.kuali.rice.core.api.resourceloader.GlobalResourceLoader; 036import org.kuali.rice.coreservice.api.CoreServiceApiServiceLocator; 037import org.kuali.rice.coreservice.api.parameter.Parameter; 038import org.kuali.rice.coreservice.api.parameter.ParameterKey; 039import org.kuali.rice.kew.api.exception.WorkflowException; 040import org.kuali.rice.kim.api.identity.Person; 041import org.kuali.rice.kim.api.identity.PersonService; 042import org.kuali.rice.kns.service.KNSServiceLocator; 043import org.kuali.rice.krad.service.BusinessObjectService; 044import org.kuali.rice.krad.service.KRADServiceLocator; 045import org.kuali.rice.krad.service.KRADServiceLocatorWeb; 046import org.kuali.rice.krad.service.KualiRuleService; 047import org.kuali.rice.krad.uif.UifConstants; 048import org.kuali.rice.krad.uif.UifParameters; 049import org.kuali.rice.krad.uif.component.BindingInfo; 050import org.kuali.rice.krad.uif.util.ObjectPropertyUtils; 051import org.kuali.rice.krad.uif.view.View; 052import org.kuali.rice.krad.util.GlobalVariables; 053import org.kuali.rice.krad.util.KRADConstants; 054import org.kuali.rice.krad.web.controller.MethodAccessible; 055import org.kuali.rice.krad.document.TransactionalDocumentControllerBase; 056import org.kuali.rice.krad.web.form.DocumentFormBase; 057import org.kuali.rice.krad.web.form.TransactionalDocumentFormBase; 058import org.kuali.rice.krad.web.form.UifFormBase; 059import org.springframework.stereotype.Controller; 060import org.springframework.validation.BindingResult; 061import org.springframework.web.bind.annotation.ModelAttribute; 062import org.springframework.web.bind.annotation.RequestMapping; 063import org.springframework.web.bind.annotation.RequestMethod; 064import org.springframework.web.servlet.ModelAndView; 065 066import javax.servlet.http.HttpServletRequest; 067import javax.servlet.http.HttpServletResponse; 068import javax.servlet.http.HttpSession; 069import java.io.IOException; 070import java.io.OutputStream; 071import java.sql.*; 072import java.text.DateFormat; 073import java.text.ParseException; 074import java.text.SimpleDateFormat; 075import java.util.*; 076import java.util.Date; 077 078/** 079 * Created with IntelliJ IDEA. 080 * User: srinivasane 081 * Date: 6/21/13 082 * Time: 12:25 PM 083 * To change this template use File | Settings | File Templates. 084 */ 085@Controller 086@RequestMapping(value = "/oleERSController") 087public class OLEEResourceRecordController extends OleTransactionalDocumentControllerBase { 088 089 090 /** 091 * @see org.kuali.rice.krad.web.controller.UifControllerBase#(javax.servlet.http.HttpServletRequest) 092 */ 093 private static final Logger LOG = Logger.getLogger(OLEEResourceRecordController.class); 094 095 private OleLicenseRequestWebService oleLicenseRequestWebService = null; 096 private KualiRuleService kualiRuleService; 097 private BusinessObjectService businessObjectService; 098 private OLEEResourceSearchService oleEResourceSearchService = null; 099 private DocstoreClientLocator docstoreClientLocator; 100 private OLEEResourceHelperService oleeResourceHelperService = new OLEEResourceHelperService(); 101 private OleReqPOCreateDocumentService oleReqPOCreateDocumentService; 102 private RequisitionCreateDocumentService requisitionCreateDocumentService; 103 104 public OLEEResourceHelperService getOleeResourceHelperService() { 105 if(oleeResourceHelperService == null) { 106 oleeResourceHelperService = new OLEEResourceHelperService(); 107 } 108 return oleeResourceHelperService; 109 } 110 111 public DocstoreClientLocator getDocstoreClientLocator() { 112 if (docstoreClientLocator == null) { 113 docstoreClientLocator = SpringContext.getBean(DocstoreClientLocator.class); 114 } 115 return docstoreClientLocator; 116 } 117 118 public OleReqPOCreateDocumentService getOleReqPOCreateDocumentService() { 119 if (oleReqPOCreateDocumentService == null) { 120 oleReqPOCreateDocumentService = SpringContext.getBean(OleReqPOCreateDocumentService.class); 121 } 122 return oleReqPOCreateDocumentService; 123 } 124 125 public RequisitionCreateDocumentService getRequisitionCreateDocumentService() { 126 if (requisitionCreateDocumentService == null) { 127 requisitionCreateDocumentService = SpringContext.getBean(RequisitionCreateDocumentService.class); 128 } 129 return requisitionCreateDocumentService; 130 } 131 132 /** 133 * This method will return new Instance of OLEEResourceRecordForm. 134 * 135 * @return OLEEResourceRecordForm. 136 */ 137 @Override 138 protected TransactionalDocumentFormBase createInitialForm() { 139 OLEEResourceRecordForm oleeResourceRecordForm = new OLEEResourceRecordForm(); 140 oleeResourceRecordForm.setStatusDate(new Date(System.currentTimeMillis()).toString()); 141 oleeResourceRecordForm.setDocumentDescription(OLEConstants.OLEEResourceRecord.NEW_E_RESOURCE_REC); 142 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"); 143 return oleeResourceRecordForm; 144 } 145 146 147 @Override 148 public ModelAndView docHandler(DocumentFormBase form) throws Exception { 149 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form; 150 oleeResourceRecordForm.setSearchUrl(ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + "/ole-kr-krad/oleERSController?viewId=OLEEResourceSearchView&methodToCall=start"); 151 form.getRequest().getSession().setAttribute("formKeyValue", oleeResourceRecordForm.getFormKey()); 152 ModelAndView modelAndView = super.docHandler(oleeResourceRecordForm); 153 OLEEResourceRecordForm kualiForm = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm"); 154 HttpSession session = kualiForm.getRequest().getSession(); 155 //session.removeAttribute("createChileEResource"); 156 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) kualiForm.getDocument(); 157 if(session.getAttribute("createChileEResource") != null){ 158 String oleeResourceInstancesIdentifier = (String) session.getAttribute("oleeResourceInstancesIdentifier"); 159 String[] identifiers = oleeResourceInstancesIdentifier.split(","); 160 Map ids = new HashMap(); 161 for(String identifier : identifiers){ 162 ids.put("oleEResourceInstanceId",identifier); 163 } 164 List<OLEEResourceInstance> oleeResourceInstances = (List<OLEEResourceInstance>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLEEResourceInstance.class, ids); 165 oleeResourceRecordDocument.setOleERSInstances(oleeResourceInstances); 166 } 167 oleeResourceRecordDocument.geteRSInstances().addAll(oleeResourceRecordDocument.getOleERSInstances()); 168 for (OLELinkedEresource oleLinkedEresource : oleeResourceRecordDocument.getOleLinkedEresources()) { 169 if (oleLinkedEresource.getRelationShipType().equalsIgnoreCase("child")) { 170 //Displaying the child EResource instance and Licence info in parent Eresource. 171 if (oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances() != null) { 172 oleeResourceRecordDocument.geteRSInstances().addAll(oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances()); 173 } 174 for (OLEEResourceLicense oleeResourceLicense : oleLinkedEresource.getOleeResourceRecordDocument().getOleERSLicenseRequests()) { 175 oleeResourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense); 176 } 177 } 178 } 179 getOleEResourceSearchService().getPOInvoiceForERS(oleeResourceRecordDocument); 180 /*Displaying the child EResource Po's and invoice in parent E-Resource.*/ 181 //oleEResourceSearchService = new OLO 182 if(oleEResourceSearchService != null){ 183 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument); 184 } 185 String noticePeriod = oleEResourceSearchService.getParameter("NOTICE_PERIOD", OLEConstants.ERESOURCE_CMPNT); 186 String alertEnabled = oleEResourceSearchService.getParameter("ALERT_ENABLED", OLEConstants.ERESOURCE_CMPNT); 187 String user = oleEResourceSearchService.getParameter("USER", OLEConstants.ERESOURCE_CMPNT); 188 oleeResourceRecordDocument.setRenewalNoticePeriod(noticePeriod); 189 if(alertEnabled.equalsIgnoreCase("Y")){ 190 oleeResourceRecordDocument.setRenewalAlertEnabled(true); 191 }else { 192 oleeResourceRecordDocument.setRenewalAlertEnabled(false); 193 } 194 oleeResourceRecordDocument.setRecipientId(user); 195 return modelAndView; 196 } 197 198 /** 199 * This method takes the initial request when click on E-Resource Record Screen. 200 * 201 * @param form 202 * @return ModelAndView 203 */ 204 @Override 205 @RequestMapping(params = "methodToCall=start") 206 public ModelAndView start(@ModelAttribute("KualiForm") UifFormBase form) { 207 LOG.debug("Start -- Start Method of OlePatronRecordForm"); 208 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form; 209 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument(); 210 oleeResourceRecordDocument.setStatusDate(new Date(System.currentTimeMillis()).toString()); 211 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList(); 212 for (OLESearchCondition oleSearchCondition : oleSearchConditions) { 213 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND); 214 } 215 return super.start(oleeResourceRecordForm); 216 } 217 218 /** 219 * This method populates date of the eventlog object thereby adding to the existing list. 220 * 221 * @param uifForm 222 * @param result 223 * @param request 224 * @param response 225 * @return ModelAndView 226 */ 227 @RequestMapping(params = "methodToCall=addEventLogLine") 228 public ModelAndView addEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 229 HttpServletRequest request, HttpServletResponse response) { 230 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 231 String selectedCollectionPath = form.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH); 232 String selectedCollectionId = form.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID); 233 BindingInfo addLineBindingInfo = (BindingInfo) form.getViewPostMetadata().getComponentPostData( 234 selectedCollectionId, UifConstants.PostMetadata.ADD_LINE_BINDING_INFO); 235 236 String addLinePath = addLineBindingInfo.getBindingPath(); 237 Object eventObject = ObjectPropertyUtils.getPropertyValue(uifForm, addLinePath); 238 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 239 OLEEResourceEventLog oleERSEventLog = (OLEEResourceEventLog) eventObject; 240 oleERSEventLog.setEventType(OLEConstants.OleLicenseRequest.USER); 241 oleERSEventLog.setCurrentTimeStamp(); 242 oleERSEventLog.setOleERSIdentifier(oleeResourceRecordDocument.getDocumentNumber()); 243 return addLine(uifForm); 244 } 245 246 /** 247 * This method populates date of the eventlog object thereby adding to the existing list. 248 * 249 * @param uifForm 250 * @param result 251 * @param request 252 * @param response 253 * @return ModelAndView 254 */ 255 @RequestMapping(params = "methodToCall=deleteEventLogLine") 256 public ModelAndView deleteEventLogLine(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 257 HttpServletRequest request, HttpServletResponse response) { 258 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 259 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 260 String selectedLineIndex = form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); 261 OLEEResourceEventLog oleERSEventLog = oleeResourceRecordDocument.getOleERSEventLogs().get(Integer.parseInt(selectedLineIndex)); 262 //KRADServiceLocatorWeb.getLegacyDataAdapter().delete(oleERSEventLog); 263 return deleteLine(form); 264 } 265 266 /** 267 * This method Creates the License Request Document and link to the E-Resource document 268 * 269 * @param form 270 * @param result 271 * @param request 272 * @param response 273 * @return ModelAndView 274 */ 275 @RequestMapping(params = "methodToCall=performCreateLicenseRequest") 276 public ModelAndView performCreateLicenseRequest(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 277 HttpServletRequest request, HttpServletResponse response) { 278 LOG.debug("performCreateLicenseRequest method starts"); 279 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form; 280 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleeResourceRecordForm.getDocument(); 281 OleLicenseRequestBo oleLicenseRequestBo = getOleLicenseRequestService().createLicenseRequest( 282 oleeResourceRecordDocument.getDocumentNumber(), null); 283 OLEEResourceLicense oleeResourceLicense = new OLEEResourceLicense(); 284 oleeResourceLicense.setLicenseDocumentNumber(oleLicenseRequestBo.getLicenseDocumentNumber()); 285 oleeResourceLicense.setDocumentRouteHeaderValue(oleLicenseRequestBo.getDocumentRouteHeaderValue()); 286 /* Map<String,String> searchCriteria = new HashMap<String,String>(); 287 searchCriteria.put(OLEConstants.DOC_ID,oleLicenseRequestBo.getLicenseDocumentNumber());*/ 288 /*DocumentRouteHeaderValue documentHeader= (DocumentRouteHeaderValue) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey 289 (DocumentRouteHeaderValue.class,searchCriteria);*/ 290 /*DocumentRouteHeaderValue documentHeader= KEWServiceLocator.getRouteHeaderService().getRouteHeader(oleLicenseRequestBo.getLicenseDocumentNumber(), true); 291 oleLicenseRequestBo.setDocumentRouteHeaderValue(documentHeader);*/ 292 293 List<OLEEResourceInstance> listOfERInstances = oleeResourceRecordDocument.getOleERSInstances(); 294 List<OleLicenseRequestItemTitle> oleLicenseRequestItemTitles = new ArrayList<>(); 295 for (OLEEResourceInstance oleeResourceInstance : listOfERInstances) { 296 OleLicenseRequestItemTitle oleLicenseRequestItemTitle = new OleLicenseRequestItemTitle(); 297 oleLicenseRequestItemTitle.setItemUUID(oleeResourceInstance.getBibId()); 298 oleLicenseRequestItemTitle.setOleLicenseRequestId(oleLicenseRequestBo.getOleLicenseRequestId()); 299 oleLicenseRequestItemTitle.setOleLicenseRequestBo(oleLicenseRequestBo); 300 oleLicenseRequestItemTitles.add(oleLicenseRequestItemTitle); 301 } 302 oleLicenseRequestBo.setOleLicenseRequestItemTitles(oleLicenseRequestItemTitles); 303 oleeResourceLicense.setOleLicenseRequestBo(oleLicenseRequestBo); 304 oleeResourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense); 305 306 //oleeResourceRecordDocument. 307 return getModelAndView(oleeResourceRecordForm); 308 } 309 310 /** 311 * Saves the document instance contained on the form 312 * 313 * @param form - document form base containing the document instance that will be saved 314 * @return ModelAndView 315 */ 316 @Override 317 @RequestMapping(params = "methodToCall=save") 318 public ModelAndView save(UifFormBase form) { 319 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 320 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 321 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString()); 322 if (oleeResourceRecordDocument.getTitle() != null) { 323 if (oleeResourceRecordDocument.getTitle().length() < 40) { 324 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle()); 325 } else { 326 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39); 327 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription); 328 } 329 } 330 HttpSession session = form.getRequest().getSession(); 331 if (session.getAttribute("createChileEResource") != null) { 332 ModelAndView modelAndView = super.save(oleERSform); 333 oleERSform = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm"); 334 oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 335 session.removeAttribute("createChileEResource"); 336 String oleeResourceInstancesIdentifier = (String) session.getAttribute("oleeResourceInstancesIdentifier"); 337 String[] identifiers = oleeResourceInstancesIdentifier.split(","); 338 List<OLEEResourceInstance> ersInstances = new ArrayList<>(); 339 for (String identifier : identifiers) { 340 Map<String, String> criteriaMap = new HashMap<>(); 341 criteriaMap.put(OLEConstants.INSTANCE_ID, identifier); 342 List<OLEEResourceInstance> instances = (List<OLEEResourceInstance>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLEEResourceInstance.class, criteriaMap); 343 ersInstances.add(instances.get(0)); 344 criteriaMap = new HashMap<>(); 345 criteriaMap.put(OLEConstants.INSTANCE_ID, identifier); 346 criteriaMap.put("oleERSIdentifier", (String) session.getAttribute("oleERSIdentifier")); 347 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLEEResourceInstance.class, criteriaMap); 348 OLEEditorResponse oleEditorResponse = new OLEEditorResponse(); 349 oleEditorResponse.setLinkedInstanceId(identifier); 350 oleEditorResponse.setTokenId(oleeResourceRecordDocument.getDocumentNumber()); 351 HashMap<String, OLEEditorResponse> oleEditorResponseMap = new HashMap<String, OLEEditorResponse>(); 352 oleEditorResponseMap.put(oleeResourceRecordDocument.getDocumentNumber(), oleEditorResponse); 353 OleDocstoreResponse.getInstance().setEditorResponse(oleEditorResponseMap); 354 String documentNumber = oleeResourceRecordDocument.getDocumentNumber(); 355 oleeResourceRecordDocument.setSelectInstance(OLEConstants.OLEEResourceRecord.LINK_EXIST_INSTANCE); 356 try { 357 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, documentNumber); 358 } catch (Exception e) { 359 e.printStackTrace(); 360 } 361 } 362 oleeResourceRecordDocument.setOleERSInstances(ersInstances); 363 String oleERSIdentifier = (String) session.getAttribute("oleERSIdentifier"); 364 Map<String, String> tempId = new HashMap<String, String>(); 365 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSIdentifier); 366 OLEEResourceRecordDocument parentDocument = (OLEEResourceRecordDocument) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId); 367 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId()); 368 try { 369 parentDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(parentDocument.getDocumentNumber(), principalPerson)); 370 } catch (WorkflowException e) { 371 e.printStackTrace(); 372 } 373 OLELinkedEresource linkedEresource = new OLELinkedEresource(); 374 //linkedEresource.setOleeResourceRecordDocument(parentDocument); 375 linkedEresource.setOleeResourceRecordDocument(oleeResourceRecordDocument); 376 linkedEresource.setRelationShipType("parent"); 377 linkedEresource.setLinkedERSIdentifier(oleERSIdentifier); 378 /* linkedEresource.seteResourceDocNum(parentDocument.getDocumentNumber()); 379 linkedEresource.seteResourceName(parentDocument.getTitle());*/ 380 oleeResourceRecordDocument.getOleLinkedEresources().add(linkedEresource); 381 OLELinkedEresource eResource = new OLELinkedEresource(); 382 eResource.setOleeResourceRecordDocument(oleeResourceRecordDocument); 383 eResource.setRelationShipType("child"); 384 eResource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier()); 385 /*eResource.seteResourceDocNum(oleeResourceRecordDocument.getDocumentNumber()); 386 eResource.seteResourceName(oleeResourceRecordDocument.getTitle());*/ 387 parentDocument.getOleLinkedEresources().add(eResource); 388 oleEResourceSearchService.getPOInvoiceForERS(parentDocument); 389 KRADServiceLocatorWeb.getDocumentService().updateDocument(parentDocument); 390 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument); 391 KRADServiceLocatorWeb.getDocumentService().updateDocument(oleeResourceRecordDocument); 392 return getModelAndView(oleERSform); 393 } 394 /*List<OLEEResourceInstance> oleeResourceInstances = (List<OLEEResourceInstance>) session.getAttribute("oleeResourceInstances"); 395 396 if(oleeResourceInstances != null && oleeResourceInstances.size() > 0) { 397 session.removeAttribute("oleeResourceInstances"); 398 oleeResourceRecordDocument.setOleERSInstances(oleeResourceInstances); 399 try { 400 getOleEResourceSearchService().saveEResourceInstanceToDocstore(oleeResourceRecordDocument); 401 } catch (Exception e) { 402 e.printStackTrace(); 403 } 404 }*/ 405 406 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes(); 407 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes(); 408 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes(); 409 List<String> instanceId = new ArrayList<String>(); 410 /*boolean oleERSFlag = false; 411 oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes())); 412 oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes())); 413 if (oleERSFlag) { 414 return getModelAndView(oleERSform); 415 }*/ 416 boolean flag = false; 417 boolean datesFlag = true; 418 flag = getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument); 419 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument, oleERSform); 420 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument, oleERSform); 421 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument, oleERSform); 422 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument, oleERSform); 423 if (flag) { 424 return getModelAndView(oleERSform); 425 } 426 if (!datesFlag) { 427 return getModelAndView(oleERSform); 428 } 429 430 String fileName = oleeResourceRecordDocument.getDocumentNumber(); 431 if (oleERSform.isCreateInstance()) { 432 try { 433 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName); 434 } catch (Exception e) { 435 e.printStackTrace(); 436 } 437 oleERSform.setCreateInstance(false); 438 } 439 oleERSform.setBibId(null); 440 oleERSform.setInstanceId(null); 441 oleERSform.setLinkInstance(false); 442 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) { 443 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument); 444 Map<String, String> tempId = new HashMap<String, String>(); 445 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier()); 446 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId); 447 int instancesSize = tempDocument.getOleERSInstances().size(); 448 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size(); 449 if (!oleERSform.isDefaultDatesFlag() && oleERSform.getPageId() != null && oleERSform.getPageId().equalsIgnoreCase("OLEEResourceRecordView-E-ResourceInstanceTab")) { 450 if (tempDocument.iseInstanceFlag() && instancesSize >= instanceSize && !oleERSform.isRemoveInstanceFlag()) { 451 try { 452 super.reload(oleERSform); 453 } catch (Exception e) { 454 LOG.error("exception while reloading the e-resource document" + e.getMessage()); 455 throw new RuntimeException("exception while reloading the e-resource document", e); 456 } 457 } 458 } 459 oleERSform.setRemoveInstanceFlag(false); 460 oleERSform.setDefaultDatesFlag(false); 461 } 462 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())) { 463 Map fundCodeMap = new HashMap(); 464 fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleeResourceRecordDocument.getFundCode()); 465 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleFundCode.class, fundCodeMap); 466 if (oleFundCode == null) { 467 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE, OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE); 468 } else { 469 oleeResourceRecordDocument.setFundId(oleFundCode.getFundCodeId()); 470 } 471 } 472 473 AlertBo alert = new AlertBo(); 474 if(oleeResourceRecordDocument.getCurrentSubscriptionEndDate()!=null){ 475 if(oleeResourceRecordDocument.isRenewalAlertEnabled()){ 476 if(oleeResourceRecordDocument.getRecipientId()==null){ 477 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.RECIPIENT_ID, OLEConstants.OLEEResourceRecord.ERROR_RECIPIENT_ID); 478 return getModelAndView(oleERSform); 479 } 480 String date = oleeResourceRecordDocument.getCurrentSubscriptionEndDate().toString().split(" ")[0].replace("-","/"); 481 SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd"); 482 Date parsed = null; 483 try { 484 parsed = format.parse(date); 485 } catch (ParseException e) { 486 e.printStackTrace(); 487 } 488 java.sql.Date sql = new java.sql.Date(parsed.getTime()); 489 Date actionDate = DateUtils.addDays(sql,-Integer.valueOf(oleeResourceRecordDocument.getRenewalNoticePeriod())); 490 alert.setAlertDate(new java.sql.Date(actionDate.getTime())); 491 alert.setAlertCreateDate(new java.sql.Date(System.currentTimeMillis())); 492 alert.setAlertInitiatorId(GlobalVariables.getUserSession().getPrincipalId()); 493 alert.setDocumentId(oleeResourceRecordDocument.getDocumentNumber()); 494 alert.setReceivingUserId(oleeResourceRecordDocument.getRecipientId()); 495 oleeResourceRecordDocument.getAlertBoList().add(alert); 496 } 497 } 498 ModelAndView modelAndView = super.save(oleERSform); 499 OLEEResourceRecordForm kualiForm = (OLEEResourceRecordForm) modelAndView.getModel().get("KualiForm"); 500 OLEEResourceRecordDocument resourceRecordDocument = (OLEEResourceRecordDocument) kualiForm.getDocument(); 501 resourceRecordDocument.geteRSInstances().clear(); 502 resourceRecordDocument.geteRSInstances().addAll(resourceRecordDocument.getOleERSInstances()); 503 for (OLELinkedEresource oleLinkedEresource : resourceRecordDocument.getOleLinkedEresources()) { 504 if (oleLinkedEresource.getRelationShipType().equalsIgnoreCase("child")) { 505 //Displaying the child EResource instance and Licence info in parent Eresource. 506 if (oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances() != null) { 507 resourceRecordDocument.geteRSInstances().addAll(oleLinkedEresource.getOleeResourceRecordDocument().getOleERSInstances()); 508 } 509 for (OLEEResourceLicense oleeResourceLicense : oleLinkedEresource.getOleeResourceRecordDocument().getOleERSLicenseRequests()) { 510 resourceRecordDocument.getOleERSLicenseRequests().add(oleeResourceLicense); 511 } 512 } 513 } 514 getOleEResourceSearchService().getPOInvoiceForERS(oleeResourceRecordDocument); 515 getOleEResourceSearchService().getPOAndInvoiceItemsWithoutDuplicate(oleeResourceRecordDocument); 516 return getModelAndView(kualiForm); 517 } 518 519 /** 520 * Routes the document instance contained on the formole-docstore-krad-servlet.xml 521 * 522 * @param form - document form base containing the document instance that will be routed 523 * @return ModelAndView 524 */ 525 @RequestMapping(params = "methodToCall=route") 526 public ModelAndView route(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 527 HttpServletRequest request, HttpServletResponse response) { 528 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 529 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 530 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString()); 531 if (oleeResourceRecordDocument.getTitle().length() < 40) { 532 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle()); 533 } else { 534 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39); 535 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription); 536 } 537 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes(); 538 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes(); 539 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes(); 540 List<String> instanceId = new ArrayList<String>(); 541 /*boolean oleERSFlag = false; 542 oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes())); 543 oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes())); 544 if (oleERSFlag) { 545 return getModelAndView(oleERSform); 546 }*/ 547 boolean flag = false; 548 boolean datesFlag = true; 549 flag=getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument); 550 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument,oleERSform); 551 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument,oleERSform); 552 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument,oleERSform); 553 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument,oleERSform); 554 if (flag) { 555 return getModelAndView(oleERSform); 556 } 557 if (!datesFlag) { 558 return getModelAndView(oleERSform); 559 } 560 String fileName = oleeResourceRecordDocument.getDocumentNumber(); 561 if (oleERSform.isCreateInstance()) { 562 try { 563 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName); 564 } catch (Exception e) { 565 e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. 566 } 567 oleERSform.setCreateInstance(false); 568 } 569 oleERSform.setBibId(null); 570 oleERSform.setInstanceId(null); 571 oleERSform.setLinkInstance(false); 572 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) { 573 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument); 574 Map<String, String> tempId = new HashMap<String, String>(); 575 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier()); 576 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId); 577 int instancesSize = tempDocument.getOleERSInstances().size(); 578 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size(); 579 if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) { 580 try { 581 super.reload(oleERSform); 582 } catch (Exception e) { 583 LOG.error("Exception while reloading the e-resource document"+e.getMessage()); 584 } 585 } 586 oleERSform.setRemoveInstanceFlag(false); 587 } 588 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())) { 589 Map fundCodeMap = new HashMap(); 590 fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleeResourceRecordDocument.getFundCode()); 591 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleFundCode.class, fundCodeMap); 592 if (oleFundCode == null) { 593 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE, OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE); 594 } else { 595 oleeResourceRecordDocument.setFundId(oleFundCode.getFundCodeId()); 596 } 597 } 598 return super.route(oleERSform); 599 } 600 601 /** 602 * Performs the approve workflow action on the form document instance 603 * 604 * @param form - document form base containing the document instance that will be approved 605 * @return ModelAndView 606 */ 607 @Override 608 @RequestMapping(params = "methodToCall=approve") 609 public ModelAndView approve(@ModelAttribute("KualiForm") DocumentFormBase form) { 610 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 611 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 612 oleeResourceRecordDocument.setStatusDate(oleERSform.getStatusDate().toString()); 613 if (oleeResourceRecordDocument.getTitle().length() < 40) { 614 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(oleeResourceRecordDocument.getTitle()); 615 } else { 616 String documentDescription = oleeResourceRecordDocument.getTitle().substring(0, 39); 617 oleeResourceRecordDocument.getDocumentHeader().setDocumentDescription(documentDescription); 618 } 619 List<OLEMaterialTypeList> oleMaterialTypeList = oleeResourceRecordDocument.getOleMaterialTypes(); 620 List<OLEFormatTypeList> oleFormatTypeLists = oleeResourceRecordDocument.getOleFormatTypes(); 621 List<OLEContentTypes> oleContentTypeList = oleeResourceRecordDocument.getOleContentTypes(); 622 List<String> instanceId = new ArrayList<String>(); 623 /*boolean oleERSFlag = false; 624 oleERSFlag &= getKualiRuleService().applyRules(new OLEMaterialTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleMaterialTypes())); 625 oleERSFlag &= getKualiRuleService().applyRules(new OLEContentTypeEvent(oleeResourceRecordDocument,oleeResourceRecordDocument.getOleContentTypes())); 626 if (oleERSFlag) { 627 return getModelAndView(oleERSform); 628 }*/ 629 boolean flag = false; 630 boolean datesFlag = true; 631 flag=getOleEResourceSearchService().validateEResourceDocument(oleeResourceRecordDocument); 632 datesFlag &= getOleEResourceSearchService().validateCoverageStartDates(oleeResourceRecordDocument,oleERSform); 633 datesFlag &= getOleEResourceSearchService().validateCoverageEndDates(oleeResourceRecordDocument,oleERSform); 634 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessStartDates(oleeResourceRecordDocument,oleERSform); 635 datesFlag &= getOleEResourceSearchService().validatePerpetualAccessEndDates(oleeResourceRecordDocument,oleERSform); 636 if (flag) { 637 return getModelAndView(oleERSform); 638 } 639 if (!datesFlag) { 640 return getModelAndView(oleERSform); 641 } 642 String fileName = oleeResourceRecordDocument.getDocumentNumber(); 643 if (oleERSform.isCreateInstance()) { 644 try { 645 getOleEResourceSearchService().getNewInstance(oleeResourceRecordDocument, fileName); 646 } catch (Exception e) { 647 e.printStackTrace(); 648 } 649 oleERSform.setCreateInstance(false); 650 } 651 oleERSform.setBibId(null); 652 oleERSform.setInstanceId(null); 653 oleERSform.setLinkInstance(false); 654 if (oleeResourceRecordDocument.getOleERSIdentifier() != null && !oleeResourceRecordDocument.getOleERSIdentifier().isEmpty()) { 655 oleeResourceRecordDocument = getOleEResourceSearchService().getNewOleERSDoc(oleeResourceRecordDocument); 656 Map<String, String> tempId = new HashMap<String, String>(); 657 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleeResourceRecordDocument.getOleERSIdentifier()); 658 OLEEResourceRecordDocument tempDocument = (OLEEResourceRecordDocument) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId); 659 int instancesSize = tempDocument.getOleERSInstances().size(); 660 int instanceSize = oleeResourceRecordDocument.getOleERSInstances().size(); 661 if (tempDocument.iseInstanceFlag() && instancesSize > instanceSize && !oleERSform.isRemoveInstanceFlag()) { 662 try { 663 super.reload(oleERSform); 664 } catch (Exception e) { 665 LOG.error("Exception while reloading the e-resource document"+e.getMessage()); 666 } 667 } 668 oleERSform.setRemoveInstanceFlag(false); 669 } 670 if (StringUtils.isNotBlank(oleeResourceRecordDocument.getFundCode())) { 671 Map fundCodeMap = new HashMap(); 672 fundCodeMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, oleeResourceRecordDocument.getFundCode()); 673 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleFundCode.class, fundCodeMap); 674 if (oleFundCode == null) { 675 GlobalVariables.getMessageMap().putError(OLEConstants.OLEEResourceRecord.FUND_CODE, OLEConstants.OLEEResourceRecord.ERROR_FUND_CODE); 676 } else { 677 oleeResourceRecordDocument.setFundId(oleFundCode.getFundCodeId()); 678 } 679 } 680 return super.approve(oleERSform); 681 } 682 683 /*@Override 684 @RequestMapping(params = "methodToCall=cancel") 685 public ModelAndView cancel(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 686 HttpServletRequest request, HttpServletResponse response) { 687 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 688 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 689 if (oleeResourceRecordDocument != null) { 690 Map<String, String> criteriaStatusIdMap = new HashMap<String, String>(); 691 criteriaStatusIdMap.put(OLEConstants.OLEEResourceRecord.STATUS_NAME, OLEConstants.OLEEResourceRecord.CANCELED); 692 List<OLEEResourceStatus> oleERSStatusList = (List<OLEEResourceStatus>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEEResourceStatus.class, criteriaStatusIdMap); 693 if (oleERSStatusList.size() > 0) { 694 OLEEResourceStatus oleERSStatus = oleERSStatusList.get(0); 695 if (oleERSStatus != null) { 696 oleeResourceRecordDocument.setStatusId(oleERSStatus.getOleEResourceStatusId()); 697 oleeResourceRecordDocument.setStatusName(oleERSStatus.getOleEResourceStatusName()); 698 } 699 } 700 } 701 try { 702 save(oleERSform); 703 } catch (Exception e) { 704 throw new RuntimeException(e); 705 } 706 return super.cancel(oleERSform); 707 } 708*/ 709 710 /** 711 * Create E-Instance document instance contained on the form 712 * 713 * @param form - document form base containing the document instance that will be routed 714 * @return ModelAndView 715 */ 716 @RequestMapping(params = "methodToCall=createInstance") 717 public ModelAndView createInstance(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 718 HttpServletRequest request, HttpServletResponse response) { 719 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 720 oleERSform.setSelectFlag(true); 721 oleERSform.setLinkInstance(false); 722 oleERSform.setCreateInstance(true); 723 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 724 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 725 } 726 727 /** 728 * close the popup in instance tab 729 * 730 * @param form - document form base containing the document instance that will be routed 731 * @return ModelAndView 732 */ 733 @RequestMapping(params = "methodToCall=closePopup") 734 public ModelAndView closePopup(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 735 HttpServletRequest request, HttpServletResponse response) { 736 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 737 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 738 } 739 740 /** 741 * This method takes List of UUids as parameter and creates a LinkedHashMap with instance as key and id as value. and calls 742 * Docstore's QueryServiceImpl class getWorkBibRecords method and return workBibDocument for passed instance Id. 743 * 744 * @param instanceIdsList 745 * @return List<WorkBibDocument> 746 */ 747// private List<WorkBibDocument> getWorkBibDocuments(List<String> instanceIdsList, String docType) { 748// List<LinkedHashMap<String, String>> instanceIdMapList = new ArrayList<LinkedHashMap<String, String>>(); 749// for (String instanceId : instanceIdsList) { 750// LinkedHashMap<String, String> instanceIdMap = new LinkedHashMap<String, String>(); 751// instanceIdMap.put(docType, instanceId); 752// instanceIdMapList.add(instanceIdMap); 753// } 754// 755// QueryService queryService = QueryServiceImpl.getInstance(); 756// List<WorkBibDocument> workBibDocuments = new ArrayList<WorkBibDocument>(); 757// try { 758// workBibDocuments = queryService.getWorkBibRecords(instanceIdMapList); 759// } catch (Exception ex) { 760// // TODO Auto-generated catch block 761// ex.printStackTrace(); 762// } 763// return workBibDocuments; 764// } 765 766 /** 767 * Called by the delete line action for a model collection. Method 768 * determines which collection the action was selected for and the line 769 * index that should be removed, then invokes the view helper service to 770 * process the action 771 */ 772 @RequestMapping(method = RequestMethod.POST, params = "methodToCall=removeInstance") 773 public ModelAndView removeInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 774 HttpServletRequest request, HttpServletResponse response) { 775 776 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) uifForm; 777 OLEEResourceRecordDocument oleEResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 778 String selectedCollectionPath = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_PATH); 779 String selectedCollectionId = uifForm.getActionParamaterValue(UifParameters.SELECTED_COLLECTION_ID); 780 if (StringUtils.isBlank(selectedCollectionPath)) { 781 throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX); 782 } 783 int selectedLineIndex = -1; 784 String selectedLine = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); 785 if (StringUtils.isNotBlank(selectedLine)) { 786 OLEEResourceInstance oleERSInstance = oleEResourceRecordDocument.getOleERSInstances().get(Integer.parseInt(selectedLine)); 787 Map removePOMap = new HashMap(); 788 removePOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID, oleERSInstance.getInstanceId()); 789 removePOMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSInstance.getOleERSIdentifier()); 790 List<OLEEResourcePO> oleERSPOs = (List<OLEEResourcePO>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEEResourcePO.class, removePOMap); 791 removePOMap.remove(OLEConstants.OLEEResourceRecord.ERESOURCE_INSTANCE_ID); 792 removePOMap.put(OLEConstants.HOLDINGS_ID, oleERSInstance.getInstanceId()); 793 List<OLEEResourceInvoices> oleERSInvoices = (List<OLEEResourceInvoices>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEEResourceInvoices.class, removePOMap); 794 if (oleERSPOs.size() > 0) { 795 if (oleERSInvoices.size()>0){ 796 for (int i = 0; i < oleERSInvoices.size(); i++) { 797 for (int j = 0; j < oleEResourceRecordDocument.getOleERSInvoices().size(); j++) { 798 if (oleEResourceRecordDocument.getOleERSInvoices().get(j).getOleEResInvoiceId().equals(oleERSInvoices.get(i).getOleEResInvoiceId())) { 799 oleEResourceRecordDocument.getOleERSInvoices().remove(j); 800 } 801 } 802 } 803 } 804 for (int i = 0; i < oleERSPOs.size(); i++) { 805 for (int j = 0; j < oleEResourceRecordDocument.getOleERSPOItems().size(); j++) { 806 if (oleEResourceRecordDocument.getOleERSPOItems().get(j).getOleEResPOId().equals(oleERSPOs.get(i).getOleEResPOId())) { 807 oleEResourceRecordDocument.getOleERSPOItems().remove(j); 808 } 809 } 810 } 811 } 812 try { 813 Holdings holdings = new EHoldings(); 814 OleHoldings oleHoldings = new OleHoldings(); 815 holdings = getDocstoreClientLocator().getDocstoreClient().retrieveHoldings(oleERSInstance.getInstanceId()); 816 if (holdings instanceof EHoldings) { 817 oleHoldings = new HoldingOlemlRecordProcessor().fromXML(holdings.getContent()); 818 oleHoldings.setEResourceId(null); 819 holdings.setContent(new HoldingOlemlRecordProcessor().toXML(oleHoldings)); 820 getDocstoreClientLocator().getDocstoreClient().updateHoldings(holdings); 821 } 822 } catch (Exception e) { 823 LOG.error("Illegal exception while updating instance record" + e.getMessage()); 824 } 825 selectedLineIndex = Integer.parseInt(selectedLine); 826 OLEEResourceEventLog oleEResourceEventLog = new OLEEResourceEventLog(); 827 oleEResourceEventLog.setCurrentTimeStamp(); 828 oleEResourceEventLog.setEventUser(GlobalVariables.getUserSession().getPrincipalName()); 829 oleEResourceEventLog.setEventNote(oleERSInstance.getInstanceTitle() + OLEConstants.OLEEResourceRecord.INSTANCE_ID_REMOVE_NOTE + oleERSInstance.getInstanceId() + OLEConstants.OLEEResourceRecord.REMOVE_NOTE); 830 oleEResourceEventLog.setEventType(OLEConstants.OLEEResourceRecord.SYSTEM); 831 oleEResourceRecordDocument.getOleERSEventLogs().add(oleEResourceEventLog); 832 } 833 if (selectedLineIndex == -1) { 834 throw new RuntimeException(OLEConstants.OLEEResourceRecord.BLANK_SELECTED_INDEX); 835 } 836 oleEResourceRecordForm.setRemoveInstanceFlag(true); 837 View view = oleEResourceRecordForm.getView(); 838 view.getViewHelperService().processCollectionDeleteLine(uifForm, selectedCollectionId, selectedCollectionPath, 839 selectedLineIndex); 840 return getModelAndView(oleEResourceRecordForm); 841 } 842 843 844 /** 845 * This method returns the object of OleLicesneRequestService 846 * 847 * @return oleLicenseRequestService 848 */ 849 public OleLicenseRequestWebService getOleLicenseRequestService() { 850 if (oleLicenseRequestWebService == null) { 851 oleLicenseRequestWebService = GlobalResourceLoader.getService(OLEConstants.OleLicenseRequest.HELPER_SERVICE); 852 } 853 return oleLicenseRequestWebService; 854 } 855 856 public KualiRuleService getKualiRuleService() { 857 if (kualiRuleService == null) { 858 kualiRuleService = GlobalResourceLoader.getService(OLEConstants.KUALI_RULE_SERVICE); 859 } 860 return kualiRuleService; 861 } 862 863 public BusinessObjectService getBusinessObjectService() { 864 if (businessObjectService == null) { 865 businessObjectService = KNSServiceLocator.getBusinessObjectService(); 866 } 867 return businessObjectService; 868 } 869 870 public OLEEResourceSearchService getOleEResourceSearchService() { 871 if (oleEResourceSearchService == null) { 872 oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE); 873 } 874 return oleEResourceSearchService; 875 } 876 877 878 /** 879 * Edit Default Coverage date for E-Instance 880 * 881 * @param form - document form base containing the document instance that will be routed 882 * @return ModelAndView 883 */ 884 @RequestMapping(params = "methodToCall=editDefaultCoverage") 885 public ModelAndView editDefaultCoverage(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 886 HttpServletRequest request, HttpServletResponse response) { 887 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 888 oleERSform.setCoverageFlag(true); 889 oleERSform.setPerpetualAccessFlag(false); 890 oleERSform.setDefaultDatesFlag(true); 891 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 892 String defaultCov = oleeResourceRecordDocument.getDummyDefaultCoverage(); 893 if(defaultCov != null && !defaultCov.isEmpty()) { 894 oleeResourceRecordDocument.setCovEdited(true); 895 getOleEResourceSearchService().getDefaultCovDatesToPopup(oleeResourceRecordDocument, defaultCov); 896 } 897 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 898 } 899 900 /** 901 * Edit Default Perpetual date for E-Instance 902 * 903 * @param form - document form base containing the document instance that will be routed 904 * @return ModelAndView 905 */ 906 @RequestMapping(params = "methodToCall=editDefaultPerpetualAccess") 907 public ModelAndView editDefaultPerpetualAccess(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 908 HttpServletRequest request, HttpServletResponse response) { 909 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 910 oleERSform.setCoverageFlag(false); 911 oleERSform.setPerpetualAccessFlag(true); 912 oleERSform.setDefaultDatesFlag(true); 913 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 914 String defaultPerAcc = oleeResourceRecordDocument.getDummyDefaultPerpetualAccess(); 915 if(defaultPerAcc != null && !defaultPerAcc.isEmpty()) { 916 oleeResourceRecordDocument.setPerAccEdited(true); 917 getOleEResourceSearchService().getDefaultPerAccDatesToPopup(oleeResourceRecordDocument,defaultPerAcc); 918 } 919 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 920 } 921 922 /** 923 * close the popup in instance tab 924 * 925 * @param form - document form base containing the document instance that will be routed 926 * @return ModelAndView 927 */ 928 @RequestMapping(params = "methodToCall=closeCoverageOrPerpetualAccessDate") 929 public ModelAndView closeCoverageOrPerpetualAccessDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 930 HttpServletRequest request, HttpServletResponse response) { 931 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 932 oleERSform.setDefaultDatesFlag(false); 933 oleERSform.setDefaultCovStartDateErrorMessage(null); 934 oleERSform.setDefaultCovEndDateErrorMessage(null); 935 oleERSform.setDefaultPerAccStartDateErrorMessage(null); 936 oleERSform.setDefaultPerAccEndDateErrorMessage(null); 937 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 938 } 939 940 /** 941 * refresh the instance tab 942 * 943 * @param form - document form base containing the document instance that will be routed 944 * @return ModelAndView 945 */ 946 @RequestMapping(params = "methodToCall=refreshDefaultDate") 947 public ModelAndView refreshDefaultDate(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 948 HttpServletRequest request, HttpServletResponse response) { 949 OLEEResourceRecordForm oleERSform = (OLEEResourceRecordForm) form; 950 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleERSform.getDocument(); 951 if(oleERSform.isCoverageFlag()) { 952 getOleEResourceSearchService().getDefaultCovergeDate(oleeResourceRecordDocument); 953 oleERSform.setCoverageFlag(false); 954 } 955 if(oleERSform.isPerpetualAccessFlag()) { 956 getOleEResourceSearchService().getDefaultPerpetualAccessDate(oleeResourceRecordDocument); 957 oleERSform.setPerpetualAccessFlag(false); 958 } 959 return getModelAndView(oleERSform, OLEConstants.OLEEResourceRecord.E_RES_INSTANCE_TAB); 960 } 961 962 @RequestMapping(params = "methodToCall=addMaterialType") 963 public ModelAndView addMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 964 HttpServletRequest request, HttpServletResponse response) { 965 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 966 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 967 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 968 index++; 969 List<OLEMaterialTypeList> oleMaterialTypeLists=oleeResourceRecordDocument.getOleMaterialTypes(); 970 oleeResourceRecordDocument.getOleMaterialTypes().add(index, new OLEMaterialTypeList()); 971 oleeResourceRecordDocument.setOleMaterialTypes(oleMaterialTypeLists); 972 form.setDocument(oleeResourceRecordDocument); 973 return super.navigate(form); 974 } 975 976 @RequestMapping(params = "methodToCall=removeMaterialType") 977 public ModelAndView removeMaterialType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 978 HttpServletRequest request, HttpServletResponse response) { 979 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 980 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 981 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 982 List<OLEMaterialTypeList> oleMaterialTypeLists=oleeResourceRecordDocument.getOleMaterialTypes(); 983 if (oleMaterialTypeLists.size() > 1) { 984 oleMaterialTypeLists.remove(index); 985 } 986 form.setDocument(oleeResourceRecordDocument); 987 return super.navigate(form); 988 } 989 990 @RequestMapping(params = "methodToCall=addFormatType") 991 public ModelAndView addFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 992 HttpServletRequest request, HttpServletResponse response) { 993 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 994 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 995 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 996 index++; 997 List<OLEFormatTypeList> oleFormatTypeLists=oleeResourceRecordDocument.getOleFormatTypes(); 998 oleeResourceRecordDocument.getOleFormatTypes().add(index, new OLEFormatTypeList()); 999 oleeResourceRecordDocument.setOleFormatTypes(oleFormatTypeLists); 1000 form.setDocument(oleeResourceRecordDocument); 1001 return super.navigate(form); 1002 } 1003 1004 @RequestMapping(params = "methodToCall=removeFormatType") 1005 public ModelAndView removeFormatType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1006 HttpServletRequest request, HttpServletResponse response) { 1007 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1008 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1009 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1010 List<OLEFormatTypeList> oleFormatTypeLists=oleeResourceRecordDocument.getOleFormatTypes(); 1011 if (oleFormatTypeLists.size() > 1) { 1012 oleFormatTypeLists.remove(index); 1013 } 1014 form.setDocument(oleeResourceRecordDocument); 1015 return super.navigate(form); 1016 } 1017 1018 @RequestMapping(params = "methodToCall=addContentType") 1019 public ModelAndView addContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1020 HttpServletRequest request, HttpServletResponse response) { 1021 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1022 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1023 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1024 index++; 1025 List<OLEContentTypes> oleContentTypes=oleeResourceRecordDocument.getOleContentTypes(); 1026 oleeResourceRecordDocument.getOleContentTypes().add(index, new OLEContentTypes()); 1027 oleeResourceRecordDocument.setOleContentTypes(oleContentTypes); 1028 form.setDocument(oleeResourceRecordDocument); 1029 return super.navigate(form); 1030 } 1031 1032 @RequestMapping(params = "methodToCall=removeContentType") 1033 public ModelAndView removeContentType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1034 HttpServletRequest request, HttpServletResponse response) { 1035 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1036 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1037 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1038 List<OLEContentTypes> oleContentTypes=oleeResourceRecordDocument.getOleContentTypes(); 1039 if (oleContentTypes.size() > 1) { 1040 oleContentTypes.remove(index); 1041 } 1042 form.setDocument(oleeResourceRecordDocument); 1043 return super.navigate(form); 1044 } 1045 1046 1047 @RequestMapping(params = "methodToCall=addSelectorType") 1048 public ModelAndView addSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1049 HttpServletRequest request, HttpServletResponse response) { 1050 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1051 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1052 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1053 index++; 1054 List<OLEEResourceSelector> oleeResourceSelectors=oleeResourceRecordDocument.getSelectors(); 1055 oleeResourceRecordDocument.getSelectors().add(index, new OLEEResourceSelector()); 1056 oleeResourceRecordDocument.setSelectors(oleeResourceSelectors); 1057 form.setDocument(oleeResourceRecordDocument); 1058 return super.navigate(form); 1059 } 1060 1061 @RequestMapping(params = "methodToCall=removeSelectorType") 1062 public ModelAndView removeSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1063 HttpServletRequest request, HttpServletResponse response) { 1064 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1065 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1066 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1067 List<OLEEResourceSelector> oleeResourceSelectors=oleeResourceRecordDocument.getSelectors(); 1068 if (oleeResourceSelectors.size() > 1) { 1069 oleeResourceSelectors.remove(index); 1070 } 1071 form.setDocument(oleeResourceRecordDocument); 1072 return super.navigate(form); 1073 } 1074 1075 @RequestMapping(params = "methodToCall=addRequestorType") 1076 public ModelAndView addRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1077 HttpServletRequest request, HttpServletResponse response) { 1078 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1079 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1080 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1081 index++; 1082 List<OLEEResourceRequestor> oleeResourceRequestors=oleeResourceRecordDocument.getRequestors(); 1083 oleeResourceRecordDocument.getRequestors().add(index, new OLEEResourceRequestor()); 1084 oleeResourceRecordDocument.setRequestors(oleeResourceRequestors); 1085 form.setDocument(oleeResourceRecordDocument); 1086 return super.navigate(form); 1087 } 1088 1089 @RequestMapping(params = "methodToCall=removeRequestorType") 1090 public ModelAndView removeRequestorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1091 HttpServletRequest request, HttpServletResponse response) { 1092 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1093 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1094 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1095 List<OLEEResourceRequestor> oleeResourceRequestors=oleeResourceRecordDocument.getRequestors(); 1096 if (oleeResourceRequestors.size() > 1) { 1097 oleeResourceRequestors.remove(index); 1098 } 1099 form.setDocument(oleeResourceRecordDocument); 1100 return super.navigate(form); 1101 } 1102 1103 @RequestMapping(params = "methodToCall=addVariantTitle") 1104 public ModelAndView addVariantTitle(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1105 HttpServletRequest request, HttpServletResponse response) { 1106 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1107 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1108 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1109 index++; 1110 List<OLEEResourceVariantTitle> oleEResourceVariantTitleList=oleeResourceRecordDocument.getOleEResourceVariantTitleList(); 1111 oleeResourceRecordDocument.getOleEResourceVariantTitleList().add(index, new OLEEResourceVariantTitle()); 1112 oleeResourceRecordDocument.setOleEResourceVariantTitleList(oleEResourceVariantTitleList); 1113 form.setDocument(oleeResourceRecordDocument); 1114 return super.navigate(form); 1115 } 1116 1117 @RequestMapping(params = "methodToCall=removeVariantTitle") 1118 public ModelAndView removeVariantTitle(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1119 HttpServletRequest request, HttpServletResponse response) { 1120 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1121 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1122 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1123 List<OLEEResourceVariantTitle> oleEResourceVariantTitleList=oleeResourceRecordDocument.getOleEResourceVariantTitleList(); 1124 if (oleEResourceVariantTitleList.size() > 1) { 1125 oleEResourceVariantTitleList.remove(index); 1126 } 1127 form.setDocument(oleeResourceRecordDocument); 1128 return super.navigate(form); 1129 } 1130 1131 @RequestMapping(params = "methodToCall=addRequestorSelectorType") 1132 public ModelAndView addRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1133 HttpServletRequest request, HttpServletResponse response) { 1134 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1135 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1136 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1137 index++; 1138 List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses=oleeResourceRecordDocument.getReqSelComments(); 1139 oleeResourceRecordDocument.getReqSelComments().add(index, new OLEEResourceReqSelComments()); 1140 oleeResourceRecordDocument.setReqSelComments(oleeResourceReqSelCommentses); 1141 form.setDocument(oleeResourceRecordDocument); 1142 return super.navigate(form); 1143 } 1144 1145 @RequestMapping(params = "methodToCall=removeRequestorSelectorType") 1146 public ModelAndView removeRequestorSelectorType(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1147 HttpServletRequest request, HttpServletResponse response) { 1148 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1149 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1150 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1151 List<OLEEResourceReqSelComments> oleeResourceReqSelCommentses=oleeResourceRecordDocument.getReqSelComments(); 1152 if (oleeResourceReqSelCommentses.size() > 1) { 1153 oleeResourceReqSelCommentses.remove(index); 1154 } 1155 form.setDocument(oleeResourceRecordDocument); 1156 return super.navigate(form); 1157 } 1158 1159 @RequestMapping(params = "methodToCall=addNoteTextSection") 1160 public ModelAndView addNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1161 HttpServletRequest request, HttpServletResponse response) { 1162 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1163 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1164 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1165 index++; 1166 List<OLEEResourceNotes> oleeResourceNoteses=oleeResourceRecordDocument.getEresNotes(); 1167 oleeResourceRecordDocument.getEresNotes().add(index, new OLEEResourceNotes()); 1168 oleeResourceRecordDocument.setEresNotes(oleeResourceNoteses); 1169 form.setDocument(oleeResourceRecordDocument); 1170 return super.navigate(form); 1171 } 1172 1173 @RequestMapping(params = "methodToCall=removeNoteTextSection") 1174 public ModelAndView removeNoteTextSection(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1175 HttpServletRequest request, HttpServletResponse response) { 1176 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1177 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1178 int index = Integer.parseInt(form.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX)); 1179 List<OLEEResourceNotes> oleeResourceNoteses=oleeResourceRecordDocument.getEresNotes(); 1180 if (oleeResourceNoteses.size() > 1) { 1181 oleeResourceNoteses.remove(index); 1182 } 1183 form.setDocument(oleeResourceRecordDocument); 1184 return super.navigate(form); 1185 } 1186 1187 @RequestMapping(params = "methodToCall=saveGokbConfig") 1188 public ModelAndView saveGokbConfig(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1189 HttpServletRequest request, HttpServletResponse response) { 1190 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1191 return super.navigate(form); 1192 } 1193 1194 1195 /** 1196 * This method will fetch the eresource and its instance to create PO(s). 1197 * 1198 * @param uifForm 1199 * @param result 1200 * @param request 1201 * @param response 1202 * @return 1203 */ 1204 @MethodAccessible 1205 @RequestMapping(params = "methodToCall=getEResourcesAndInstances") 1206 public ModelAndView getEResourcesAndInstances(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1207 HttpServletRequest request, HttpServletResponse response) { 1208 1209 String oleERSIdentifier = request.getParameter(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER); 1210 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 1211 oleeResourceRecordForm.setPoSuccessMessage(null); 1212 oleeResourceRecordForm.setPoErrorMessage(null); 1213 OLEEResourceRecordDocument oleeResourceRecordDocument = null; 1214 if (oleERSIdentifier != null) { 1215 Map eResMap = new HashMap(); 1216 eResMap.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, oleERSIdentifier); 1217 oleeResourceRecordDocument = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, eResMap); 1218 } 1219 if (oleeResourceRecordDocument != null) { 1220 String purposeId = null; 1221 String purposeType = getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.PURPOSE_TYPE, OLEConstants.ERESOURCE_CMPNT); 1222 if (purposeType != null) { 1223 Map purposeMap = new HashMap(); 1224 purposeMap.put(OLEConstants.OlePurchaseOrderPurpose.PURCHASE_ORDER_PURPOSE_CODE, purposeType); 1225 List<OlePurchaseOrderPurpose> purposeList = (List<OlePurchaseOrderPurpose>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OlePurchaseOrderPurpose.class, purposeMap); 1226 if (purposeList != null && purposeList.size() > 0) { 1227 OlePurchaseOrderPurpose purpose = purposeList.get(0); 1228 purposeId = purpose.getPurchaseOrderPurposeId(); 1229 } 1230 } 1231 String fundCode = null; 1232 if (oleeResourceRecordDocument.getFundId()!=null){ 1233 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findBySinglePrimaryKey(OleFundCode.class,oleeResourceRecordDocument.getFundId()); 1234 if (oleFundCode!=null){ 1235 fundCode = oleFundCode.getFundCode(); 1236 } 1237 } 1238 List<OLECreatePO> eResources = getOleEResourceSearchService().getEresources(oleeResourceRecordDocument, purposeId, fundCode); 1239 oleeResourceRecordForm.seteResourcePOs(eResources); 1240 1241 List<OLECreatePO> instancePOs = getOleEResourceSearchService().getInstances(oleeResourceRecordDocument, purposeId, fundCode); 1242 oleeResourceRecordForm.setInstancePOs(instancePOs); 1243 } 1244 return super.navigate(oleeResourceRecordForm); 1245 } 1246 1247 1248 1249 1250 /** 1251 * This method will fetch the eresource and its instance to create PO(s). 1252 * 1253 * @param uifForm 1254 * @param request 1255 * @param response 1256 * @return 1257 */ 1258 1259 @MethodAccessible 1260 @RequestMapping(params = "methodToCall=getPlatformForEResource") 1261 public ModelAndView getPlatformForEResource(@ModelAttribute("KualiForm") UifFormBase uifForm, 1262 HttpServletRequest request, HttpServletResponse response) { 1263 1264 1265// String oleERSIdentifier = request.getParameter("oleERSIdentifier"); 1266 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1267 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument)form.getDocument(); 1268 String oleERSIdentifier = oleeResourceRecordDocument.getOleERSIdentifier(); 1269 List<OLEPlatformAdminUrl> olePlatformAdminUrlList1 = new ArrayList<OLEPlatformAdminUrl>(); 1270 List<String> olePlatformIdList = new ArrayList<>(); 1271 1272 if (oleERSIdentifier!=null) 1273 { 1274 Map map = new HashMap(); 1275 map.put("oleERSIdentifier", oleERSIdentifier); 1276 1277 oleeResourceRecordDocument = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, map); 1278 List<OLEEResourceInstance> oleERSInstances = oleeResourceRecordDocument.getOleERSInstances(); 1279 1280 if (oleERSInstances!=null) 1281 { 1282 for(OLEEResourceInstance oleeResourceInstance : oleERSInstances) { 1283 1284 String olePlatformId = oleeResourceInstance.getPlatformId(); 1285 Map platformMap = new HashMap(); 1286 if(olePlatformId!=null) 1287 { 1288 platformMap.put("olePlatformId", olePlatformId); 1289 OLEPlatformRecordDocument olePlatformRecordDocument = (OLEPlatformRecordDocument)KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEPlatformRecordDocument.class, platformMap); 1290 List<OLEPlatformAdminUrl> olePlatformAdminUrlList = olePlatformRecordDocument.getAdminUrls(); 1291 ((OLEEResourceRecordDocument) form.getDocument()).setOlePlatformAdminUrlList(olePlatformAdminUrlList1); 1292 1293 if (olePlatformAdminUrlList.size()>0) 1294 { 1295 //We are only with unique platform records in this table,so we ignore if more than 1 adminUrls associated with same platform 1296 olePlatformAdminUrlList1.add(olePlatformAdminUrlList.get(0)); 1297 } 1298 else{ 1299 OLEPlatformAdminUrl olePlatformAdminUrl = new OLEPlatformAdminUrl(); 1300 olePlatformAdminUrl.setOlePlatformRecordDocument(olePlatformRecordDocument); 1301 1302 if (!olePlatformIdList.contains(olePlatformRecordDocument.getOlePlatformId())) 1303 { 1304 olePlatformAdminUrlList1.add(olePlatformAdminUrl); 1305 olePlatformIdList.add(olePlatformRecordDocument.getOlePlatformId()); 1306 } 1307 1308 } 1309 HashSet hs = new HashSet(); 1310 hs.addAll(olePlatformAdminUrlList1); 1311 olePlatformAdminUrlList1.clear(); 1312 olePlatformAdminUrlList1.addAll(hs); 1313 ((OLEEResourceRecordDocument) form.getDocument()).setOlePlatformAdminUrlList(olePlatformAdminUrlList1); 1314 } 1315 1316 else 1317 { 1318 LOG.error("No platforms associated with this e-holding"); 1319 } 1320 } 1321 } 1322 else{ 1323 LOG.error("No holdings associated with this e-resource"); 1324 } 1325 } 1326 return super.navigate(form); 1327 } 1328 1329 private String getMask() 1330 { 1331 return "******"; 1332 } 1333 1334 1335 public final String getParameter(String parameterName) { 1336 ParameterKey parameterKey = ParameterKey.create(OLEConstants.APPL_ID, OLEConstants.SELECT_NMSPC, OLEConstants.SELECT_CMPNT, parameterName); 1337 Parameter parameter = CoreServiceApiServiceLocator.getParameterRepositoryService().getParameter(parameterKey); 1338 return parameter != null ? parameter.getValue() : null; 1339 } 1340 1341 @MethodAccessible 1342 @RequestMapping(params = "methodToCall=addPOForInstance") 1343 public ModelAndView addPOForInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1344 HttpServletRequest request, HttpServletResponse response) throws CloneNotSupportedException { 1345 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1346 form.setPoSuccessMessage(null); 1347 form.setPoErrorMessage(null); 1348 int index = form.getIndex(); 1349 List<OLECreatePO> inOleCreatePOs = form.getInstancePOs(); 1350 1351 OLECreatePO instancePO1 = (OLECreatePO) inOleCreatePOs.get(index).clone(); 1352 index++; 1353 1354 instancePO1.setPoId(null); 1355 1356 inOleCreatePOs.add(index, instancePO1); 1357 1358 return super.navigate(form); 1359 1360 } 1361 1362 @MethodAccessible 1363 @RequestMapping(params = "methodToCall=addPOForEResource") 1364 public ModelAndView addPOForEResource(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1365 HttpServletRequest request, HttpServletResponse response) throws CloneNotSupportedException { 1366 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1367 form.setPoSuccessMessage(null); 1368 form.setPoErrorMessage(null); 1369 int index = form.getIndex(); 1370 List<OLECreatePO> eResourceCreatePOs = form.geteResourcePOs(); 1371 1372 OLECreatePO eResourcePO1 = (OLECreatePO) eResourceCreatePOs.get(index).clone(); 1373 index++; 1374 1375 eResourcePO1.setPoId(null); 1376 1377 eResourceCreatePOs.add(index, eResourcePO1); 1378 1379 return super.navigate(form); 1380 1381 } 1382 1383 @MethodAccessible 1384 @RequestMapping(params = "methodToCall=synchronizeWithGokb") 1385 public ModelAndView synchronizeWithGokb(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1386 HttpServletRequest request, HttpServletResponse response) { 1387 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1388 1389 1390 return super.navigate(form); 1391 1392 } 1393 1394 @MethodAccessible 1395 @RequestMapping(params = "methodToCall=createPOs") 1396 public ModelAndView createPOs(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1397 HttpServletRequest request, HttpServletResponse response) throws Exception { 1398 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 1399 oleeResourceRecordForm.setPoSuccessMessage(null); 1400 oleeResourceRecordForm.setPoErrorMessage(null); 1401 StringBuffer poSuccessMessage = new StringBuffer(); 1402 StringBuffer poErrorMessage = new StringBuffer(); 1403 String selectedPOType = oleeResourceRecordForm.getSelectedPOType(); 1404 List<OLECreatePO> posToCreateForEholdings = new ArrayList<>(); 1405 List<OLECreatePO> posToCreateForHoldings = new ArrayList<>(); 1406 List<OLECreatePO> posToCreateForEResources = new ArrayList<>(); 1407 List<OLECreatePO> instancePOs = oleeResourceRecordForm.getInstancePOs(); 1408 List<OLECreatePO> eResourcePOs = oleeResourceRecordForm.geteResourcePOs(); 1409 for (OLECreatePO instancePO : instancePOs) { 1410 if (instancePO.isSelectFlag()) { 1411 String validationMsg = getOleEResourceSearchService().validateFundVendorPrice(instancePO); 1412 if (validationMsg.length() == 0) { 1413 Map createPOMap = new HashMap(); 1414 createPOMap.put("oleERSIdentifier", instancePO.getOleERSIdentifier()); 1415 createPOMap.put("instanceId", instancePO.getInstanceId()); 1416 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLECreatePO.class, createPOMap); 1417 if (instancePO.getInstanceFlag() != null && instancePO.getInstanceFlag().equalsIgnoreCase("false")) { 1418 posToCreateForEholdings.add(instancePO); 1419 } else if (instancePO.getInstanceFlag() != null && instancePO.getInstanceFlag().equalsIgnoreCase("true")) { 1420 posToCreateForHoldings.add(instancePO); 1421 } 1422 } else { 1423 poErrorMessage.append(validationMsg.toString()); 1424 } 1425 } 1426 } 1427 for (OLECreatePO eResourcePo : eResourcePOs) { 1428 if (eResourcePo.isSelectFlag()) { 1429 String validationMsg = getOleEResourceSearchService().validateFundVendorPrice(eResourcePo); 1430 if (validationMsg.length() == 0) { 1431 Map createPOMap = new HashMap(); 1432 createPOMap.put("oleERSIdentifier", eResourcePo.getOleERSIdentifier()); 1433 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLECreatePO.class, createPOMap); 1434 if (oleCreatePOs != null) { 1435 for (OLECreatePO oleCreatePO : oleCreatePOs) { 1436 if (oleCreatePO.getInstanceId() == null) { 1437 KRADServiceLocator.getLegacyDataAdapter().delete(oleCreatePO); 1438 } 1439 } 1440 } 1441 posToCreateForEResources.add(eResourcePo); 1442 } else { 1443 poErrorMessage.append(validationMsg.toString()); 1444 } 1445 } 1446 } 1447 List<OleOrderRecord> oleOrderRecordList = new ArrayList<>(); 1448 if (posToCreateForEholdings.size() > 0) { 1449 oleOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForEholdings, OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_ELECTRONIC,getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.LOCATION,OLEConstants.ERESOURCE_CMPNT))); 1450 } 1451 if (posToCreateForHoldings.size() > 0) { 1452 oleOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForHoldings, OLEConstants.ORDER_RECORD_IMPORT_MARC_ONLY_PRINT,getOleEResourceSearchService().getParameter(OLEConstants.OLEEResourceRecord.LOCATION,OLEConstants.ERESOURCE_CMPNT))); 1453 } 1454 if (posToCreateForEResources.size()>0){ 1455 oleOrderRecordList.addAll(getOleEResourceSearchService().fetchOleOrderRecordList(posToCreateForEResources, "E-Resource", "E-Resource")); 1456 } 1457 if (selectedPOType.equals(OLEConstants.OLEEResourceRecord.ONE_PO_PER_TITLE)) { 1458 for (OleOrderRecord oleOrderRecord : oleOrderRecordList) { 1459 if (oleOrderRecord.getOleTxRecord() != null) { 1460 OleRequisitionDocument requisitionDocument = null; 1461 try { 1462 requisitionDocument = getOleReqPOCreateDocumentService().createRequisitionDocument(); 1463 requisitionDocument.setRequisitionSourceCode(oleOrderRecord.getOleTxRecord().getRequisitionSource()); 1464 Map purchaseOrderTypeMap = new HashMap(); 1465 purchaseOrderTypeMap.put(OLEConstants.PURCHASE_ORDER_TYPE_ID, oleOrderRecord.getOleTxRecord().getOrderType()); 1466 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap); 1467 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) { 1468 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId()); 1469 } 1470 getOleReqPOCreateDocumentService().setDocumentValues(requisitionDocument, oleOrderRecord); 1471 requisitionDocument.setItems(getOleEResourceSearchService().generateItemList(oleOrderRecord, requisitionDocument)); 1472 1473 RequisitionService requisitionService = SpringContext.getBean(RequisitionService.class); 1474 boolean apoRuleFlag = requisitionService.isAutomaticPurchaseOrderAllowed(requisitionDocument); 1475 if (!apoRuleFlag) { 1476 oleOrderRecord.getMessageMap().put(OLEConstants.IS_APO_RULE, true); 1477 } 1478 requisitionDocument.setApplicationDocumentStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS); 1479 getRequisitionCreateDocumentService().saveRequisitionDocuments(requisitionDocument); 1480 if (oleOrderRecord.getOleBibRecord() != null) { 1481 poSuccessMessage.append("Requisition Document created for title '" + oleOrderRecord.getOleBibRecord().getBib().getTitle() + "' - " + requisitionDocument.getPurapDocumentIdentifier()); 1482 } else if (oleOrderRecord.getOleERSIdentifier() != null) { 1483 OLEEResourceRecordDocument oleeResourceRecordDocument = KRADServiceLocator.getLegacyDataAdapter().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, oleOrderRecord.getOleERSIdentifier()); 1484 if (oleeResourceRecordDocument != null) { 1485 poSuccessMessage.append("Requisition Document created for title '" + oleeResourceRecordDocument.getTitle() + "' - " + requisitionDocument.getPurapDocumentIdentifier()); 1486 } 1487 } 1488 poSuccessMessage.append(OLEConstants.BREAK); 1489 1490 } catch (Exception e) { 1491 e.printStackTrace(); 1492 oleOrderRecord.addMessageToMap(OLEConstants.IS_VALID_RECORD, false); 1493 } 1494 } 1495 } 1496 } else if (selectedPOType.equals(OLEConstants.OLEEResourceRecord.ONE_PO_WITH_ALL_TITLES)) { 1497 OleRequisitionDocument requisitionDocument = null; 1498 try { 1499 requisitionDocument = getOleReqPOCreateDocumentService().createRequisitionDocument(); 1500 requisitionDocument.setRequisitionSourceCode(oleOrderRecordList.get(0).getOleTxRecord().getRequisitionSource()); 1501 Map purchaseOrderTypeMap = new HashMap(); 1502 purchaseOrderTypeMap.put(OLEConstants.PURCHASE_ORDER_TYPE_ID, oleOrderRecordList.get(0).getOleTxRecord().getOrderType()); 1503 List<PurchaseOrderType> purchaseOrderTypeDocumentList = (List) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(PurchaseOrderType.class, purchaseOrderTypeMap); 1504 if (purchaseOrderTypeDocumentList != null && purchaseOrderTypeDocumentList.size() > 0) { 1505 requisitionDocument.setPurchaseOrderTypeId(purchaseOrderTypeDocumentList.get(0).getPurchaseOrderTypeId()); 1506 } 1507 getOleReqPOCreateDocumentService().setDocumentValues(requisitionDocument, oleOrderRecordList.get(0)); 1508 requisitionDocument.setItems(getOleEResourceSearchService().generateMultipleItemsForOneRequisition(oleOrderRecordList, requisitionDocument)); 1509 1510 requisitionDocument.setApplicationDocumentStatus(PurapConstants.RequisitionStatuses.APPDOC_IN_PROCESS); 1511 getRequisitionCreateDocumentService().saveRequisitionDocuments(requisitionDocument); 1512 String tiles = new String(); 1513 for (OleOrderRecord oleOrderRecord : oleOrderRecordList) { 1514 if (oleOrderRecord.getOleBibRecord() != null) { 1515 tiles = tiles.concat("'"); 1516 tiles = tiles.concat(oleOrderRecord.getOleBibRecord().getBib().getTitle()); 1517 tiles = tiles.concat("'"); 1518 tiles = tiles.concat(" "); 1519 } else if (oleOrderRecord.getOleERSIdentifier() != null) { 1520 OLEEResourceRecordDocument oleeResourceRecordDocument = KRADServiceLocator.getLegacyDataAdapter().findBySinglePrimaryKey(OLEEResourceRecordDocument.class, oleOrderRecord.getOleERSIdentifier()); 1521 if (oleeResourceRecordDocument != null) { 1522 tiles = tiles.concat("'"); 1523 tiles = tiles.concat(oleeResourceRecordDocument.getTitle()); 1524 tiles = tiles.concat("'"); 1525 tiles = tiles.concat(" "); 1526 } 1527 } 1528 } 1529 poSuccessMessage.append("Requisition Document created for titles " + tiles + " - " + requisitionDocument.getPurapDocumentIdentifier()); 1530 } catch (Exception e) { 1531 e.printStackTrace(); 1532 } 1533 } 1534 if (poSuccessMessage.length() > 1) { 1535 oleeResourceRecordForm.setPoSuccessMessage(poSuccessMessage.toString()); 1536 } 1537 if (poErrorMessage.length() > 1) { 1538 oleeResourceRecordForm.setPoErrorMessage(poErrorMessage.toString()); 1539 } 1540 return super.navigate(oleeResourceRecordForm); 1541 } 1542 1543 @MethodAccessible 1544 @RequestMapping(params = "methodToCall=savePoChanges") 1545 public ModelAndView savePoChanges(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1546 HttpServletRequest request, HttpServletResponse response) { 1547 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 1548 oleeResourceRecordForm.setPoSuccessMessage(null); 1549 oleeResourceRecordForm.setPoErrorMessage(null); 1550 for (OLECreatePO eResourcePO : oleeResourceRecordForm.geteResourcePOs()) { 1551 if (eResourcePO.isSelectFlag()) { 1552 if (eResourcePO.getFundCode() != null) { 1553 Map fundMap = new HashMap(); 1554 fundMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, eResourcePO.getFundCode()); 1555 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleFundCode.class, fundMap); 1556 if (oleFundCode != null) { 1557 eResourcePO.setFundId(oleFundCode.getFundCodeId()); 1558 } 1559 } 1560 if (eResourcePO.getCreatePOId() != null) { 1561 KRADServiceLocator.getLegacyDataAdapter().save(eResourcePO); 1562 } else { 1563 Map createPOMap = new HashMap(); 1564 createPOMap.put("oleERSIdentifier", eResourcePO.getOleERSIdentifier()); 1565 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLECreatePO.class, createPOMap); 1566 if (oleCreatePOs != null && oleCreatePOs.size() > 0) { 1567 for (OLECreatePO oleCreatePO : oleCreatePOs) { 1568 if (oleCreatePO.getInstanceId() == null) { 1569 eResourcePO.setCreatePOId(oleCreatePO.getCreatePOId()); 1570 eResourcePO.setObjectId(oleCreatePO.getObjectId()); 1571 eResourcePO.setVersionNumber(oleCreatePO.getVersionNumber()); 1572 } 1573 } 1574 } 1575 KRADServiceLocator.getLegacyDataAdapter().save(eResourcePO); 1576 } 1577 } 1578 } 1579 for (OLECreatePO instancePO : oleeResourceRecordForm.getInstancePOs()) { 1580 if (instancePO.isSelectFlag()) { 1581 if (instancePO.getFundCode() != null) { 1582 Map fundMap = new HashMap(); 1583 fundMap.put(OLEConstants.OLEEResourceRecord.FUND_CODE, instancePO.getFundCode()); 1584 OleFundCode oleFundCode = KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OleFundCode.class, fundMap); 1585 if (oleFundCode != null) { 1586 instancePO.setFundId(oleFundCode.getFundCodeId()); 1587 } 1588 } 1589 if (instancePO.getCreatePOId() != null) { 1590 KRADServiceLocator.getLegacyDataAdapter().save(instancePO); 1591 } else { 1592 Map createPOMap = new HashMap(); 1593 createPOMap.put("oleERSIdentifier", instancePO.getOleERSIdentifier()); 1594 createPOMap.put("instanceId", instancePO.getInstanceId()); 1595 List<OLECreatePO> oleCreatePOs = (List<OLECreatePO>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLECreatePO.class, createPOMap); 1596 if (oleCreatePOs != null && oleCreatePOs.size() > 0) { 1597 OLECreatePO oleCreatePO = oleCreatePOs.get(0); 1598 instancePO.setCreatePOId(oleCreatePO.getCreatePOId()); 1599 instancePO.setObjectId(oleCreatePO.getObjectId()); 1600 instancePO.setVersionNumber(oleCreatePO.getVersionNumber()); 1601 } 1602 KRADServiceLocator.getLegacyDataAdapter().save(instancePO); 1603 } 1604 } 1605 } 1606 oleeResourceRecordForm.setPoSuccessMessage("Changes have been saved successfully"); 1607 return super.navigate(oleeResourceRecordForm); 1608 } 1609 1610 @MethodAccessible 1611 @RequestMapping(params = "methodToCall=next") 1612 public ModelAndView next(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1613 HttpServletRequest request, HttpServletResponse response) { 1614 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1615 return getModelAndView(form, "OLEEResourceRecordView"); 1616 } 1617 1618 @MethodAccessible 1619 @RequestMapping(params = "methodToCall=saveRelationship") 1620 public ModelAndView saveRelationship(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1621 HttpServletRequest request, HttpServletResponse response) { 1622 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1623 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1624 ListIterator<OLELinkedEresource> oleLinkedEresourceListIterator = oleeResourceRecordDocument.getOleLinkedEresources().listIterator(); 1625 while(oleLinkedEresourceListIterator.hasNext()){ 1626 OLELinkedEresource linkedEresource = oleLinkedEresourceListIterator.next(); 1627 Map<String, String> tempId = new HashMap<String, String>(); 1628 tempId.put(OLEConstants.OLEEResourceRecord.ERESOURCE_IDENTIFIER, linkedEresource.getLinkedERSIdentifier()); 1629 OLEEResourceRecordDocument parentDocument = (OLEEResourceRecordDocument) KRADServiceLocatorWeb.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceRecordDocument.class, tempId); 1630 Person principalPerson = SpringContext.getBean(PersonService.class).getPerson(GlobalVariables.getUserSession().getPerson().getPrincipalId()); 1631 try { 1632 parentDocument.getDocumentHeader().setWorkflowDocument(KRADServiceLocatorWeb.getWorkflowDocumentService().loadWorkflowDocument(parentDocument.getDocumentNumber(), principalPerson)); 1633 } catch (WorkflowException e) { 1634 e.printStackTrace(); 1635 } 1636 String removeChild= form.getActionParamaterValue("removeChild"); 1637 if(removeChild.equalsIgnoreCase("no")){ 1638 linkedEresource.setRemoveRelationShip(false); 1639 return getModelAndView(form); 1640 } 1641 if(linkedEresource.getRelationShipType().equalsIgnoreCase("child") && linkedEresource.isRemoveRelationShip()) { 1642 if(oleeResourceRecordDocument.getRemoveOrRelinkToParent() !=null && oleeResourceRecordDocument.getRemoveOrRelinkToParent().equalsIgnoreCase("relinkToParent")){ 1643 for(OLEEResourceInstance instance : linkedEresource.getOleeResourceRecordDocument().getOleERSInstances()){ 1644 Map criteriaMap = new HashMap(); 1645 criteriaMap.put("oleEResourceInstanceId", instance.getOleEResourceInstanceId()); 1646 OLEEResourceInstance oleeResourceInstance = KRADServiceLocator.getLegacyDataAdapter().findByPrimaryKey(OLEEResourceInstance.class, criteriaMap); 1647 oleeResourceInstance.setOleERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier()); 1648 oleLinkedEresourceListIterator.remove(); 1649 } 1650 } else if(oleeResourceRecordDocument.getRemoveOrRelinkToParent() !=null && oleeResourceRecordDocument.getRemoveOrRelinkToParent().equalsIgnoreCase("removelink")) { 1651 Map criteriaMap = new HashMap(); 1652 criteriaMap.put("linkedERSIdentifier", linkedEresource.getLinkedERSIdentifier()); 1653 criteriaMap.put("oleERSIdentifier", linkedEresource.getOleERSIdentifier()); 1654 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLELinkedEresource.class, criteriaMap); 1655 criteriaMap.clear(); 1656 criteriaMap.put("oleERSIdentifier", linkedEresource.getLinkedERSIdentifier()); 1657 criteriaMap.put("linkedERSIdentifier", linkedEresource.getOleERSIdentifier()); 1658 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLELinkedEresource.class, criteriaMap); 1659 oleLinkedEresourceListIterator.remove(); 1660 } 1661 }else if(linkedEresource.getRelationShipType().equalsIgnoreCase("parent")) { 1662 String removeParent = form.getActionParamaterValue("removeParent"); 1663 if(removeParent.equalsIgnoreCase("yes")){ 1664 Map criteriaMap = new HashMap(); 1665 criteriaMap.put("linkedERSIdentifier", linkedEresource.getLinkedERSIdentifier()); 1666 criteriaMap.put("oleERSIdentifier", linkedEresource.getOleERSIdentifier()); 1667 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLELinkedEresource.class, criteriaMap); 1668 criteriaMap.clear(); 1669 criteriaMap.put("oleERSIdentifier", linkedEresource.getLinkedERSIdentifier()); 1670 criteriaMap.put("linkedERSIdentifier", linkedEresource.getOleERSIdentifier()); 1671 KRADServiceLocator.getLegacyDataAdapter().deleteMatching(OLELinkedEresource.class, criteriaMap); 1672 oleLinkedEresourceListIterator.remove(); 1673 } 1674 } 1675 linkedEresource.setRemoveRelationShip(false); 1676 oleeResourceRecordDocument.setOleLinkedEresources(null); 1677 oleEResourceSearchService.getPOInvoiceForERS(oleeResourceRecordDocument); 1678 } 1679 return getModelAndView(form); 1680 } 1681 1682 @MethodAccessible 1683 @RequestMapping(params = "methodToCall=saveResultToEventlog") 1684 public ModelAndView saveResultToEventlog(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1685 HttpServletRequest request, HttpServletResponse response) { 1686 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1687 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1688 OLEEResourceEventLog oleERSEventLog = new OLEEResourceEventLog(); 1689 oleERSEventLog.setEventType(OLEConstants.OleLicenseRequest.USER); 1690 oleERSEventLog.setCurrentTimeStamp(); 1691 oleERSEventLog.setOleERSIdentifier(oleeResourceRecordDocument.getDocumentNumber()); 1692 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()); 1693 oleeResourceRecordDocument.getOleERSEventLogs().add(oleERSEventLog); 1694 return super.navigate(form); 1695 } 1696 1697 @MethodAccessible 1698 @RequestMapping(params = "methodToCall=downloadCsv") 1699 public ModelAndView downloadCsv(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1700 HttpServletRequest request, HttpServletResponse response) { 1701 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1702 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1703 response.setHeader("Content-disposition", "attachment;filename=PriceIncreaseAnalysis.csv"); 1704 response.setHeader("Expires", "0"); 1705 response.setHeader("Cache-Control", "must-revalidate, post-check=0, pre-check=0"); 1706 response.setHeader("Pragma", "public"); 1707 response.setContentType("text"); 1708 StringBuffer sb = new StringBuffer(); 1709 sb.append("YearCost"); 1710 sb.append(","); 1711 sb.append("quote"); 1712 sb.append(","); 1713 sb.append("CostIncrease"); 1714 sb.append(","); 1715 sb.append("PercentIncrease"); 1716 sb.append("\n"); 1717 1718 sb.append(oleeResourceRecordDocument.getFiscalYearCost()); 1719 sb.append(","); 1720 sb.append(oleeResourceRecordDocument.getYearPriceQuote()); 1721 sb.append(","); 1722 sb.append(oleeResourceRecordDocument.getCostIncrease()); 1723 sb.append(","); 1724 sb.append(oleeResourceRecordDocument.getPercentageIncrease()); 1725 sb.append("\n"); 1726 1727 byte [] txt = sb.toString().getBytes(); 1728 OutputStream out; 1729 try { 1730 out = response.getOutputStream(); 1731 out.write(txt); 1732 out.flush(); 1733 out.close(); 1734 } catch (IOException e) { 1735 e.printStackTrace(); 1736 } 1737 return getModelAndView(form); 1738 } 1739 1740 @MethodAccessible 1741 @RequestMapping(params = "methodToCall=generateEmailText") 1742 public ModelAndView generateEmailText(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1743 HttpServletRequest request, HttpServletResponse response) { 1744 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1745 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1746 form.setEmailFlag(true); 1747 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); 1748 return getModelAndView(form); 1749 } 1750 1751 @MethodAccessible 1752 @RequestMapping(params = "methodToCall=calculateIncrease") 1753 public ModelAndView calculateIncrease(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1754 HttpServletRequest request, HttpServletResponse response) { 1755 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1756 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 1757 List<OLEEResourceInvoices> oleERSInvoices = oleeResourceRecordDocument.getOleERSInvoices(); 1758 int fiscalYearCost = 0; 1759 for(OLEEResourceInvoices oleeResourceInvoices : oleERSInvoices){ 1760 fiscalYearCost = fiscalYearCost + Integer.valueOf(oleeResourceInvoices.getInvoicedAmount()); 1761 } 1762 double cost = oleeResourceRecordDocument.getYearPriceQuote() - oleeResourceRecordDocument.getFiscalYearCost(); 1763 oleeResourceRecordDocument.setCostIncrease(Math.round(cost)); 1764 double percentage = (cost / oleeResourceRecordDocument.getFiscalYearCost()) * 100; 1765 oleeResourceRecordDocument.setPercentageIncrease(Math.round(percentage)); 1766 return super.navigate(form); 1767 } 1768 1769 @MethodAccessible 1770 @RequestMapping(params = "methodToCall=closeDialog") 1771 public ModelAndView closeDialog(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 1772 HttpServletRequest request, HttpServletResponse response) { 1773 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 1774 form.setEmailFlag(false); 1775 return getModelAndView(form); 1776 } 1777 1778 @RequestMapping(params = "methodToCall=search") 1779 public ModelAndView search(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 1780 HttpServletRequest request, HttpServletResponse response) { 1781 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form; 1782 String formKey = (String) request.getSession().getValue("formKeyValue"); 1783 List<String> oleEResIdentifiers = new ArrayList<>(); 1784 if (StringUtils.isNotBlank(formKey)) { 1785 OLEEResourceRecordForm sessionForm = (OLEEResourceRecordForm) GlobalVariables.getUifFormManager().getSessionForm(formKey); 1786 OLEEResourceRecordDocument oleEResourceRecordDocument = (OLEEResourceRecordDocument) sessionForm.getDocument(); 1787 oleEResIdentifiers.add(oleEResourceRecordDocument.getOleERSIdentifier()); 1788 List<OLELinkedEresource> oleLinkedEresources = oleEResourceRecordDocument.getOleLinkedEresources(); 1789 for (OLELinkedEresource oleLinkedEresource : oleLinkedEresources) { 1790 oleEResIdentifiers.add(oleLinkedEresource.getLinkedERSIdentifier()); 1791 } 1792 } 1793 OLEEResourceSearchServiceImpl oleEResourceSearchService = GlobalResourceLoader.getService(OLEConstants.OLEEResourceRecord.ERESOURSE_SEARCH_SERVICE); 1794 List<OLESearchCondition> oleSearchConditionsList = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList(); 1795 List<OLEEResourceRecordDocument> eresourceDocumentList = new ArrayList<OLEEResourceRecordDocument>(); 1796 List<OLEEResourceRecordDocument> eresourceList = new ArrayList<OLEEResourceRecordDocument>(); 1797 try { 1798 eresourceList = oleEResourceSearchService.performSearch(oleSearchConditionsList); 1799 } catch (Exception e) { 1800 LOG.error("Exception while hitting the performSearch()" + e.getMessage()); 1801 } 1802 if (oleEResIdentifiers != null && oleEResIdentifiers.size()>0) { 1803 List<OLEEResourceRecordDocument> oleeResourceRecordDocumentList = new ArrayList<OLEEResourceRecordDocument>(); 1804 for (OLEEResourceRecordDocument oleeResourceRecordDocument : eresourceList) { 1805 if (!oleEResIdentifiers.contains(oleeResourceRecordDocument.getOleERSIdentifier())) { 1806 oleeResourceRecordDocumentList.add(oleeResourceRecordDocument); 1807 oleeResourceRecordDocument.setRelationshipType("child"); 1808 } 1809 } 1810 eresourceList = oleeResourceRecordDocumentList; 1811 for (OLEEResourceRecordDocument oleEResourceRecordDocument : eresourceList) { 1812 Map criteriaMap = new HashMap(); 1813 criteriaMap.put("oleERSIdentifier", oleEResourceRecordDocument.getOleERSIdentifier()); 1814 List<OLELinkedEresource> oleLinkedEresourceList = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, criteriaMap); 1815 oleEResourceRecordDocument.setOleLinkedEresources(oleLinkedEresourceList); 1816 } 1817 } 1818 if (oleeResourceRecordForm.getStatus() != null) { 1819 eresourceList = oleEResourceSearchService.statusNotNull(eresourceList, oleeResourceRecordForm.getStatus()); 1820 } 1821 if (oleeResourceRecordForm.iseResStatusDate()) { 1822 eresourceDocumentList = oleEResourceSearchService.filterEResRecBystatusDate(oleeResourceRecordForm.getBeginDate(),oleeResourceRecordForm.getEndDate(),eresourceList); 1823 oleeResourceRecordForm.setEresourceDocumentList(eresourceDocumentList); 1824 } else { 1825 oleeResourceRecordForm.setEresourceDocumentList(eresourceList); 1826 } 1827 List<OLEEResourceRecordDocument> eresDocumentList = oleeResourceRecordForm.getEresourceDocumentList(); 1828 oleEResourceSearchService.removeDuplicateEresDocumentsFromList(eresDocumentList); 1829 if (!GlobalVariables.getMessageMap().hasMessages()){ 1830 if (oleeResourceRecordForm.getEresourceDocumentList().size()==0) 1831 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_ERRORS, OLEConstants.NO_RECORD_FOUND); 1832 } 1833 else { 1834 oleeResourceRecordForm.setEresourceDocumentList(null); 1835 } 1836 return getModelAndView(oleeResourceRecordForm); 1837 } 1838 1839 @MethodAccessible 1840 @RequestMapping(params = "methodToCall=linkEResource") 1841 public ModelAndView linkEResource(@ModelAttribute("KualiForm") DocumentFormBase form, BindingResult result, 1842 HttpServletRequest request, HttpServletResponse response)throws Exception{ 1843 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) form; 1844 oleeResourceRecordForm.setMessage(null); 1845 List<OLEEResourceRecordDocument> oleeResourceRecordDocumentList = oleeResourceRecordForm.getEresourceDocumentList(); 1846 String formKey = (String) request.getSession().getValue("formKeyValue"); 1847 OLEEResourceRecordForm sessionForm; 1848 if (StringUtils.isNotBlank(formKey)) { 1849 sessionForm = (OLEEResourceRecordForm) GlobalVariables.getUifFormManager().getSessionForm(formKey); 1850 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) sessionForm.getDocument(); 1851 List<OLELinkedEresource> oleLinkedEresources = oleeResourceRecordDocument.getOleLinkedEresources(); 1852 int parentCount = 0; 1853 int selectCount = 0; 1854 for (OLEEResourceRecordDocument eResourceRecordDocument : oleeResourceRecordDocumentList) { 1855 if (eResourceRecordDocument.isSelectEResFlag()) { 1856 selectCount++; 1857 if (eResourceRecordDocument.getRelationshipType().equals("parent")) { 1858 parentCount++; 1859 if (parentCount > 1) { 1860 break; 1861 } 1862 } 1863 } 1864 } 1865 if (selectCount == 0){ 1866 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_SELECT_ERESOURCE)); 1867 return getModelAndView(oleeResourceRecordForm); 1868 } 1869 else if (parentCount > 1) { 1870 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_ERESOURCE_ONLY_ONE_PARENT)); 1871 return getModelAndView(oleeResourceRecordForm); 1872 } 1873 int linkedParentCount = 0; 1874 for (OLELinkedEresource linkedEresource : oleLinkedEresources) { 1875 if (linkedEresource.getRelationShipType().equals("parent")) { 1876 linkedParentCount++; 1877 } 1878 } 1879 if (linkedParentCount > 0 && parentCount > 0) { 1880 oleeResourceRecordForm.setMessage(SpringContext.getBean(ConfigurationService.class).getPropertyValueAsString(PurapKeyConstants.ERROR_ERESOURCE_ALREADY_HAS_PARENT)); 1881 return getModelAndView(oleeResourceRecordForm); 1882 } 1883 StringBuffer message = new StringBuffer(); 1884 List<String> ids = new ArrayList<String>(); 1885 boolean messageText = false; 1886 for (OLEEResourceRecordDocument selectedeResourceRecordDocument : oleeResourceRecordDocumentList) { 1887 if (selectedeResourceRecordDocument.isSelectEResFlag()) { 1888 for(OLELinkedEresource linkedEresource : selectedeResourceRecordDocument.getOleLinkedEresources()){ 1889 if (linkedEresource.getRelationShipType().equalsIgnoreCase("parent")) { 1890 message.append(selectedeResourceRecordDocument.getTitle()); 1891 message.append(", "); 1892 ids.add(selectedeResourceRecordDocument.getOleERSIdentifier()); 1893 } else { 1894 Map map = new HashMap(); 1895 map.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier()); 1896 map.put("relationShipType", "child"); 1897 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, map); 1898 OLELinkedEresource oleLinkedEresource = eResource.get(0); 1899 String chain = oleLinkedEresource.getChainString(); 1900 if(chain.contains(selectedeResourceRecordDocument.getOleERSIdentifier())){ 1901 message.append(selectedeResourceRecordDocument.getTitle()); 1902 message.append(", "); 1903 messageText = true; 1904 ids.add(selectedeResourceRecordDocument.getOleERSIdentifier()); 1905 } 1906 } 1907 } 1908 } 1909 } 1910 Iterator<OLEEResourceRecordDocument> iterator = oleeResourceRecordDocumentList.iterator(); 1911 for(String id : ids){ 1912 while(iterator.hasNext()){ 1913 if(id.equalsIgnoreCase(iterator.next().getOleERSIdentifier())){ 1914 iterator.remove(); 1915 break; 1916 } 1917 } 1918 } 1919 for (OLEEResourceRecordDocument selectedeResourceRecordDocument : oleeResourceRecordDocumentList) { 1920 if (selectedeResourceRecordDocument.isSelectEResFlag()) { 1921 1922 Map map = new HashMap(); 1923 map.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier()); 1924 map.put("relationShipType", "child"); 1925 List<OLELinkedEresource> eResource1 = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, map); 1926 if(eResource1.size()>0){ 1927 OLELinkedEresource oleLinkedEresource1 = eResource1.get(0); 1928 String chain = oleLinkedEresource1.getChainString(); 1929 if(!chain.contains(selectedeResourceRecordDocument.getOleERSIdentifier())){ 1930 OLELinkedEresource oleLinkedEresource = new OLELinkedEresource(); 1931 oleLinkedEresource.setLinkedERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier()); 1932 oleLinkedEresource.setRelationShipType(selectedeResourceRecordDocument.getRelationshipType()); 1933 if(selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("child")){ 1934 Map linkedEresourceMap = new HashMap(); 1935 linkedEresourceMap.put("linkedERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier()); 1936 linkedEresourceMap.put("relationShipType", "child"); 1937 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, linkedEresourceMap); 1938 if(eResource.size()>0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())){ 1939 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1940 }else{ 1941 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1942 } 1943 } 1944 oleLinkedEresources.add(oleLinkedEresource); 1945 OLELinkedEresource linkedEresource = new OLELinkedEresource(); 1946 linkedEresource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier()); 1947 linkedEresource.setOleERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier()); 1948 if(selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("parent")){ 1949 linkedEresource.setRelationShipType("child"); 1950 Map eResourceMap = new HashMap(); 1951 eResourceMap.put("oleERSIdentifier", selectedeResourceRecordDocument.getOleERSIdentifier()); 1952 eResourceMap.put("relationShipType", "child"); 1953 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, eResourceMap); 1954 if(eResource.size()>0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())){ 1955 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1956 }else{ 1957 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1958 } 1959 }else{ 1960 linkedEresource.setRelationShipType("parent"); 1961 } 1962 KRADServiceLocator.getLegacyDataAdapter().save(linkedEresource); 1963 } 1964 }else{ 1965 OLELinkedEresource oleLinkedEresource = new OLELinkedEresource(); 1966 oleLinkedEresource.setLinkedERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier()); 1967 oleLinkedEresource.setRelationShipType(selectedeResourceRecordDocument.getRelationshipType()); 1968 if(selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("child")){ 1969 Map linkedEresourceMap = new HashMap(); 1970 linkedEresourceMap.put("oleERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier()); 1971 linkedEresourceMap.put("relationShipType", "child"); 1972 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, linkedEresourceMap); 1973 if(eResource.size()>0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())){ 1974 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1975 }else{ 1976 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1977 } 1978 } 1979 oleLinkedEresources.add(oleLinkedEresource); 1980 OLELinkedEresource linkedEresource = new OLELinkedEresource(); 1981 linkedEresource.setLinkedERSIdentifier(oleeResourceRecordDocument.getOleERSIdentifier()); 1982 linkedEresource.setOleERSIdentifier(selectedeResourceRecordDocument.getOleERSIdentifier()); 1983 if(selectedeResourceRecordDocument.getRelationshipType().equalsIgnoreCase("parent")){ 1984 linkedEresource.setRelationShipType("child"); 1985 Map eResourceMap = new HashMap(); 1986 eResourceMap.put("oleERSIdentifier", selectedeResourceRecordDocument.getOleERSIdentifier()); 1987 eResourceMap.put("relationShipType", "child"); 1988 List<OLELinkedEresource> eResource = (List<OLELinkedEresource>) KRADServiceLocator.getLegacyDataAdapter().findMatching(OLELinkedEresource.class, eResourceMap); 1989 if(eResource.size()>0 && StringUtils.isNotEmpty(eResource.get(0).getChainString())){ 1990 oleLinkedEresource.setChainString(eResource.get(0).getChainString() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1991 }else{ 1992 oleLinkedEresource.setChainString(oleeResourceRecordDocument.getOleERSIdentifier() + ":" +selectedeResourceRecordDocument.getOleERSIdentifier()); 1993 } 1994 }else{ 1995 linkedEresource.setRelationShipType("parent"); 1996 } 1997 KRADServiceLocator.getLegacyDataAdapter().save(linkedEresource); 1998 } 1999 2000 } 2001 } 2002 if (message.length() > 0 && !messageText) { 2003 String format = String.format("The following documents (%s) can not be linked, since it already has parent. ", message.substring(0, message.lastIndexOf(","))); 2004 oleeResourceRecordForm.setMessage(format); 2005 }else if(message.length() > 0 && messageText) { 2006 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(","))); 2007 oleeResourceRecordForm.setMessage(format); 2008 } 2009 } 2010 return getModelAndView(oleeResourceRecordForm); 2011 } 2012 2013 @MethodAccessible 2014 @RequestMapping(params = "methodToCall=delete") 2015 public ModelAndView delete(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2016 HttpServletRequest request, HttpServletResponse response) { 2017 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 2018 OLEEResourceRecordDocument document = (OLEEResourceRecordDocument)form.getDocument(); 2019 List<OLEEResourceInstance> oleeResourceInstances = document.getOleERSInstances(); 2020 List<OLEEResourceLicense> oleERSLicenses = document.getOleERSLicenseRequests(); 2021 List<OLELinkedEresource> oleLikedEResources = document.getOleLinkedEresources(); 2022 List<OLEEResourcePO> oleEResourcePOList = document.getOleERSPOItems(); 2023 2024 if (oleeResourceInstances.size()>0 || oleERSLicenses.size()>0 || oleLikedEResources.size()>0 || oleEResourcePOList.size()>0) 2025 { 2026 document.setAccessStatus("Active"); 2027 } 2028 else{ 2029 document.setAccessStatus("Inactive"); 2030 KRADServiceLocator.getLegacyDataAdapter().saveDocument(document); 2031 GlobalVariables.getMessageMap().putError(KRADConstants.GLOBAL_MESSAGES, OLEConstants.OLEEResourceRecord.ERESOURCE_HAS_BEEN_DELETED); 2032 } 2033 return getModelAndView(form); 2034 } 2035 2036 @MethodAccessible 2037 @RequestMapping(params = "methodToCall=deleteInstance") 2038 public ModelAndView deleteInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2039 HttpServletRequest request, HttpServletResponse response) { 2040 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 2041 2042 OLEEResourceRecordDocument document = (OLEEResourceRecordDocument)form.getDocument(); 2043 List<OLEEResourceInstance> oleInstancesDeleteList = new ArrayList<>(); 2044 List<OLEEResourceInstance> oleInstancesAddList = new ArrayList<>(); 2045 List<OLEEResourceInstance> oleERSInstances = document.getOleERSInstances(); 2046 if (oleERSInstances!=null) { 2047 for(OLEEResourceInstance oleeResourceInstance : oleERSInstances) { 2048 int purchaseOrderCount = 0; 2049 if (oleeResourceInstance.isSelect()) { 2050 String instanceId = oleeResourceInstance.getInstanceId(); 2051 Map instanceMap = new HashMap(); 2052 instanceMap.put("instanceId", instanceId); 2053 List<OleCopy> oleCopyList = (List<OleCopy>)KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OleCopy.class, instanceMap); 2054 for(OleCopy oleCopy : oleCopyList){ 2055 if(oleCopy.getPoItemId()!=null){ 2056 purchaseOrderCount++; 2057 } 2058 } 2059 2060 if (purchaseOrderCount == 0) { 2061 oleInstancesDeleteList.add(oleeResourceInstance); 2062 } 2063 else { 2064 oleInstancesAddList.add(oleeResourceInstance); 2065 } 2066 } 2067 } 2068 } 2069 form.setDeletedInstance(oleInstancesDeleteList.size()); 2070 StringBuffer deletdInfo = new StringBuffer(); 2071 for(OLEEResourceInstance oleeResourceInstance : oleInstancesDeleteList){ 2072 deletdInfo.append(oleeResourceInstance.getInstanceTitle()); 2073 deletdInfo.append(","); 2074 KRADServiceLocatorWeb.getLegacyDataAdapter().delete(oleeResourceInstance); 2075 } 2076 if (deletdInfo.length() > 0) { 2077 String info = deletdInfo.toString().substring(0, deletdInfo.lastIndexOf(",")); 2078 form.setDeletedInstanceInfo(info); 2079 } 2080 return getModelAndView(form); 2081 } 2082 2083 @RequestMapping(params = "methodToCall=addSearchCriteria") 2084 public ModelAndView addSearchCriteria(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2085 HttpServletRequest request, HttpServletResponse response) { 2086 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 2087 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList(); 2088 oleSearchConditions.add(new OLESearchCondition()); 2089 for (OLESearchCondition oleSearchCondition : oleSearchConditions) { 2090 if (oleSearchCondition.getOperator() == null) { 2091 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND); 2092 } 2093 } 2094 return super.navigate(oleeResourceRecordForm); 2095 } 2096 2097 @RequestMapping(params = "methodToCall=clearSearch") 2098 public ModelAndView clearSearch(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2099 HttpServletRequest request, HttpServletResponse response) { 2100 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 2101 List<OLESearchCondition> oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList(); 2102 int searchConditionSize = oleSearchConditions.size(); 2103 oleeResourceRecordForm.setOleSearchParams(new OLESearchParams()); 2104 oleSearchConditions = oleeResourceRecordForm.getOleSearchParams().getSearchFieldsList(); 2105 for (int ersCount = 0; ersCount < searchConditionSize; ersCount++) { 2106 oleSearchConditions.add(new OLESearchCondition()); 2107 } 2108 for (OLESearchCondition oleSearchCondition : oleSearchConditions) { 2109 oleSearchCondition.setOperator(OLEConstants.OLEEResourceRecord.AND); 2110 } 2111 oleeResourceRecordForm.setEresourceDocumentList(null); 2112 oleeResourceRecordForm.seteResStatusDate(false); 2113 oleeResourceRecordForm.setBeginDate(null); 2114 oleeResourceRecordForm.setEndDate(null); 2115 oleeResourceRecordForm.setStatus(null); 2116 return super.navigate(oleeResourceRecordForm); 2117 } 2118 2119 @RequestMapping(params = "methodToCall=cancelSearch") 2120 public ModelAndView cancelSearch(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2121 HttpServletRequest request, HttpServletResponse response) { 2122 OLEEResourceRecordForm oleeResourceRecordForm = (OLEEResourceRecordForm) uifForm; 2123 return getModelAndView(oleeResourceRecordForm, "OLEEResourceRecordView-Related-E-ResourceTab"); 2124 } 2125 2126 @MethodAccessible 2127 @RequestMapping(params = "methodToCall=linkEResourceInstance") 2128 public ModelAndView linkEResourceInstance(@ModelAttribute("KualiForm") UifFormBase uifForm, BindingResult result, 2129 HttpServletRequest request, HttpServletResponse response) { 2130 OLEEResourceRecordForm form = (OLEEResourceRecordForm) uifForm; 2131 List<OLEEResourceInstance> oleeResourceInstances = new ArrayList<>(); 2132 2133 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) form.getDocument(); 2134 List<OLEEResourceInstance> oleeResourceInstanceList = oleeResourceRecordDocument.getOleERSInstances(); 2135 2136 HttpSession session = request.getSession(); 2137 session.setAttribute("oleERSIdentifier", oleeResourceRecordDocument.getOleERSIdentifier()); 2138 session.setAttribute("createChileEResource",Boolean.TRUE); 2139 StringBuffer instanceIds = new StringBuffer(); 2140 for(OLEEResourceInstance oleeResourceInstance : oleeResourceInstanceList) { 2141 if(oleeResourceInstance.isSelect()) { 2142 instanceIds.append(oleeResourceInstance.getInstanceId()); 2143 instanceIds.append(","); 2144 } 2145 } 2146 session.setAttribute("oleeResourceInstancesIdentifier", instanceIds.toString()); 2147 form.setOleeResourceInstances(oleeResourceInstances); 2148 2149 String url = ConfigContext.getCurrentContextConfig().getProperty("ole.fs.url.base") + 2150 "/ole-kr-krad/oleERSController?viewId=OLEEResourceRecordView&methodToCall=docHandler&command=initiate&documentClass=org.kuali.ole.select.document.OLEEResourceRecordDocument"; 2151 2152 return performRedirect(form, url); 2153 2154 } 2155 2156 2157 @MethodAccessible 2158 @RequestMapping(params = "methodToCall=packageSearch") 2159 public ModelAndView packageSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2160 HttpServletRequest request, HttpServletResponse response) { 2161 2162 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2163 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2164 List<OLEGOKbPackage> goKbPackages = new ArrayList<>(); 2165 2166 OLEGOKbPackage gokbPackage1 = new OLEGOKbPackage(); 2167 gokbPackage1.setPackageName("Elsevier Scientific Direct Mathematics Backfile"); 2168 gokbPackage1.setGokbStatus("Active"); 2169 gokbPackage1.setOleStatus("owned"); 2170 gokbPackage1.setPrimaryPlatform("Scientific Direct"); 2171 gokbPackage1.setPrimaryPlatformProvider("Elsevier"); 2172 gokbPackage1.setTiips("5"); 2173 gokbPackage1.setDateCreated("1/1/2010"); 2174 gokbPackage1.setDateEntered("2/2/2011"); 2175 goKbPackages.add(gokbPackage1); 2176 gokbPackage1.setMultiplePlatform(false); 2177 2178 List<OLEGOKbPlatform> platformList = new ArrayList<>(); 2179 2180 OLEGOKbPlatform goKbPlatform = new OLEGOKbPlatform(); 2181 2182 platformList.add(goKbPlatform); 2183 2184 List<OLEGOKbTIPP> goKbTIPPs = new ArrayList<>(); 2185 2186 goKbPlatform.setGoKbTIPPList(goKbTIPPs); 2187 2188 oleeResourceRecordDocument.setGoKbPackageList(goKbPackages); 2189 2190 OLEGOKbPackage gokbPackage2 = new OLEGOKbPackage(); 2191 gokbPackage2.setPackageName("Elsevier Scientific Direct Mathematics Backfile"); 2192 gokbPackage2.setGokbStatus("Active"); 2193 gokbPackage2.setOleStatus("owned"); 2194 gokbPackage2.setPrimaryPlatform("Scientific Direct"); 2195 gokbPackage2.setPrimaryPlatformProvider("Elsevier"); 2196 gokbPackage2.setTiips("5"); 2197 gokbPackage2.setDateCreated("1/1/2010"); 2198 gokbPackage2.setDateEntered("2/2/2011"); 2199 goKbPackages.add(gokbPackage2); 2200 gokbPackage2.setMultiplePlatform(true); 2201 2202 OLEGOKbPlatform goKbPlatform2 = new OLEGOKbPlatform(); 2203 2204 platformList.add(goKbPlatform2); 2205 2206 OLEGOKbPlatform goKbPlatform3 = new OLEGOKbPlatform(); 2207 2208 platformList.add(goKbPlatform3); 2209 2210 oleEResourceRecordForm.setShowTippResults(true); 2211 oleeResourceRecordDocument.setGoKbPackageList(goKbPackages); 2212 2213 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP(); 2214 2215 olegoKbTIPP.setTitle("Behaviour and cognitive "); 2216 olegoKbTIPP.setDateCreated("1/1/2009"); 2217 olegoKbTIPP.setDateUpdated("1/1/2013"); 2218 olegoKbTIPP.setIssn("1234-4458"); 2219 olegoKbTIPP.setGokbStatus("Active"); 2220 olegoKbTIPP.setType("Journal"); 2221 olegoKbTIPP.setUrl("example.com"); 2222 2223 goKbTIPPs.add(olegoKbTIPP); 2224 2225 OLEGOKbTIPP olegoKbTIPP1 = new OLEGOKbTIPP(); 2226 2227 olegoKbTIPP1.setTitle("Behaviour and Brain science "); 2228 olegoKbTIPP1.setGokbStatus("excepted"); 2229 goKbTIPPs.add(olegoKbTIPP1); 2230 2231 oleeResourceRecordDocument.setGoKbTIPPList(goKbTIPPs); 2232 return getModelAndView(oleEResourceRecordForm); 2233 } 2234 2235 @MethodAccessible 2236 @RequestMapping(params = "methodToCall=getPlatforms") 2237 public ModelAndView getPlatforms(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2238 HttpServletRequest request, HttpServletResponse response) { 2239 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2240 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2241 2242 List<OLEGOKbPlatform> platformList = new ArrayList<>(); 2243 2244 OLEGOKbPlatform goKbPlatform = new OLEGOKbPlatform(); 2245 goKbPlatform.setPlatformName("Scientific Direct"); 2246 goKbPlatform.setPlatformProvider("Elsevier"); 2247 goKbPlatform.setNoOfTiips("123"); 2248 List<OLEGOKbTIPP> goKbTIPPs = new ArrayList<>(); 2249 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP(); 2250 olegoKbTIPP.setTitle("Behaviour and cognitive "); 2251 olegoKbTIPP.setDateCreated("1/1/2009"); 2252 olegoKbTIPP.setDateUpdated("1/1/2013"); 2253 olegoKbTIPP.setIssn("1234-4458"); 2254 olegoKbTIPP.setGokbStatus("Active"); 2255 olegoKbTIPP.setType("Journal"); 2256 olegoKbTIPP.setUrl("example.com"); 2257 goKbTIPPs.add(olegoKbTIPP); 2258 goKbPlatform.setGoKbTIPPList(goKbTIPPs); 2259 platformList.add(goKbPlatform); 2260 2261 OLEGOKbPlatform goKbPlatform2 = new OLEGOKbPlatform(); 2262 goKbPlatform2.setPlatformName("Scopus"); 2263 goKbPlatform2.setPlatformProvider("Elsevier"); 2264 goKbPlatform2.setNoOfTiips("12"); 2265 List<OLEGOKbTIPP> goKbTIPPs1 = new ArrayList<>(); 2266 OLEGOKbTIPP olegoKbTIPP1 = new OLEGOKbTIPP(); 2267 olegoKbTIPP1.setTitle("Behaviour and Brain science "); 2268 olegoKbTIPP1.setGokbStatus("excepted"); 2269 goKbTIPPs1.add(olegoKbTIPP1); 2270 goKbPlatform2.setGoKbTIPPList(goKbTIPPs1); 2271 platformList.add(goKbPlatform2); 2272 2273 oleeResourceRecordDocument.setGoKbPlatformList(platformList); 2274 2275 return super.navigate(form); 2276 } 2277 2278 @MethodAccessible 2279 @RequestMapping(params = "methodToCall=getTipps") 2280 public ModelAndView getTipps(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2281 HttpServletRequest request, HttpServletResponse response) { 2282 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2283 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2284 2285 /*List<OLEGOKbPlatform> platformList = new ArrayList<>(); 2286 2287 OLEGOKbPlatform goKbPlatform = new OLEGOKbPlatform(); 2288 List<OLEGOKbTIPP> goKbTIPPs = new ArrayList<>(); 2289 List<OLEGOKbTIPP> goKbTIPPs1 = new ArrayList<>(); 2290 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP(); 2291 goKbTIPPs.add(olegoKbTIPP); 2292 goKbPlatform.setGoKbTIPPList(goKbTIPPs); 2293 2294 goKbPlatform.setPlatformName("Scientific Direct"); 2295 goKbPlatform.setPlatformProvider("Elsevier"); 2296 goKbPlatform.setNoOfTiips("123"); 2297 2298 platformList.add(goKbPlatform); 2299 2300 OLEGOKbPlatform goKbPlatform2 = new OLEGOKbPlatform(); 2301 goKbPlatform2.setGoKbTIPPList(goKbTIPPs1); 2302 OLEGOKbTIPP olegoKbTIPP1 = new OLEGOKbTIPP(); 2303 olegoKbTIPP1.setTitle("Behaviour and Brain science "); 2304 olegoKbTIPP1.setGokbStatus("excepted"); 2305 goKbTIPPs1.add(olegoKbTIPP1); 2306 2307 goKbPlatform2.setPlatformName("Scopus"); 2308 goKbPlatform2.setPlatformProvider("Elsevier"); 2309 goKbPlatform2.setNoOfTiips("12"); 2310 platformList.add(goKbPlatform2); 2311 2312 olegoKbTIPP.setTitle("Behaviour and cognitive "); 2313 olegoKbTIPP.setDateCreated("1/1/2009"); 2314 olegoKbTIPP.setDateUpdated("1/1/2013"); 2315 olegoKbTIPP.setIssn("1234-4458"); 2316 olegoKbTIPP.setGokbStatus("Active"); 2317 olegoKbTIPP.setType("Journal"); 2318 olegoKbTIPP.setUrl("example.com");*/ 2319 2320 List<OLEGOKbPlatform> goKbPlatformList = new ArrayList<>(); 2321 for(OLEGOKbPlatform gokbPlatform : oleeResourceRecordDocument.getGoKbPlatformList()) { 2322 if(gokbPlatform.isSelect()) { 2323 goKbPlatformList.add(gokbPlatform); 2324 gokbPlatform.setSelect(Boolean.FALSE); 2325 } 2326 } 2327 2328 oleeResourceRecordDocument.setGoKbPlatformList(goKbPlatformList); 2329 oleEResourceRecordForm.setShowTippsWithMorePlatform(true); 2330 return super.navigate(form); 2331 } 2332 2333 @MethodAccessible 2334 @RequestMapping(params = "methodToCall=platformSearch") 2335 public ModelAndView platformSearch(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2336 HttpServletRequest request, HttpServletResponse response) { 2337 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2338 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2339 List<OLEGOKbTIPP> goKbTIPPs = new ArrayList<>(); 2340 OLEGOKbTIPP olegoKbTIPP = new OLEGOKbTIPP(); 2341 goKbTIPPs.add(olegoKbTIPP); 2342 goKbTIPPs.add(olegoKbTIPP); 2343 goKbTIPPs.add(olegoKbTIPP); 2344 oleeResourceRecordDocument.setGoKbTIPPList(goKbTIPPs); 2345 return super.navigate(form); 2346 } 2347 2348 @MethodAccessible 2349 @RequestMapping(params = "methodToCall=tiipResults") 2350 public ModelAndView tiipResults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2351 HttpServletRequest request, HttpServletResponse response) { 2352 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2353 oleEResourceRecordForm.setShowTiipResults(true); 2354 return super.navigate(form); 2355 } 2356 2357 @MethodAccessible 2358 @RequestMapping(params = "methodToCall=importData") 2359 public ModelAndView importData(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2360 HttpServletRequest request, HttpServletResponse response) { 2361 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2362 return super.navigate(form); 2363 } 2364 2365 @MethodAccessible 2366 @RequestMapping(params = "methodToCall=setDefaults") 2367 public ModelAndView setDefaults(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2368 HttpServletRequest request, HttpServletResponse response) { 2369 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2370 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2371 if(oleeResourceRecordDocument.getTitle() !=null && StringUtils.isNotEmpty(oleeResourceRecordDocument.getTitle())){ 2372 oleEResourceRecordForm.setPackageName(oleeResourceRecordDocument.getTitle()); 2373 } 2374 if(oleeResourceRecordDocument.getPlatformProvider() !=null && StringUtils.isNotEmpty(oleeResourceRecordDocument.getPlatformProvider())){ 2375 oleEResourceRecordForm.setPlatformProvider(oleeResourceRecordDocument.getPlatformProvider()); 2376 } 2377 if(oleeResourceRecordDocument.getIsbn() != null && StringUtils.isNotEmpty(oleeResourceRecordDocument.getIsbn())){ 2378 oleeResourceRecordDocument.getStandardIdentifiers().get(0).setIdentifier(oleeResourceRecordDocument.getIsbn()); 2379 } 2380 return super.navigate(oleEResourceRecordForm); 2381 } 2382 2383 /** 2384 * This method is to get manage GOKb data on E-Resource 2385 * 2386 * @param form 2387 * @param result 2388 * @param request 2389 * @param response 2390 * @return ModelAndView 2391 */ 2392 @MethodAccessible 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 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2398 oleeResourceRecordDocument.setOleGOKbMappingValueList(new ArrayList<OLEGOKbMappingValue>()); 2399 String selectedLine = oleEResourceRecordForm.getActionParamaterValue(UifParameters.SELECTED_LINE_INDEX); 2400 if (StringUtils.isNotBlank(selectedLine)) { 2401 OLEEResourceInstance oleERSInstance = oleeResourceRecordDocument.getOleERSInstances().get(Integer.parseInt(selectedLine)); 2402 Map map = new HashMap(); 2403 map.put("recordId", oleERSInstance.getInstanceId()); 2404 map.put("recordType", "E-Instance"); 2405 List<OLEGOKbMappingValue> goKbMappingValueList = (List<OLEGOKbMappingValue>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEGOKbMappingValue.class, map); 2406 if (goKbMappingValueList != null && goKbMappingValueList.size() > 0) { 2407 for (OLEGOKbMappingValue olegoKbMappingValue : goKbMappingValueList) { 2408 if (olegoKbMappingValue != null && olegoKbMappingValue.getGoKbDataElement() != null && olegoKbMappingValue.getGoKbDataElement().getDataElementName() != null 2409 && olegoKbMappingValue.getGoKbDataElement().getDataElementName().equals("GOKb ID")) { 2410 olegoKbMappingValue.setGokbFlag(true); 2411 } 2412 oleeResourceRecordDocument.getOleGOKbMappingValueList().add(olegoKbMappingValue); 2413 } 2414 } 2415 } 2416 return getModelAndView(oleEResourceRecordForm); 2417 } 2418 2419 /** 2420 * This method is to get manage GOKb data on E-Instance 2421 * 2422 * @param form 2423 * @param result 2424 * @param request 2425 * @param response 2426 * @return ModelAndView 2427 */ 2428 @MethodAccessible 2429 @RequestMapping(params = "methodToCall=getManageGOKbDataOnERes") 2430 public ModelAndView getManageGOKbDataOnERes(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2431 HttpServletRequest request, HttpServletResponse response) { 2432 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2433 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument) oleEResourceRecordForm.getDocument(); 2434 oleeResourceRecordDocument.setOleGOKbMappingValueList(new ArrayList<OLEGOKbMappingValue>()); 2435 Map map = new HashMap(); 2436 map.put("recordId", oleeResourceRecordDocument.getOleERSIdentifier()); 2437 map.put("recordType", "E-Resource"); 2438 List<OLEGOKbMappingValue> goKbMappingValueList = (List<OLEGOKbMappingValue>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEGOKbMappingValue.class, map); 2439 if (goKbMappingValueList != null && goKbMappingValueList.size() > 0) { 2440 for (OLEGOKbMappingValue olegoKbMappingValue : goKbMappingValueList) { 2441 if (olegoKbMappingValue != null && olegoKbMappingValue.getGoKbDataElement() != null && olegoKbMappingValue.getGoKbDataElement().getDataElementName() != null 2442 && olegoKbMappingValue.getGoKbDataElement().getDataElementName().equals("GOKb ID")) { 2443 olegoKbMappingValue.setGokbFlag(true); 2444 } 2445 oleeResourceRecordDocument.getOleGOKbMappingValueList().add(olegoKbMappingValue); 2446 } 2447 } 2448 return getModelAndView(oleEResourceRecordForm); 2449 } 2450 2451 /** 2452 * This method is to get manage GOKb data on E-Instance 2453 * 2454 * @param form 2455 * @param result 2456 * @param request 2457 * @param response 2458 * @return ModelAndView 2459 */ 2460 @MethodAccessible 2461 @RequestMapping(params = "methodToCall=showMultipleContacts") 2462 public ModelAndView showMultipleContacts(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2463 HttpServletRequest request, HttpServletResponse response) { 2464 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2465 String eResourceId = request.getParameter("eResourceId"); 2466 Map map = new HashMap(); 2467 map.put("oleERSIdentifier", eResourceId); 2468 List<OLEEResourceRecordDocument> oleeResourceRecordDocuments = (List<OLEEResourceRecordDocument>) KRADServiceLocatorWeb.getLegacyDataAdapter().findMatching(OLEEResourceRecordDocument.class, map); 2469 OLEEResourceRecordDocument oleeResourceRecordDocument = null; 2470 if(oleeResourceRecordDocuments != null && oleeResourceRecordDocuments.size() > 0) { 2471 oleeResourceRecordDocument = oleeResourceRecordDocuments.get(0); 2472 int index = Integer.parseInt(request.getParameter("index")); 2473 getOleeResourceHelperService().updateVendorInfo(oleeResourceRecordDocument); 2474 2475 if(oleeResourceRecordDocument.getOleERSContacts() != null && oleeResourceRecordDocument.getOleERSContacts().size() >= index) { 2476 OLEEResourceContacts oleeResourceContacts = oleeResourceRecordDocument.getOleERSContacts().get(index); 2477 oleEResourceRecordForm.setVendorNameForContacts(oleeResourceContacts.getOrganization()); 2478 oleEResourceRecordForm.setPhoneNos(oleeResourceContacts.getOlePhoneNumbers()); 2479 } 2480 } 2481 2482 return getModelAndView(oleEResourceRecordForm); 2483 } 2484 2485 @MethodAccessible 2486 @RequestMapping(params = "methodToCall=deleteEresource") 2487 public ModelAndView deleteEresource(@ModelAttribute("KualiForm") UifFormBase form, BindingResult result, 2488 HttpServletRequest request, HttpServletResponse response) { 2489 OLEEResourceRecordForm oleEResourceRecordForm = (OLEEResourceRecordForm) form; 2490 OLEEResourceRecordDocument oleeResourceRecordDocument = (OLEEResourceRecordDocument)oleEResourceRecordForm.getDocument(); 2491 if(oleeResourceRecordDocument.geteRSInstances().size()==0 && oleeResourceRecordDocument.getOleLinkedEresources().size() ==0 && oleeResourceRecordDocument.getOleERSPOItems().size()==0 && oleeResourceRecordDocument.getOleERSLicenseRequests().size()==0){ 2492 KRADServiceLocator.getLegacyDataAdapter().delete(oleeResourceRecordDocument); 2493 } 2494 return getModelAndView(oleEResourceRecordForm); 2495 } 2496 2497}