org.springframework.beans.PropertyAccessorUtils Java Examples

The following examples show how to use org.springframework.beans.PropertyAccessorUtils. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PersonServiceImpl.java    From rice with Educational Community License v2.0 7 votes vote down vote up
private boolean isPersonProperty(Object bo, String propertyName) {
    try {
    	if (PropertyAccessorUtils.isNestedOrIndexedProperty( propertyName ) // is a nested property
        		&& !StringUtils.contains(propertyName, "add.") ) {// exclude add line properties (due to path parsing problems in PropertyUtils.getPropertyType)
            int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(propertyName);
            String propertyTypeName = lastIndex != -1 ? StringUtils.substring(propertyName, 0, lastIndex) : StringUtils.EMPTY;
    		Class<?> type = PropertyUtils.getPropertyType(bo, propertyTypeName);
    		// property type indicates a Person object
    		if ( type != null ) {
    			return Person.class.isAssignableFrom(type);
    		}
    		LOG.warn( "Unable to determine type of nested property: " + bo.getClass().getName() + " / " + propertyName );
    	}
    } catch (Exception ex) {
    	if ( LOG.isDebugEnabled() ) {
    		LOG.debug("Unable to determine if property on " + bo.getClass().getName() + " to a person object: " + propertyName, ex );
    	}
    }
    return false;
}
 
Example #2
Source File: KNSLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Override
public Map<String, String> getInquiryParameters(Object dataObject, List<String> keys, String propertyName) {
    Map<String, String> inquiryParameters = new HashMap<String, String>();
    Class<?> objectClass = ObjectUtils.materializeClassForProxiedObject(dataObject);
    org.kuali.rice.krad.bo.DataObjectRelationship relationship =
            dataObjectMetaDataService.getDataObjectRelationship(dataObject, objectClass, propertyName, "", true,
                    false, true);
    for (String keyName : keys) {
        String keyConversion = keyName;
        if (relationship != null) {
            keyConversion = relationship.getParentAttributeForChildAttribute(keyName);
        } else if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
            String nestedAttributePrefix = KRADUtils.getNestedAttributePrefix(propertyName);
            keyConversion = nestedAttributePrefix + "." + keyName;
        }
        inquiryParameters.put(keyConversion, keyName);
    }
    return inquiryParameters;
}
 
Example #3
Source File: ViewHelperServiceImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Set the parent for bi-directional relationships when adding a line to a collection.
 *
 * @param model the view data
 * @param collectionPath the path to the collection being linked
 * @param addedIndex the index of the added line
 * @return whether the linked line needs further processing
 */
protected boolean linkAddedLine(Object model, String collectionPath, int addedIndex) {
    int lastSepIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(collectionPath);
    if (lastSepIndex != -1) {
        String collectionParentPath = collectionPath.substring(0, lastSepIndex);
        Object parent = ObjectPropertyUtils.getPropertyValue(model, collectionParentPath);
        if (parent != null && getDataObjectService().supports(parent.getClass())) {
            DataObjectWrapper<?> wrappedParent = getDataObjectService().wrap(parent);
            String collectionName = collectionPath.substring(lastSepIndex + 1);
            wrappedParent.linkChanges(Sets.newHashSet(collectionName + "[" + addedIndex + "]"));
        }

        // check if its edit line in dialog line action, and if it is we want to set the collection as
        // the dialog's parent and do not want further processing of the dialog object
        if (collectionParentPath.equalsIgnoreCase(UifPropertyPaths.DIALOG_DATA_OBJECT)) {
            ((UifFormBase) model).setDialogDataObject(parent);
            return false;
        }
    }
    return true;
}
 
Example #4
Source File: UifViewBeanWrapper.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Overridden to copy property editor registration to the new bean wrapper.
 *
 * <p>This is necessary because spring only copies over the editors when a new bean wrapper is
 * created. The wrapper is then cached and use for subsequent calls. But the get calls could bring in
 * new custom editors we need to copy.</p>
 *
 * {@inheritDoc}
 */
@Override
protected BeanWrapperImpl getBeanWrapperForPropertyPath(String propertyPath) {
    BeanWrapperImpl beanWrapper = super.getBeanWrapperForPropertyPath(propertyPath);

    PropertyTokenHolder tokens = getPropertyNameTokens(propertyPath);
    String canonicalName = tokens.canonicalName;

    int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(canonicalName);
    if (pos != -1) {
        canonicalName = canonicalName.substring(0, pos);
    }

    copyCustomEditorsTo(beanWrapper, canonicalName);

    return beanWrapper;
}
 
Example #5
Source File: ReferenceLinker.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
* Gets indexes that have been modified.
*
* <p>
*     Returns a set of indexes which have been modified in the given collection. If the returned set contains
*     {@link java.lang.Integer#MAX_VALUE} then it means that it should be treated as if all items in the collection
*     have been modified.
* </p>
*
* @return indexes which have been modified in the given collection
*/
private Set<Integer> extractModifiedIndicies(DataObjectCollection collectionMetadata,
        Map<String, Set<String>> decomposedPaths) {
    String relationshipName = collectionMetadata.getName();
    Set<Integer> modifiedIndicies = Sets.newHashSet();
    // if it contains *exactly* the collection relationship name, then indicate that all items modified
    if (decomposedPaths.containsKey(relationshipName)) {
        modifiedIndicies.add(Integer.valueOf(Integer.MAX_VALUE));
    }
    for (String propertyName : decomposedPaths.keySet()) {
        if (relationshipName.equals(PropertyAccessorUtils.getPropertyName(relationshipName))) {
            Integer index = extractIndex(propertyName);
            if (index != null) {
                modifiedIndicies.add(index);
            }
        }
    }
    return modifiedIndicies;
}
 
Example #6
Source File: DataObjectWrapperBase.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Gets the property type for a property name in a relationship.
 *
 * @param objectMetadata the metadata object.
 * @param attributePrefix the prefix of the property that indicated it was in a relationship.
 * @param attributeName the name of the property.
 * @return the property type for a property name.
 */
private Class<?> traverseRelationship(DataObjectMetadata objectMetadata,String attributePrefix,
                                      String attributeName){
    DataObjectRelationship rd = objectMetadata.getRelationship(attributePrefix);
    if(rd != null){
        DataObjectMetadata relatedObjectMetadata =
                dataObjectService.getMetadataRepository().getMetadata(rd.getRelatedType());
        if(relatedObjectMetadata != null){
            if(PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)){
                return getPropertyTypeChild(relatedObjectMetadata,attributeName);
            } else{
                if(relatedObjectMetadata.getAttribute(attributeName) == null &&
                        relatedObjectMetadata.getRelationship(attributeName)!=null){
                    DataObjectRelationship relationship = relatedObjectMetadata.getRelationship(attributeName);
                    return relationship.getRelatedType();
                }
                return relatedObjectMetadata.getAttribute(attributeName).getDataType().getType();
            }
        }
    }
    return null;
}
 
Example #7
Source File: DataObjectWrapperBase.java    From rice with Educational Community License v2.0 6 votes vote down vote up
/**
 * Gets the property type for a property name.
 *
 * @param objectMetadata the metadata object.
 * @param propertyName the name of the property.
 * @return the property type for a property name.
 */
private Class<?> getPropertyTypeChild(DataObjectMetadata objectMetadata, String propertyName){
    if(PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)){
        String attributePrefix = StringUtils.substringBefore(propertyName,".");
        String attributeName = StringUtils.substringAfter(propertyName,".");

        if(StringUtils.isNotBlank(attributePrefix) && StringUtils.isNotBlank(attributeName) &&
                objectMetadata!= null){
            Class<?> propertyType = traverseRelationship(objectMetadata,attributePrefix,attributeName);
            if(propertyType != null){
                return propertyType;
            }
        }
    }
    return getPropertyType(propertyName);
}
 
Example #8
Source File: KRADLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 6 votes vote down vote up
@Override
public Map<String, String> getInquiryParameters(Object dataObject, List<String> keys, String propertyName) {
    Map<String, String> inquiryParameters = new HashMap<String, String>();
    org.kuali.rice.krad.data.metadata.DataObjectRelationship dataObjectRelationship = null;

    DataObjectMetadata objectMetadata =
            KRADServiceLocator.getDataObjectService().getMetadataRepository().getMetadata(dataObject.getClass());

    if (objectMetadata != null) {
        dataObjectRelationship = objectMetadata.getRelationshipByLastAttributeInRelationship(propertyName);
    }

    for (String keyName : keys) {
        String keyConversion = keyName;
        if (dataObjectRelationship != null) {
            keyConversion = dataObjectRelationship.getParentAttributeNameRelatedToChildAttributeName(keyName);
        } else if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
            String nestedAttributePrefix = KRADUtils.getNestedAttributePrefix(propertyName);
            keyConversion = nestedAttributePrefix + "." + keyName;
        }
        inquiryParameters.put(keyConversion, keyName);
    }
    return inquiryParameters;
}
 
Example #9
Source File: ViewHelperServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void refreshReferences(String referencesToRefresh) {
    Object model = ViewLifecycle.getModel();
    for (String reference : StringUtils.split(referencesToRefresh, KRADConstants.REFERENCES_TO_REFRESH_SEPARATOR)) {
        if (StringUtils.isBlank(reference)) {
            continue;
        }

        //ToDo: handle add line

        if (PropertyAccessorUtils.isNestedOrIndexedProperty(reference)) {
            String parentPath = KRADUtils.getNestedAttributePrefix(reference);
            Object parentObject = ObjectPropertyUtils.getPropertyValue(model, parentPath);
            String referenceObjectName = KRADUtils.getNestedAttributePrimitive(reference);

            if (parentObject == null) {
                LOG.warn("Unable to refresh references for " + referencesToRefresh +
                        ". Object not found in model. Nothing refreshed.");
                continue;
            }

            refreshReference(parentObject, referenceObjectName);
        } else {
            refreshReference(model, reference);
        }
    }
}
 
Example #10
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 5 votes vote down vote up
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
Example #11
Source File: DictionaryValidationServiceImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
/**
 * @see org.kuali.rice.krad.service.DictionaryValidationService#validateReferenceExistsAndIsActive(java.lang.Object
 * dataObject,
 * String, String, String)
 */
@Override
public boolean validateReferenceExistsAndIsActive(Object dataObject, String referenceName,
        String attributeToHighlightOnFail, String displayFieldName) {

    // if we're dealing with a nested attribute, we need to resolve down to the BO where the primitive attribute is located
    // this is primarily to deal with the case of a defaultExistenceCheck that uses an "extension", i.e referenceName
    // would be extension.attributeName
    if (PropertyAccessorUtils.isNestedOrIndexedProperty(referenceName)) {
        String nestedAttributePrefix = KRADUtils.getNestedAttributePrefix(referenceName);
        String nestedAttributePrimitive = KRADUtils.getNestedAttributePrimitive(referenceName);
        Object nestedObject = KradDataServiceLocator.getDataObjectService().wrap(dataObject)
                .getPropertyValueNullSafe(nestedAttributePrefix);
        return validateReferenceExistsAndIsActive(nestedObject, nestedAttributePrimitive,
                attributeToHighlightOnFail, displayFieldName);
    }

    boolean hasReferences = validateFkFieldsPopulated(dataObject, referenceName);
    boolean referenceExists = hasReferences && validateReferenceExists(dataObject, referenceName);
    boolean canIncludeActiveReference = referenceExists && (!(dataObject instanceof Inactivatable) ||
            ((Inactivatable) dataObject).isActive());
    boolean referenceActive = canIncludeActiveReference && validateReferenceIsActive(dataObject, referenceName);

    if(hasReferences && !referenceExists) {
        GlobalVariables.getMessageMap().putError(attributeToHighlightOnFail, RiceKeyConstants.ERROR_EXISTENCE,
                displayFieldName);
        return false;
    } else if(canIncludeActiveReference && !referenceActive) {
        GlobalVariables.getMessageMap().putError(attributeToHighlightOnFail, RiceKeyConstants.ERROR_INACTIVE,
                displayFieldName);
        return false;
    }

    return true;
}
 
Example #12
Source File: DataBinder.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
Example #13
Source File: KRADLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 5 votes vote down vote up
@Override
/**
 * Recursively calls getPropertyTypeChild if nested property to allow it to properly look it up
 */
public Class<?> getPropertyType(Object object, String propertyName) {
    DataObjectWrapper<?> wrappedObject = dataObjectService.wrap(object);
    if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
        return wrappedObject.getPropertyTypeNullSafe(wrappedObject.getWrappedClass(), propertyName);
    }
    return wrappedObject.getPropertyType(propertyName);
}
 
Example #14
Source File: DataBinder.java    From java-technology-stack with MIT License 5 votes vote down vote up
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
Example #15
Source File: DataBinder.java    From spring-analysis-note with MIT License 5 votes vote down vote up
/**
 * Check the given property values against the allowed fields,
 * removing values for fields that are not allowed.
 * @param mpvs the property values to be bound (can be modified)
 * @see #getAllowedFields
 * @see #isAllowed(String)
 */
protected void checkAllowedFields(MutablePropertyValues mpvs) {
	PropertyValue[] pvs = mpvs.getPropertyValues();
	for (PropertyValue pv : pvs) {
		String field = PropertyAccessorUtils.canonicalPropertyName(pv.getName());
		if (!isAllowed(field)) {
			mpvs.removePropertyValue(pv);
			getBindingResult().recordSuppressedField(field);
			if (logger.isDebugEnabled()) {
				logger.debug("Field [" + field + "] has been removed from PropertyValues " +
						"and will not be bound, because it has not been found in the list of allowed fields");
			}
		}
	}
}
 
Example #16
Source File: KRADLegacyDataAdapterImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
@Override
public org.kuali.rice.krad.bo.DataObjectRelationship getDataObjectRelationship(Object dataObject,
        Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly,
        boolean supportsLookup, boolean supportsInquiry) {
    RelationshipDefinition ddReference = getDictionaryRelationship(dataObjectClass, attributeName);

    org.kuali.rice.krad.bo.DataObjectRelationship relationship = null;
    DataObjectAttributeRelationship rel = null;
    if (PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)) {
        if (ddReference != null) {
            if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
                relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference,
                        attributePrefix, keysOnly);

                return relationship;
            }
        }

        if (dataObject == null) {
            try {
                dataObject = KRADUtils.createNewObjectFromClass(dataObjectClass);
            } catch (RuntimeException e) {
                // found interface or abstract class, just swallow exception and return a null relationship
                return null;
            }
        }

        // recurse down to the next object to find the relationship
        int nextObjectIndex = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(attributeName);
        if (nextObjectIndex == StringUtils.INDEX_NOT_FOUND) {
            nextObjectIndex = attributeName.length();
        }
        String localPrefix = StringUtils.substring(attributeName, 0, nextObjectIndex);
        String localAttributeName = StringUtils.substring(attributeName, nextObjectIndex + 1);
        Object nestedObject = ObjectPropertyUtils.getPropertyValue(dataObject, localPrefix);
        Class<?> nestedClass = null;
        if (nestedObject == null) {
            nestedClass = ObjectPropertyUtils.getPropertyType(dataObject, localPrefix);
        } else {
            nestedClass = nestedObject.getClass();
        }

        String fullPrefix = localPrefix;
        if (StringUtils.isNotBlank(attributePrefix)) {
            fullPrefix = attributePrefix + "." + localPrefix;
        }

        relationship = getDataObjectRelationship(nestedObject, nestedClass, localAttributeName, fullPrefix,
                keysOnly, supportsLookup, supportsInquiry);

        return relationship;
    }

    // non-nested reference, get persistence relationships first
    int maxSize = Integer.MAX_VALUE;

    if (isPersistable(dataObjectClass)) {
        DataObjectMetadata metadata = dataObjectService.getMetadataRepository().getMetadata(dataObjectClass);
        DataObjectRelationship dataObjectRelationship = metadata.getRelationship(attributeName);

        if (dataObjectRelationship != null) {
            List<DataObjectAttributeRelationship> attributeRelationships =
                    dataObjectRelationship.getAttributeRelationships();
            for (DataObjectAttributeRelationship dataObjectAttributeRelationship : attributeRelationships) {
                if (classHasSupportedFeatures(dataObjectRelationship.getRelatedType(), supportsLookup,
                        supportsInquiry)) {
                    maxSize = attributeRelationships.size();
                    relationship = transformToDeprecatedDataObjectRelationship(dataObjectClass, attributeName,
                            attributePrefix, dataObjectRelationship.getRelatedType(),
                            dataObjectAttributeRelationship);

                    break;
                }
            }
        }

    } else {
        ModuleService moduleService = kualiModuleService.getResponsibleModuleService(dataObjectClass);
        if (moduleService != null && moduleService.isExternalizable(dataObjectClass)) {
            relationship = getRelationshipMetadata(dataObjectClass, attributeName, attributePrefix);
            if ((relationship != null) && classHasSupportedFeatures(relationship.getRelatedClass(), supportsLookup,
                    supportsInquiry)) {
                return relationship;
            } else {
                return null;
            }
        }
    }

    if (ddReference != null && ddReference.getPrimitiveAttributes().size() < maxSize) {
        if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
            relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, null,
                    keysOnly);
        }
    }
    return relationship;
}
 
Example #17
Source File: AbstractPropertyBindingResult.java    From lams with GNU General Public License v2.0 4 votes vote down vote up
/**
 * Returns the canonical property name.
 * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName
 */
@Override
protected String canonicalFieldName(String field) {
	return PropertyAccessorUtils.canonicalPropertyName(field);
}
 
Example #18
Source File: AbstractPropertyBindingResult.java    From spring4-understanding with Apache License 2.0 4 votes vote down vote up
/**
 * Returns the canonical property name.
 * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName
 */
@Override
protected String canonicalFieldName(String field) {
	return PropertyAccessorUtils.canonicalPropertyName(field);
}
 
Example #19
Source File: InquirableImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
/**
 * @see Inquirable#buildInquirableLink(java.lang.Object,
 *      java.lang.String, org.kuali.rice.krad.uif.widget.Inquiry)
 */
@Override
public void buildInquirableLink(Object dataObject, String propertyName, Inquiry inquiry) {
    Class<?> inquiryObjectClass = null;

    // inquiry into data object class if property is title attribute
    Class<?> objectClass = KRADUtils.materializeClassForProxiedObject(dataObject);
    if (propertyName.equals(KRADServiceLocatorWeb.getLegacyDataAdapter().getTitleAttribute(objectClass))) {
        inquiryObjectClass = objectClass;
    } else if (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyName)) {
        String nestedPropertyName = KRADUtils.getNestedAttributePrefix(propertyName);
        Object nestedPropertyObject = KRADUtils.getNestedValue(dataObject, nestedPropertyName);

        if (KRADUtils.isNotNull(nestedPropertyObject)) {
            String nestedPropertyPrimitive = KRADUtils.getNestedAttributePrimitive(propertyName);
            Class<?> nestedPropertyObjectClass = KRADUtils.materializeClassForProxiedObject(nestedPropertyObject);

            if (nestedPropertyPrimitive.equals(KRADServiceLocatorWeb.getLegacyDataAdapter().getTitleAttribute(
                    nestedPropertyObjectClass))) {
                inquiryObjectClass = nestedPropertyObjectClass;
            }
        }
    }

    // if not title, then get primary relationship
    if (inquiryObjectClass == null) {
        inquiryObjectClass = getLegacyDataAdapter().getInquiryObjectClassIfNotTitle(dataObject,propertyName);
    }

    // if haven't found inquiry class, then no inquiry can be rendered
    if (inquiryObjectClass == null) {
        inquiry.setRender(false);

        return;
    }

    if (DocumentHeader.class.isAssignableFrom(inquiryObjectClass)) {
        String documentNumber = (String) KradDataServiceLocator.getDataObjectService().wrap(dataObject).getPropertyValueNullSafe(propertyName);
        if (StringUtils.isNotBlank(documentNumber)) {
            inquiry.getInquiryLink().setHref(getConfigurationService().getPropertyValueAsString(
                    KRADConstants.WORKFLOW_URL_KEY)
                    + KRADConstants.DOCHANDLER_DO_URL
                    + documentNumber
                    + KRADConstants.DOCHANDLER_URL_CHUNK);
            inquiry.getInquiryLink().setLinkText(documentNumber);
            inquiry.setRender(true);
        }

        return;
    }

    synchronized (SUPER_CLASS_TRANSLATOR_LIST) {
        for (Class<?> clazz : SUPER_CLASS_TRANSLATOR_LIST) {
            if (clazz.isAssignableFrom(inquiryObjectClass)) {
                inquiryObjectClass = clazz;
                break;
            }
        }
    }

    if (!inquiryObjectClass.isInterface() && ExternalizableBusinessObject.class.isAssignableFrom(
            inquiryObjectClass)) {
        inquiryObjectClass = ExternalizableBusinessObjectUtils.determineExternalizableBusinessObjectSubInterface(
                inquiryObjectClass);
    }

    // listPrimaryKeyFieldNames returns an unmodifiable list. So a copy is necessary.
    List<String> keys = new ArrayList<String>(getLegacyDataAdapter().listPrimaryKeyFieldNames(
            inquiryObjectClass));

    if (keys == null) {
        keys = Collections.emptyList();
    }

    // build inquiry parameter mappings
    Map<String, String> inquiryParameters = getLegacyDataAdapter().getInquiryParameters(dataObject,keys,propertyName);

    inquiry.buildInquiryLink(dataObject, propertyName, inquiryObjectClass, inquiryParameters);
}
 
Example #20
Source File: AbstractPropertyBindingResult.java    From spring-analysis-note with MIT License 4 votes vote down vote up
/**
 * Returns the canonical property name.
 * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName
 */
@Override
protected String canonicalFieldName(String field) {
	return PropertyAccessorUtils.canonicalPropertyName(field);
}
 
Example #21
Source File: AbstractPropertyBindingResult.java    From java-technology-stack with MIT License 4 votes vote down vote up
/**
 * Returns the canonical property name.
 * @see org.springframework.beans.PropertyAccessorUtils#canonicalPropertyName
 */
@Override
protected String canonicalFieldName(String field) {
	return PropertyAccessorUtils.canonicalPropertyName(field);
}
 
Example #22
Source File: DataObjectMetaDataServiceImpl.java    From rice with Educational Community License v2.0 4 votes vote down vote up
protected DataObjectRelationship getDataObjectRelationship(RelationshipDefinition ddReference, Object dataObject,
        Class<?> dataObjectClass, String attributeName, String attributePrefix, boolean keysOnly,
        boolean supportsLookup, boolean supportsInquiry) {
    DataObjectRelationship relationship = null;

    // if it is nested then replace the data object and attributeName with the
    // sub-refs
    if (PropertyAccessorUtils.isNestedOrIndexedProperty(attributeName)) {
        if (ddReference != null) {
            if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
                relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference,
                        attributePrefix, keysOnly);

                return relationship;
            }
        }

        // recurse down to the next object to find the relationship
        String localPrefix = StringUtils.substringBefore(attributeName, ".");
        String localAttributeName = StringUtils.substringAfter(attributeName, ".");
        if (dataObject == null) {
            try {
                dataObject = KRADUtils.createNewObjectFromClass(dataObjectClass);
            } catch (RuntimeException e) {
                // found interface or abstract class, just swallow exception and return a null relationship
                return null;
            }
        }

        Object nestedObject = ObjectPropertyUtils.getPropertyValue(dataObject, localPrefix);
        Class<?> nestedClass = null;
        if (nestedObject == null) {
            nestedClass = ObjectPropertyUtils.getPropertyType(dataObject, localPrefix);
        } else {
            nestedClass = nestedObject.getClass();
        }

        String fullPrefix = localPrefix;
        if (StringUtils.isNotBlank(attributePrefix)) {
            fullPrefix = attributePrefix + "." + localPrefix;
        }

        relationship = getDataObjectRelationship(nestedObject, nestedClass, localAttributeName, fullPrefix,
                keysOnly, supportsLookup, supportsInquiry);

        return relationship;
    }

    // non-nested reference, get persistence relationships first
    int maxSize = Integer.MAX_VALUE;

    // try persistable reference first
    if (getPersistenceStructureService().isPersistable(dataObjectClass)) {
        Map<String, DataObjectRelationship> rels = getPersistenceStructureService().getRelationshipMetadata(
                dataObjectClass, attributeName, attributePrefix);
        if (rels.size() > 0) {
            for (DataObjectRelationship rel : rels.values()) {
                if (rel.getParentToChildReferences().size() < maxSize) {
                    if (classHasSupportedFeatures(rel.getRelatedClass(), supportsLookup, supportsInquiry)) {
                        maxSize = rel.getParentToChildReferences().size();
                        relationship = rel;
                    }
                }
            }
        }
    } else {
        ModuleService moduleService = getKualiModuleService().getResponsibleModuleService(dataObjectClass);
        if (moduleService != null && moduleService.isExternalizable(dataObjectClass)) {
            relationship = getRelationshipMetadata(dataObjectClass, attributeName, attributePrefix);
            if ((relationship != null) && classHasSupportedFeatures(relationship.getRelatedClass(), supportsLookup,
                    supportsInquiry)) {
                return relationship;
            } else {
                return null;
            }
        }
    }

    if (ddReference != null && ddReference.getPrimitiveAttributes().size() < maxSize) {
        if (classHasSupportedFeatures(ddReference.getTargetClass(), supportsLookup, supportsInquiry)) {
            relationship = populateRelationshipFromDictionaryReference(dataObjectClass, ddReference, null,
                    keysOnly);
        }
    }

    return relationship;
}
 
Example #23
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 3 votes vote down vote up
/**
 * Register fields that are required for each binding process.
 * <p>If one of the specified fields is not contained in the list of
 * incoming property values, a corresponding "missing field" error
 * will be created, with error code "required" (by the default
 * binding error processor).
 * @param requiredFields array of field names
 * @see #setBindingErrorProcessor
 * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE
 */
public void setRequiredFields(String... requiredFields) {
	this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields);
	if (logger.isDebugEnabled()) {
		logger.debug("DataBinder requires binding of required fields [" +
				StringUtils.arrayToCommaDelimitedString(requiredFields) + "]");
	}
}
 
Example #24
Source File: DataBinder.java    From lams with GNU General Public License v2.0 3 votes vote down vote up
/**
 * Register fields that are required for each binding process.
 * <p>If one of the specified fields is not contained in the list of
 * incoming property values, a corresponding "missing field" error
 * will be created, with error code "required" (by the default
 * binding error processor).
 * @param requiredFields array of field names
 * @see #setBindingErrorProcessor
 * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE
 */
public void setRequiredFields(String... requiredFields) {
	this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields);
	if (logger.isDebugEnabled()) {
		logger.debug("DataBinder requires binding of required fields [" +
				StringUtils.arrayToCommaDelimitedString(requiredFields) + "]");
	}
}
 
Example #25
Source File: DataBinder.java    From java-technology-stack with MIT License 3 votes vote down vote up
/**
 * Register fields that are required for each binding process.
 * <p>If one of the specified fields is not contained in the list of
 * incoming property values, a corresponding "missing field" error
 * will be created, with error code "required" (by the default
 * binding error processor).
 * @param requiredFields array of field names
 * @see #setBindingErrorProcessor
 * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE
 */
public void setRequiredFields(@Nullable String... requiredFields) {
	this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields);
	if (logger.isDebugEnabled()) {
		logger.debug("DataBinder requires binding of required fields [" +
				StringUtils.arrayToCommaDelimitedString(requiredFields) + "]");
	}
}
 
Example #26
Source File: DataBinder.java    From spring-analysis-note with MIT License 3 votes vote down vote up
/**
 * Register fields that are required for each binding process.
 * <p>If one of the specified fields is not contained in the list of
 * incoming property values, a corresponding "missing field" error
 * will be created, with error code "required" (by the default
 * binding error processor).
 * @param requiredFields array of field names
 * @see #setBindingErrorProcessor
 * @see DefaultBindingErrorProcessor#MISSING_FIELD_ERROR_CODE
 */
public void setRequiredFields(@Nullable String... requiredFields) {
	this.requiredFields = PropertyAccessorUtils.canonicalPropertyNames(requiredFields);
	if (logger.isDebugEnabled()) {
		logger.debug("DataBinder requires binding of required fields [" +
				StringUtils.arrayToCommaDelimitedString(requiredFields) + "]");
	}
}
 
Example #27
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Register fields that should <i>not</i> be allowed for binding. Default is none.
 * Mark fields as disallowed for example to avoid unwanted modifications
 * by malicious users when binding HTTP request parameters.
 * <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
 * can be implemented by overriding the {@code isAllowed} method.
 * <p>Alternatively, specify a list of <i>allowed</i> fields.
 * @param disallowedFields array of field names
 * @see #setAllowedFields
 * @see #isAllowed(String)
 * @see org.springframework.web.bind.ServletRequestDataBinder
 */
public void setDisallowedFields(String... disallowedFields) {
	this.disallowedFields = PropertyAccessorUtils.canonicalPropertyNames(disallowedFields);
}
 
Example #28
Source File: KRADUtils.java    From rice with Educational Community License v2.0 2 votes vote down vote up
/**
 * Returns the prefix of a nested attribute name, or the empty string if the attribute name is not nested.
 *
 * @param attributeName
 * @return everything BEFORE the last "." character in attributeName
 */
public static String getNestedAttributePrefix(String attributeName) {
    int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(attributeName);

    return lastIndex != -1 ? StringUtils.substring(attributeName, 0, lastIndex) : StringUtils.EMPTY;
}
 
Example #29
Source File: KRADUtils.java    From rice with Educational Community License v2.0 2 votes vote down vote up
/**
 * Returns the primitive part of an attribute name string.
 *
 * @param attributeName
 * @return everything AFTER the last "." character in attributeName
 */
public static String getNestedAttributePrimitive(String attributeName) {
    int lastIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(attributeName);

    return lastIndex != -1 ? StringUtils.substring(attributeName, lastIndex + 1) : attributeName;
}
 
Example #30
Source File: DataBinder.java    From spring4-understanding with Apache License 2.0 2 votes vote down vote up
/**
 * Register fields that should be allowed for binding. Default is all
 * fields. Restrict this for example to avoid unwanted modifications
 * by malicious users when binding HTTP request parameters.
 * <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
 * can be implemented by overriding the {@code isAllowed} method.
 * <p>Alternatively, specify a list of <i>disallowed</i> fields.
 * @param allowedFields array of field names
 * @see #setDisallowedFields
 * @see #isAllowed(String)
 * @see org.springframework.web.bind.ServletRequestDataBinder
 */
public void setAllowedFields(String... allowedFields) {
	this.allowedFields = PropertyAccessorUtils.canonicalPropertyNames(allowedFields);
}