@SuppressWarnings("unchecked") @Override public List<String> listPrimaryKeyFieldNames(Class<?> type) { List<String> keys = new ArrayList<String>(); if (type == null) { return keys; } if (isPersistable(type)) { keys = persistenceStructureService.listPrimaryKeyFieldNames(type); } else { ModuleService responsibleModuleService = kualiModuleService.getResponsibleModuleService(type); if (responsibleModuleService != null && responsibleModuleService.isExternalizable(type)) { keys = responsibleModuleService.listPrimaryKeyFieldNames(type); } else { // check the Data Dictionary for PK's of non PBO/EBO DataObjectEntry dataObjectEntry = dataDictionaryService.getDataDictionary().getDataObjectEntry(type.getName()); if (dataObjectEntry != null) { List<String> pks = dataObjectEntry.getPrimaryKeys(); if (pks != null) { keys = pks; } } else { LOG.warn( "Unable to retrieve data object entry for non-persistable KNS-managed class: " + type.getName()); } } } return keys; }
/** * Invoked to request an inquiry view for a data object class * * <p>Checks if the data object is externalizable and we need to redirect to the appropriate * inquiry URL, else continues with the inquiry view display * * <p>Data object class name and values for a primary or alternate key set must be sent in the * request * * <p>Invokes the inquirable to perform the query for the data object record, if not found an * exception will be thrown. If found the object is set on the form and then the view is rendered */ @RequestMapping(params = "methodToCall=start") @Override public ModelAndView start( @ModelAttribute("KualiForm") UifFormBase form, BindingResult result, HttpServletRequest request, HttpServletResponse response) { InquiryForm inquiryForm = (InquiryForm) form; // if request is not a redirect, determine if we need to redirect for an externalizable object // inquiry if (!inquiryForm.isRedirectedInquiry()) { Class inquiryObjectClass = null; try { inquiryObjectClass = Class.forName(inquiryForm.getDataObjectClassName()); } catch (ClassNotFoundException e) { throw new RiceRuntimeException( "Unable to get class for name: " + inquiryForm.getDataObjectClassName()); } ModuleService responsibleModuleService = KRADServiceLocatorWeb.getKualiModuleService() .getResponsibleModuleService(inquiryObjectClass); if (responsibleModuleService != null && responsibleModuleService.isExternalizable(inquiryObjectClass)) { String inquiryUrl = responsibleModuleService.getExternalizableDataObjectInquiryUrl( inquiryObjectClass, KRADUtils.convertRequestMapToProperties(request.getParameterMap())); Properties redirectUrlProps = new Properties(); redirectUrlProps.put(UifParameters.REDIRECTED_INQUIRY, "true"); // clear current form from session GlobalVariables.getUifFormManager().removeSessionForm(form); return performRedirect(form, inquiryUrl, redirectUrlProps); } } // initialize data object class in inquirable try { inquiryForm .getInquirable() .setDataObjectClass(Class.forName(inquiryForm.getDataObjectClassName())); } catch (ClassNotFoundException e) { LOG.error( "Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e); throw new RuntimeException( "Unable to get new instance for object class: " + inquiryForm.getDataObjectClassName(), e); } // invoke inquirable to retrieve inquiry data object Object dataObject = inquiryForm .getInquirable() .retrieveDataObject(KRADUtils.translateRequestParameterMap(request.getParameterMap())); inquiryForm.setDataObject(dataObject); return super.start(form, result, request, response); }
public Object retrieveDataObject(Map<String, String> parameters) { if (dataObjectClass == null) { LOG.error("Data object class must be set in inquirable before retrieving the object"); throw new RuntimeException( "Data object class must be set in inquirable before retrieving the object"); } // build list of key values from the map parameters List<String> pkPropertyNames = getDataObjectMetaDataService().listPrimaryKeyFieldNames(dataObjectClass); // some classes might have alternate keys defined for retrieving List<List<String>> alternateKeyNames = this.getAlternateKeysForClass(dataObjectClass); // add pk set as beginning so it will be checked first for match alternateKeyNames.add(0, pkPropertyNames); List<String> dataObjectKeySet = retrieveKeySetFromMap(alternateKeyNames, parameters); if ((dataObjectKeySet == null) || dataObjectKeySet.isEmpty()) { LOG.warn("Matching key set not found in request for class: " + getDataObjectClass()); return null; } String patronHome = parameters.get("flow"); // found key set, now build map of key values pairs we can use to retrieve the object Map<String, Object> keyPropertyValues = new HashMap<String, Object>(); for (String keyPropertyName : dataObjectKeySet) { String keyPropertyValue = parameters.get(keyPropertyName); // uppercase value if needed Boolean forceUppercase = Boolean.FALSE; try { forceUppercase = getDataDictionaryService().getAttributeForceUppercase(dataObjectClass, keyPropertyName); } catch (UnknownBusinessClassAttributeException ex) { // swallowing exception because this check for ForceUppercase would // require a DD entry for the attribute, and we will just set force uppercase to false LOG.warn( "Data object class " + dataObjectClass + " property " + keyPropertyName + " should probably have a DD definition.", ex); } if (forceUppercase.booleanValue() && (keyPropertyValue != null)) { keyPropertyValue = keyPropertyValue.toUpperCase(); } // check security on key field if (getDataObjectAuthorizationService() .attributeValueNeedsToBeEncryptedOnFormsAndLinks(dataObjectClass, keyPropertyName)) { try { keyPropertyValue = getEncryptionService().decrypt(keyPropertyValue); } catch (GeneralSecurityException e) { LOG.error( "Data object class " + dataObjectClass + " property " + keyPropertyName + " should have been encrypted, but there was a problem decrypting it.", e); throw new RuntimeException( "Data object class " + dataObjectClass + " property " + keyPropertyName + " should have been encrypted, but there was a problem decrypting it.", e); } } keyPropertyValues.put(keyPropertyName, keyPropertyValue); } // now retrieve the object based on the key set Object dataObject = null; ModuleService moduleService = KRADServiceLocatorWeb.getKualiModuleService() .getResponsibleModuleService(getDataObjectClass()); if (moduleService != null && moduleService.isExternalizable(getDataObjectClass())) { dataObject = moduleService.getExternalizableBusinessObject( getDataObjectClass().asSubclass(ExternalizableBusinessObject.class), keyPropertyValues); } else if (BusinessObject.class.isAssignableFrom(getDataObjectClass())) { dataObject = getBusinessObjectService() .findByPrimaryKey( getDataObjectClass().asSubclass(BusinessObject.class), keyPropertyValues); } // OleEntityAddressBo entityAddressBo = new OleEntityAddressBo(); EntityAddressBo entityAddress = new EntityAddressBo(); List<OleEntityAddressBo> oleEntityAddressList = new ArrayList<OleEntityAddressBo>(); List<OleEntityPhoneBo> oleEntityPhoneBoList = new ArrayList<>(); List<OleEntityEmailBo> oleEntityEmailBoList = new ArrayList<>(); OlePatronDocument patronDocument = (OlePatronDocument) dataObject; if (patronDocument != null) { EntityBo kimEnity = patronDocument.getEntity(); if (kimEnity.getNames().size() > 0) { patronDocument.setName(kimEnity.getNames().get(0)); } if (kimEnity.getEntityTypeContactInfos().size() > 0) { List<EntityAddressBo> entityAddressList = kimEnity.getEntityTypeContactInfos().get(0).getAddresses(); for (EntityAddressBo entityAdd : entityAddressList) { OleEntityAddressBo entityAddressBo = new OleEntityAddressBo(); entityAddressBo.setEntityAddressBo(entityAdd); Map addMap = new HashMap(); // addMap.put(OLEConstants.OlePatron.OLE_ADDRESS_ID, entityAdd.getId()); addMap.put(OLEConstants.OlePatron.ENTITY_BO_ID, entityAdd.getId()); addMap.put(OLEConstants.OlePatron.PATRON_ID, patronDocument.getId()); List<OleAddressBo> oleAddressBos = (List<OleAddressBo>) getBusinessObjectService().findMatching(OleAddressBo.class, addMap); if (CollectionUtils.isNotEmpty(oleAddressBos)) { entityAddressBo.setOleAddressBo(oleAddressBos.get(0)); } oleEntityAddressList.add(entityAddressBo); } patronDocument.setOleEntityAddressBo(oleEntityAddressList); List<EntityPhoneBo> entityPhoneBoList = kimEnity.getEntityTypeContactInfos().get(0).getPhoneNumbers(); for (EntityPhoneBo entityPhoneBo : entityPhoneBoList) { OleEntityPhoneBo oleEntityPhoneBo = new OleEntityPhoneBo(); oleEntityPhoneBo.setEntityPhoneBo(entityPhoneBo); Map map = new HashMap(); map.put(OLEConstants.OlePatron.ENTITY_BO_ID, entityPhoneBo.getId()); map.put(OLEConstants.OlePatron.PATRON_ID, patronDocument.getId()); List<OlePhoneBo> olePhoneBos = (List<OlePhoneBo>) getBusinessObjectService().findMatching(OlePhoneBo.class, map); if (CollectionUtils.isNotEmpty(olePhoneBos)) { oleEntityPhoneBo.setOlePhoneBo(olePhoneBos.get(0)); } oleEntityPhoneBoList.add(oleEntityPhoneBo); } patronDocument.setOleEntityPhoneBo(oleEntityPhoneBoList); List<EntityEmailBo> entityEmailBoList = kimEnity.getEntityTypeContactInfos().get(0).getEmailAddresses(); for (EntityEmailBo entityEmailBo : entityEmailBoList) { OleEntityEmailBo oleEntityEmailBo = new OleEntityEmailBo(); oleEntityEmailBo.setEntityEmailBo(entityEmailBo); Map map = new HashMap(); map.put(OLEConstants.OlePatron.ENTITY_BO_ID, entityEmailBo.getId()); map.put(OLEConstants.OlePatron.PATRON_ID, patronDocument.getId()); List<OleEmailBo> oleEmailBos = (List<OleEmailBo>) getBusinessObjectService().findMatching(OleEmailBo.class, map); if (CollectionUtils.isNotEmpty(oleEmailBos)) { oleEntityEmailBo.setOleEmailBo(oleEmailBos.get(0)); } oleEntityEmailBoList.add(oleEntityEmailBo); } patronDocument.setOleEntityEmailBo(oleEntityEmailBoList); patronDocument.setPatronAffiliations( getPatronAffiliationFromEntity( kimEnity.getAffiliations(), kimEnity.getEmploymentInformation())); if (patronHome != null) { if (patronHome.equalsIgnoreCase("start")) patronDocument.setPatronHomePage(false); else patronDocument.setPatronHomePage(true); } } if (null != patronDocument.getName()) { String createBillUrl = OLEConstants.OlePatron.PATRON_CREATE_BILL_URL + patronDocument.getOlePatronId() + "&firstName=" + patronDocument.getName().getFirstName() + "&lastName=" + patronDocument.getName().getLastName(); patronDocument.setCreateBillUrl(createBillUrl); } if (CollectionUtils.isNotEmpty(patronDocument.getPatronBillPayments())) { patronDocument.setPatronBillFileName(OLEConstants.OlePatron.PATRON_VIEW_BILLS); patronDocument.setViewBillUrl( OLEConstants.OlePatron.PATRON_VIEW_BILL_URL + patronDocument.getOlePatronId()); } patronDocument.setShowBillUrlsFlag(true); } if (CollectionUtils.isNotEmpty(patronDocument.getOleProxyPatronDocuments())) { OlePatronDocument olePatronDocument; for (OleProxyPatronDocument oleProxyPatronDocument : patronDocument.getOleProxyPatronDocuments()) { olePatronDocument = oleProxyPatronDocument.getOlePatronDocument(); oleProxyPatronDocument.setProxyForPatronFirstName( olePatronDocument.getEntity().getNames().get(0).getFirstName()); oleProxyPatronDocument.setProxyForPatronLastName( olePatronDocument.getEntity().getNames().get(0).getLastName()); } } if (CollectionUtils.isNotEmpty(patronDocument.getOleProxyPatronDocumentList())) { OlePatronDocument olePatronDocument; for (OleProxyPatronDocument oleProxyPatronDocument : patronDocument.getOleProxyPatronDocumentList()) { olePatronDocument = oleProxyPatronDocument.getOlePatronDocument(); oleProxyPatronDocument.setProxyForPatronFirstName( olePatronDocument.getEntity().getNames().get(0).getFirstName()); oleProxyPatronDocument.setProxyForPatronLastName( olePatronDocument.getEntity().getNames().get(0).getLastName()); } } if (patronDocument.getOleLoanDocuments() != null) { patronDocument.setLoanCount(patronDocument.getOleLoanDocuments().size()); } if (patronDocument.getOleTemporaryCirculationHistoryRecords() != null) { patronDocument.setTempCirculationHistoryCount( patronDocument.getOleTemporaryCirculationHistoryRecords().size()); } if (patronDocument.getOleDeliverRequestBos() != null) { patronDocument.setRequestedItemRecordsCount(patronDocument.getOleDeliverRequestBos().size()); } return patronDocument; }