List of usage examples for org.apache.commons.beanutils PropertyUtils setNestedProperty
public static void setNestedProperty(Object bean, String name, Object value) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException
Sets 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.dataovveride.ProposalDevelopmentDataOverrideController.java
protected void setChangedValue(DevelopmentProposal developmentProposal, ProposalChangedData proposalChangedData) throws Exception { String propertyName = proposalChangedData.getAttributeName(); DataType dataType = DataType// w ww. jav a 2 s .co m .getDataTypeFromClass(DevelopmentProposal.class.getDeclaredField(propertyName).getType()); if (dataType.isTemporal()) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, getDateTimeService().convertToSqlDate(proposalChangedData.getChangedValue())); } else if (dataType.equals(DataType.INTEGER)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, Integer.valueOf(proposalChangedData.getChangedValue())); } else if (dataType.equals(DataType.LONG)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, Long.valueOf(proposalChangedData.getChangedValue())); } else if (dataType.equals(DataType.FLOAT)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, Float.valueOf(proposalChangedData.getChangedValue())); } else if (dataType.equals(DataType.DOUBLE)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, Double.valueOf(proposalChangedData.getChangedValue())); } else if (dataType.equals(DataType.LARGE_INTEGER)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, BigInteger.valueOf(Long.valueOf(proposalChangedData.getChangedValue()))); } else if (dataType.equals(DataType.PRECISE_DECIMAL)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, BigDecimal.valueOf(Long.valueOf(proposalChangedData.getChangedValue()))); } else if (dataType.equals(DataType.STRING)) { PropertyUtils.setNestedProperty(developmentProposal, propertyName, proposalChangedData.getChangedValue()); } else { throw new RuntimeException("Data override does not work for this class"); } }
From source file:org.kuali.rice.kew.impl.document.lookup.DocumentLookupCriteriaTranslatorImpl.java
@Override public DocumentLookupCriteria translate(Map<String, String> fieldValues) { DocumentLookupCriteria.Builder criteria = DocumentLookupCriteria.Builder.create(); for (Map.Entry<String, String> field : fieldValues.entrySet()) { try {/*from ww w . j a va 2 s . c o m*/ if (StringUtils.isNotBlank(field.getValue())) { if (DIRECT_TRANSLATE_FIELD_NAMES_SET.contains(field.getKey())) { PropertyUtils.setNestedProperty(criteria, field.getKey(), field.getValue()); } else if (DATE_RANGE_TRANSLATE_FIELD_NAMES_SET.contains(field.getKey())) { applyDateRangeField(criteria, field.getKey(), field.getValue()); } else if (field.getKey().startsWith(KEWConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX)) { String documentAttributeName = field.getKey() .substring(KEWConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX.length()); applyDocumentAttribute(criteria, documentAttributeName, field.getValue()); } } } catch (Exception e) { throw new IllegalStateException("Failed to set document lookup criteria field: " + field.getKey(), e); } } String routeNodeLookupLogic = fieldValues.get(ROUTE_NODE_LOOKUP_LOGIC); if (StringUtils.isNotBlank(routeNodeLookupLogic)) { criteria.setRouteNodeLookupLogic(RouteNodeLookupLogic.valueOf(routeNodeLookupLogic)); } String documentStatusesValue = fieldValues.get(DOCUMENT_STATUSES); if (StringUtils.isNotBlank(documentStatusesValue)) { String[] documentStatuses = documentStatusesValue.split(","); for (String documentStatus : documentStatuses) { if (documentStatus.startsWith("category:")) { String categoryCode = StringUtils.remove(documentStatus, "category:"); criteria.getDocumentStatusCategories().add(DocumentStatusCategory.fromCode(categoryCode)); } else { criteria.getDocumentStatuses().add(DocumentStatus.fromCode(documentStatus)); } } } return criteria.build(); }
From source file:org.kuali.rice.kew.impl.document.lookup.DocumentLookupCriteriaTranslatorImpl.java
protected void applyDateRangeField(DocumentLookupCriteria.Builder criteria, String fieldName, String fieldValue) throws Exception { DateTime lowerDateTime = DocumentLookupInternalUtils.getLowerDateTimeBound(fieldValue); DateTime upperDateTime = DocumentLookupInternalUtils.getUpperDateTimeBound(fieldValue); if (lowerDateTime != null) { PropertyUtils.setNestedProperty(criteria, fieldName + "From", lowerDateTime); }/*from www . ja v a2 s. c o m*/ if (upperDateTime != null) { PropertyUtils.setNestedProperty(criteria, fieldName + "To", upperDateTime); } }
From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaTranslatorImpl.java
@Override public DocumentSearchCriteria translateFieldsToCriteria(Map<String, String> fieldValues) { DocumentSearchCriteria.Builder criteria = DocumentSearchCriteria.Builder.create(); List<String> documentAttributeFields = new ArrayList<String>(); for (Map.Entry<String, String> field : fieldValues.entrySet()) { try {//from ww w . j a va 2 s .c om if (StringUtils.isNotBlank(field.getValue())) { if (DIRECT_TRANSLATE_FIELD_NAMES_SET.contains(field.getKey())) { PropertyUtils.setNestedProperty(criteria, field.getKey(), field.getValue()); } else if (DATE_RANGE_TRANSLATE_FIELD_NAMES_SET.contains(field.getKey())) { applyDateRangeField(criteria, field.getKey(), field.getValue()); } else if (field.getKey().startsWith(KewApiConstants.DOCUMENT_ATTRIBUTE_FIELD_PREFIX)) { documentAttributeFields.add(field.getKey()); } } } catch (Exception e) { throw new IllegalStateException("Failed to set document search criteria field: " + field.getKey(), e); } } if (!documentAttributeFields.isEmpty()) { translateDocumentAttributeFieldsToCriteria(fieldValues, documentAttributeFields, criteria); } String routeNodeLookupLogic = fieldValues.get(ROUTE_NODE_LOOKUP_LOGIC); if (StringUtils.isNotBlank(routeNodeLookupLogic)) { criteria.setRouteNodeLookupLogic(RouteNodeLookupLogic.valueOf(routeNodeLookupLogic)); } String documentStatusesValue = fieldValues .get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_STATUS_CODE); if (StringUtils.isNotBlank(documentStatusesValue)) { String[] documentStatuses = documentStatusesValue.split(","); for (String documentStatus : documentStatuses) { if (documentStatus.startsWith("category:")) { String categoryCode = StringUtils.remove(documentStatus, "category:"); criteria.getDocumentStatusCategories().add(DocumentStatusCategory.fromCode(categoryCode)); } else { criteria.getDocumentStatuses().add(DocumentStatus.fromCode(documentStatus)); } } } LinkedHashMap<String, List<String>> applicationDocumentStatusGroupings = ApplicationDocumentStatusUtils .getApplicationDocumentStatusCategories(criteria.getDocumentTypeName()); String applicationDocumentStatusesValue = fieldValues .get(KEWPropertyConstants.DOC_SEARCH_RESULT_PROPERTY_NAME_DOC_STATUS); if (StringUtils.isNotBlank(applicationDocumentStatusesValue)) { String[] applicationDocumentStatuses = applicationDocumentStatusesValue.split(","); for (String applicationDocumentStatus : applicationDocumentStatuses) { // KULRICE-7786: support for groups (categories) of application document statuses if (applicationDocumentStatus.startsWith("category:")) { String categoryCode = StringUtils.remove(applicationDocumentStatus, "category:"); if (applicationDocumentStatusGroupings.containsKey(categoryCode)) { criteria.getApplicationDocumentStatuses() .addAll(applicationDocumentStatusGroupings.get(categoryCode)); } } else { criteria.getApplicationDocumentStatuses().add(applicationDocumentStatus); } } } // blank the deprecated field out, it's not needed. criteria.setApplicationDocumentStatus(null); return criteria.build(); }
From source file:org.kuali.rice.kew.impl.document.search.DocumentSearchCriteriaTranslatorImpl.java
protected void applyDateRangeField(DocumentSearchCriteria.Builder criteria, String fieldName, String fieldValue) throws Exception { DateTime lowerDateTime = DocumentSearchInternalUtils.getLowerDateTimeBound(fieldValue); DateTime upperDateTime = DocumentSearchInternalUtils.getUpperDateTimeBound(fieldValue); if (lowerDateTime != null) { PropertyUtils.setNestedProperty(criteria, fieldName + "From", lowerDateTime); }/*from w w w.j a va2 s.co m*/ if (upperDateTime != null) { PropertyUtils.setNestedProperty(criteria, fieldName + "To", upperDateTime); } }
From source file:org.kuali.rice.krad.service.impl.KRADLegacyDataAdapterImpl.java
@Override public void setObjectProperty(Object bo, String propertyName, Class propertyType, Object propertyValue) throws IllegalAccessException, InvocationTargetException, NoSuchMethodException { PropertyUtils.setNestedProperty(bo, propertyName, propertyValue); }
From source file:org.kuali.rice.krad.util.ObjectUtils.java
/** * Sets the property of an object with the given value. Converts using the formatter of the given type if one is * found./* w ww. ja v a 2 s .c om*/ * * @param bo * @param propertyName * @param propertyType * @param propertyValue * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ public static void setObjectProperty(Object bo, String propertyName, Class propertyType, Object propertyValue) throws FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { // reformat propertyValue, if necessary boolean reformat = false; if (propertyType != null) { if (propertyValue != null && propertyType.isAssignableFrom(String.class)) { // always reformat if the destination is a String reformat = true; } else if (propertyValue != null && !propertyType.isAssignableFrom(propertyValue.getClass())) { // otherwise, only reformat if the propertyValue can't be assigned into the property reformat = true; } // attempting to set boolean fields to null throws an exception, set to false instead if (boolean.class.isAssignableFrom(propertyType) && propertyValue == null) { propertyValue = false; } } Formatter formatter = getFormatterWithDataDictionary(bo, propertyName); if (reformat && formatter != null) { LOG.debug("reformatting propertyValue using Formatter " + formatter.getClass().getName()); propertyValue = formatter.convertFromPresentationFormat(propertyValue); } // set property in the object PropertyUtils.setNestedProperty(bo, propertyName, propertyValue); }
From source file:org.kuali.rice.krad.util.ObjectUtils.java
/** * Sets the property of an object with the given value. Converts using the given formatter, if it isn't null. * * @param formatter/* w ww. j a v a 2 s.c o m*/ * @param bo * @param propertyName * @param type * @param propertyValue * @throws NoSuchMethodException * @throws InvocationTargetException * @throws IllegalAccessException */ public static void setObjectProperty(Formatter formatter, Object bo, String propertyName, Class type, Object propertyValue) throws FormatException, IllegalAccessException, InvocationTargetException, NoSuchMethodException { // convert value using formatter for type if (formatter != null) { propertyValue = formatter.convertFromPresentationFormat(propertyValue); } // KULRICE-8412 Changes so that values passed back through via the URL such as // lookups are decrypted where applicable if (propertyValue instanceof String) { String propVal = (String) propertyValue; if (propVal.endsWith(EncryptionService.ENCRYPTION_POST_PREFIX)) { propVal = StringUtils.removeEnd(propVal, EncryptionService.ENCRYPTION_POST_PREFIX); } if (KNSServiceLocator.getBusinessObjectAuthorizationService() .attributeValueNeedsToBeEncryptedOnFormsAndLinks(bo.getClass(), propertyName)) { try { if (CoreApiServiceLocator.getEncryptionService().isEnabled()) { propertyValue = CoreApiServiceLocator.getEncryptionService().decrypt(propVal); } } catch (GeneralSecurityException e) { throw new RuntimeException(e); } } } // set property in the object PropertyUtils.setNestedProperty(bo, propertyName, propertyValue); }
From source file:org.metamorfosis.model.AbstractJMetaClass.java
private void replaceProperty(String propertyName, Object newPropertyValue) { try {//from w ww.j a v a 2 s .c o m removeProperty(propertyName); PropertyUtils.setNestedProperty(this, propertyName, newPropertyValue); } catch (Exception ex) { } }
From source file:org.metamorfosis.model.AbstractJMetaClass.java
@Override public void injectClassProperty(String propName, Object propValue) throws MetaClassException { try {//from www.j av a2s . c om // Pone la propiedad al servicio con get('injectedPropertyName') PropertyUtils.setNestedProperty(this, propName, propValue); } catch (Exception ex) { throw new MetaClassException("Error al inyectar la propiedad '[" + propName + ", " + propValue + "']", ex); } }