List of usage examples for org.apache.commons.beanutils PropertyUtils getNestedProperty
public static Object getNestedProperty(Object bean, String name) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Return the value of the (possibly nested) property of the specified name, for the specified bean, with no type conversions.
For more details see PropertyUtilsBean
.
From source file:org.kuali.coeus.propdev.impl.budget.core.ProposalBudgetViewHelperServiceImpl.java
@Override public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, String collectionPath) { if (addLine instanceof BudgetProjectIncome) { BudgetProjectIncome budgetProjectIncome = (BudgetProjectIncome) addLine; if (budgetProjectIncome != null) { budgetProjectIncome.setBudgetId(((ProposalBudgetForm) model).getBudget().getBudgetId()); budgetProjectIncome.setDocumentComponentId(((ProposalBudgetForm) model).getBudget() .getNextValue(budgetProjectIncome.getDocumentComponentIdKey())); budgetProjectIncome.setBudgetPeriod( ((ProposalBudgetForm) model).getBudget().getBudgetPeriod(budgetProjectIncome)); }/*from w w w .j a v a 2 s .c o m*/ } if (addLine instanceof BudgetUnrecoveredFandA) { BudgetUnrecoveredFandA budgetUnrecoveredFandA = (BudgetUnrecoveredFandA) addLine; if (budgetUnrecoveredFandA != null) { budgetUnrecoveredFandA.setBudget(((ProposalBudgetForm) model).getBudget()); budgetUnrecoveredFandA.setDocumentComponentId(((ProposalBudgetForm) model).getBudget() .getNextValue(budgetUnrecoveredFandA.getDocumentComponentIdKey())); } } if (addLine instanceof BudgetCostShare) { BudgetCostShare budgetCostShare = (BudgetCostShare) addLine; if (budgetCostShare != null) { budgetCostShare.setBudget(((ProposalBudgetForm) model).getBudget()); budgetCostShare.setDocumentComponentId(((ProposalBudgetForm) model).getBudget() .getNextValue(budgetCostShare.getDocumentComponentIdKey())); } } if (addLine instanceof BudgetModularIdc) { BudgetModularIdc budgetModularIdc = (BudgetModularIdc) addLine; try { budgetModularIdc.setBudgetModular((BudgetModular) PropertyUtils.getNestedProperty(model, StringUtils.replace(collectionPath, ".budgetModularIdcs", ""))); } catch (Exception e) { throw new RuntimeException("proposal budget modular cannot be retrieved from propdev budget", e); } budgetModularIdc.setBudgetPeriod(budgetModularIdc.getBudgetModular().getBudgetPeriod()); budgetModularIdc.setBudgetId(budgetModularIdc.getBudgetModular().getBudgetId()); budgetModularIdc.setBudgetPeriodId(budgetModularIdc.getBudgetModular().getBudgetPeriodId()); budgetModularIdc.setRateNumber(((ProposalBudgetForm) model).getBudget().getNextValue("rateNumber")); } }
From source file:org.kuali.coeus.propdev.impl.core.ProposalDevelopmentViewHelperServiceImpl.java
@Override public void processBeforeAddLine(ViewModel model, Object addLine, String collectionId, final String collectionPath) { ProposalDevelopmentDocumentForm form = (ProposalDevelopmentDocumentForm) model; ProposalDevelopmentDocument document = form.getProposalDevelopmentDocument(); DevelopmentProposal proposal = document.getDevelopmentProposal(); if (addLine instanceof Narrative) { Narrative narrative = (Narrative) addLine; getNarrativeService().prepareNarrative(document, narrative); if (StringUtils.equals(collectionPath, "document.developmentProposal.instituteAttachments")) { narrative.setModuleStatusCode(Constants.NARRATIVE_MODULE_STATUS_COMPLETE); }//w ww.j a v a 2 s . c om updateAttachmentInformation(narrative.getNarrativeAttachment()); } else if (addLine instanceof ProposalPersonBiography) { ProposalPersonBiography biography = (ProposalPersonBiography) addLine; biography.setDevelopmentProposal(document.getDevelopmentProposal()); biography.setBiographyNumber(document.getDocumentNextValue(Constants.PROP_PERSON_BIO_NUMBER)); updateAttachmentInformation(biography.getPersonnelAttachment()); } else if (addLine instanceof ProposalPersonDegree) { ((ProposalPersonDegree) addLine).setDegreeSequenceNumber( document.getDocumentNextValue(Constants.PROPOSAL_PERSON_DEGREE_SEQUENCE_NUMBER)); try { ((ProposalPersonDegree) addLine).setProposalPerson( (ProposalPerson) PropertyUtils.getNestedProperty(form.getDevelopmentProposal(), StringUtils.replace(collectionPath, ".proposalPersonDegrees", ""))); } catch (Exception e) { throw new RuntimeException("proposal person cannot be retrieved from development proposal", e); } } else if (addLine instanceof ProposalPersonUnit) { try { ProposalPersonUnit unit = (ProposalPersonUnit) addLine; ProposalPerson proposalPerson = (ProposalPerson) PropertyUtils.getNestedProperty( form.getDevelopmentProposal(), StringUtils.replace(collectionPath, ".units", "")); unit.setProposalPerson(proposalPerson); unit.getCreditSplits().addAll(getKeyPersonnelService().createCreditSplits(unit)); } catch (Exception e) { throw new RuntimeException("proposal person cannot be retrieved from development proposal", e); } } else if (addLine instanceof ProposalAbstract) { ProposalAbstract proposalAbstract = (ProposalAbstract) addLine; proposalAbstract.setProposalNumber(proposal.getProposalNumber()); proposalAbstract.refreshReferenceObject("abstractType"); proposalAbstract.setUpdateDisplayFields(); } else if (addLine instanceof ProposalSpecialReview) { ProposalSpecialReview proposalSpecialReview = (ProposalSpecialReview) addLine; proposalSpecialReview.setDevelopmentProposal(document.getDevelopmentProposal()); } else if (addLine instanceof ProposalSite) { ProposalSite newProposalSite = (ProposalSite) addLine; if (newProposalSite.getOrganizationId() != null) { ((ProposalSite) addLine).setLocationTypeCode(ProposalSite.PROPOSAL_SITE_OTHER_ORGANIZATION); } else if (newProposalSite.getRolodexId() != null) { ((ProposalSite) addLine).setLocationTypeCode(ProposalSite.PROPOSAL_SITE_PERFORMANCE_SITE); } ((ProposalSite) addLine).setDevelopmentProposal(document.getDevelopmentProposal()); } else if (addLine instanceof CongressionalDistrict) { CongressionalDistrict congressionalDistrict = (CongressionalDistrict) addLine; ((CongressionalDistrict) addLine).setCongressionalDistrict(congressionalDistrict.getNewState(), congressionalDistrict.getNewDistrictNumber()); } else if (addLine instanceof Note) { Note note = (Note) addLine; note.setRemoteObjectIdentifier(document.getNoteTarget().getObjectId()); note.setAuthorUniversalIdentifier(getGlobalVariableService().getUserSession().getPrincipalId()); note.setNotePostedTimestampToCurrent(); note.setNoteTypeCode("BO"); } if (addLine instanceof KcPersistableBusinessObjectBase) { ((KcPersistableBusinessObjectBase) addLine) .setUpdateTimestamp(getDateTimeService().getCurrentTimestamp()); ((KcPersistableBusinessObjectBase) addLine) .setUpdateUser(getGlobalVariableService().getUserSession().getPrincipalName()); } }
From source file:org.kuali.coeus.propdev.impl.dataovveride.ProposalDevelopmentDataOverrideController.java
protected void getDisplayReferenceValue(ProposalChangedData proposalChangedData, DevelopmentProposal proposal) { String refName = ""; DataObjectRelationship relationship = getDataObjectService().getMetadataRepository() .getMetadata(DevelopmentProposal.class) .getRelationshipByLastAttributeInRelationship(proposalChangedData.getAttributeName()); if (relationship != null) { refName = relationship.getName(); }// w w w .j a va 2s. c o m if (StringUtils.isNotEmpty(refName)) { getDataObjectService().wrap(proposal).fetchRelationship(refName); try { Object refObject = PropertyUtils.getNestedProperty(proposal, refName); String refDescription = (String) PropertyUtils.getNestedProperty(refObject, "description"); proposalChangedData.setDisplayValue(refDescription); } catch (Exception e) { LOG.warn("no description field found on ref object", e); } } }
From source file:org.kuali.coeus.propdev.impl.dataovveride.ProposalDevelopmentDataOverrideController.java
protected Object getPropertyValue(DevelopmentProposal developmentProposal, String propertyName) { try {/*from w w w . j a v a 2 s.c om*/ return PropertyUtils.getNestedProperty(developmentProposal, propertyName); } catch (Exception e) { throw new RiceRuntimeException( "propertyName " + propertyName + "can not be found on development proposal"); } }
From source file:org.kuali.coeus.propdev.impl.editable.ProposalDevelopmentDataOverrideRule.java
/** * /* w w w . j a v a2 s .c o m*/ * This method is to validate the format/length of custom attribute * @param proposalOverriddenData * @param dataDictionaryService * @return boolean */ private boolean validateAttributeFormat(ProposalChangedData proposalOverriddenData, DevelopmentProposal developmentProposal, DataDictionaryService dataDictionaryService) { ProposalDevelopmentService proposalDevelopmentService = KcServiceLocator .getService(ProposalDevelopmentService.class); DateTimeService dateTimeService = CoreApiServiceLocator.getDateTimeService(); String overriddenValue = proposalOverriddenData.getChangedValue(); String changedValueLabel = dataDictionaryService.getAttributeLabel(ProposalChangedData.class, "changedValue"); String dataType = null; Integer maxLength = -1; if (proposalOverriddenData.getEditableColumn() != null) { dataType = proposalOverriddenData.getEditableColumn().getDataType(); maxLength = proposalOverriddenData.getEditableColumn().getDataLength(); } ValidationPattern validationPattern = null; if (DATE.equalsIgnoreCase(dataType)) { try { dateTimeService.convertToDate(overriddenValue); } catch (ParseException e) { GlobalVariables.getMessageMap().putError(Constants.PROPOSALDATA_CHANGED_VAL_KEY, RiceKeyConstants.ERROR_INVALID_FORMAT, new String[] { changedValueLabel, overriddenValue }); return false; } } else { String validationClassName = validationClasses.get(dataType); if (StringUtils.isNotEmpty(validationClassName)) { try { validationPattern = (ValidationPattern) Class.forName(validationClasses.get(dataType)) .newInstance(); if (dataType.equalsIgnoreCase("STRING")) { ((org.kuali.rice.kns.datadictionary.validation.charlevel.AnyCharacterValidationPattern) validationPattern) .setAllowWhitespace(true); } } catch (Exception e) { throw new RuntimeException( "Error in instantiating a ValidationPatternClass for Proposal Data Overriding", e); } } else { //throw error } if (validationPattern != null) { Pattern validationExpression = validationPattern.getRegexPattern(); if (validationExpression != null && !validationExpression.pattern().equals(".*")) { if (!validationExpression.matcher(overriddenValue).matches()) { GlobalVariables.getMessageMap().putError(Constants.PROPOSALDATA_CHANGED_VAL_KEY, RiceKeyConstants.ERROR_INVALID_FORMAT, new String[] { changedValueLabel, overriddenValue }); return false; } } } } if ((maxLength != null) && (maxLength.intValue() < overriddenValue.length())) { GlobalVariables.getMessageMap().putError(Constants.PROPOSALDATA_CHANGED_VAL_KEY, RiceKeyConstants.ERROR_MAX_LENGTH, new String[] { changedValueLabel, maxLength.toString() }); return false; } try { Object currentValue = PropertyUtils.getNestedProperty(developmentProposal, proposalOverriddenData.getAttributeName()); String currentValueStr = (currentValue != null) ? currentValue.toString() : ""; if (DATE.equalsIgnoreCase(proposalOverriddenData.getEditableColumn().getDataType()) && currentValue != null) { currentValueStr = dateTimeService.toString((Date) currentValue, "MM/dd/yyyy"); } if (StringUtils.isNotEmpty(currentValueStr) && currentValueStr.equalsIgnoreCase(overriddenValue)) { GlobalVariables.getMessageMap().putError(Constants.PROPOSALDATA_CHANGED_VAL_KEY, KeyConstants.PROPOSAL_DATA_OVERRIDE_SAME_VALUE, new String[] { proposalOverriddenData.getEditableColumn().getColumnLabel(), (proposalOverriddenData.getDisplayValue() != null) ? proposalOverriddenData.getDisplayValue() : overriddenValue }); return false; } } catch (Exception e) { throw new RuntimeException( "Error retrieving " + proposalOverriddenData.getAttributeName() + " from the proposal", e); } return true; }
From source file:org.kuali.coeus.propdev.impl.person.creditsplit.CreditSplitCustomColumnsCollection.java
@Override public void performInitialization(Object model) { ProposalDevelopmentDocumentForm pdForm = (ProposalDevelopmentDocumentForm) model; ((ProposalDevelopmentViewHelperServiceImpl) pdForm.getViewHelperService()) .setInvestigatorCreditTypes(pdForm); if (CollectionUtils.isNotEmpty( ((ProposalDevelopmentDocumentForm) model).getDevelopmentProposal().getInvestigators())) { List<Object> columnCollection = ObjectPropertyUtils.getPropertyValue(model, getColumnBindingInfo().getBindingPath()); List<Component> columns = new ArrayList<Component>(); for (Component component : this.getItems()) { if (component.isRender() || component.isHidden()) { columns.add(component);//w w w. j a va 2 s . com } } int index = 0; for (Object column : columnCollection) { DataFieldBase columnField = ComponentUtils.copy(columnFieldPrototype); String columnLabel = StringUtils.isEmpty(columnLabelPropertyName) ? "description" : columnLabelPropertyName; try { columnField.getFieldLabel() .setLabelText(PropertyUtils.getNestedProperty(column, columnLabel).toString()); columnField.getBindingInfo().setBindingName("creditSplits[" + index + "].credit"); columnField.setPropertyName("creditSplits.credit"); columnField.setOrder(100 + index); columns.add(columnField); } catch (Exception e) { LOG.error("Could not retrieve column label from column collection item", e); } index++; } this.setItems(columns); } super.performInitialization(model); }
From source file:org.kuali.coeus.sys.framework.keyvalue.ConditionValuesFinder.java
/** * Gets a String property on the passed in Object. The property can be a nested property. * If the property is not a String then property.toString() is returned. * @param o the Object// w ww.j a v a 2 s.c om * @param name the property name * @return the property value. * @throws PropertyException if this methods fails to retrieve the property. */ private String getPropery(T o, String name) { assert o != null : "o is null"; assert !StringUtils.isBlank(name) : "name is blank"; try { final Object property = PropertyUtils.getNestedProperty(o, name); if (property == null) { throw new PropertyException("property " + name + " is null."); } return property.toString(); } catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { throw new PropertyException(e); } }
From source file:org.kuali.kra.coi.disclosure.CoiDisclosureAction.java
/** * //from w w w . jav a 2s.c o m * This method is for the 'update' button to update questionnaire answer to new version * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward updateAnswerToNewVersion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String methodToCallStart = "methodToCall.updateAnswerToNewVersion."; String methodToCallEnd = ".line"; String methodToCall = ((String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE)); String questionnaireHelperPath = methodToCall.substring(methodToCallStart.length(), methodToCall.indexOf(methodToCallEnd)); QuestionnaireHelperBase helper = (QuestionnaireHelperBase) PropertyUtils.getNestedProperty(form, questionnaireHelperPath); helper.updateQuestionnaireAnswer(getLineToDelete(request)); return mapping.findForward(Constants.MAPPING_BASIC); }
From source file:org.kuali.kra.lookup.keyvalue.ConditionValuesFinder.java
/** * Gets a String property on the passed in Object. The property can be a nested property. * If the property is not a String then property.toString() is returned. * @param o the Object/* ww w . jav a 2s .c o m*/ * @param name the property name * @return the property value. * @throws PropertyException if this methods fails to retrieve the property. */ private String getPropery(T o, String name) { assert o != null : "o is null"; assert !StringUtils.isBlank(name) : "name is blank"; try { final Object property = PropertyUtils.getNestedProperty(o, name); if (property == null) { throw new PropertyException("property " + name + " is null."); } return property.toString(); } catch (IllegalAccessException e) { throw new PropertyException(e); } catch (InvocationTargetException e) { throw new PropertyException(e); } catch (NoSuchMethodException e) { throw new PropertyException(e); } }
From source file:org.kuali.kra.protocol.ProtocolActionBase.java
/** * /*from w w w .j a v a 2 s . c o m*/ * This method is for the 'update' button to update questionnaire answer to new version * * @param mapping * @param form * @param request * @param response * @return * @throws Exception */ public ActionForward updateAnswerToNewVersion(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { String methodToCallStart = "methodToCall.updateAnswerToNewVersion."; String methodToCallEnd = ".line"; String methodToCall = ((String) request.getAttribute(KRADConstants.METHOD_TO_CALL_ATTRIBUTE)); String questionnaireHelperPath = methodToCall.substring(methodToCallStart.length(), methodToCall.indexOf(methodToCallEnd)); QuestionnaireHelperBase helper = (QuestionnaireHelperBase) PropertyUtils.getNestedProperty(form, questionnaireHelperPath); helper.updateQuestionnaireAnswer(getLineToDelete(request)); getBusinessObjectService().save(helper.getAnswerHeaders()); return mapping.findForward(Constants.MAPPING_BASIC); }