List of usage examples for org.springframework.beans PropertyAccessorUtils isNestedOrIndexedProperty
public static boolean isNestedOrIndexedProperty(@Nullable String propertyPath)
From source file:org.obiba.magma.beans.BeanVariableValueSourceFactory.java
/** * Finds the type ({@code Class}) for a given {@code propertyName} which may denote a nested property (property path * e.g: a.b.c) or mapped property (attribute[key]) or a combination of both (e.g.: a.b[c].d). * * @param propertyName//w w w. j a v a2s. c o m * @return */ @SuppressWarnings({ "OverlyLongMethod", "PMD.NcssMethodCount" }) protected Class<?> getPropertyType(String propertyName) { // Has a property type been explicitly declared? If so, use it. Class<?> declaredPropertyType = propertyNameToPropertyType.get(propertyName); if (declaredPropertyType != null) { return declaredPropertyType; } Class<?> currentType = getBeanClass(); String propertyPath = propertyName; // Loop as long as the propertyPath designates a nested property while (PropertyAccessorUtils.isNestedOrIndexedProperty(propertyPath)) { int pos = PropertyAccessorUtils.getFirstNestedPropertySeparatorIndex(propertyPath); String nestedProperty = pos > -1 ? propertyPath.substring(0, pos) : propertyPath; // Check whether this is a mapped property (a[b]) if (PropertyAccessorUtils.isNestedOrIndexedProperty(nestedProperty)) { // We cannot determine the type of these properties through reflection (even when they contain type parameters // i.e. Map<String, String>). // The type of these properties has to be specified through configuration currentType = getMapAttributeType(PropertyAccessorUtils.getPropertyName(nestedProperty)); if (pos == -1) { return currentType; } propertyPath = propertyPath.substring(pos + 1); } else { PropertyDescriptor currentProperty = BeanUtils.getPropertyDescriptor(currentType, nestedProperty); if (currentProperty == null) { throw new IllegalArgumentException("Invalid path '" + propertyName + "' for type " + getBeanClass().getName() + ": nested property '" + nestedProperty + "' does not exist on type " + currentType.getName()); } // Change the current type so it points to the nested type currentType = currentProperty.getPropertyType(); // Extract the nested type's property path from the original path propertyPath = propertyPath.substring(pos + 1); } } // propertyPath is a direct reference to a property of the currentType (no longer a path) PropertyDescriptor descriptor = BeanUtils.getPropertyDescriptor(currentType, propertyPath); if (descriptor == null) { throw new IllegalArgumentException( "Invalid path '" + propertyName + "' for type " + getBeanClass().getName() + ": property '" + propertyPath + "' does not exist on type " + currentType.getName()); } return descriptor.getPropertyType(); }
From source file:org.kuali.rice.kim.impl.identity.PersonServiceImpl.java
private boolean isPersonProperty(Object bo, String propertyName) { try {/*from w ww. j av a2s .c o m*/ 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; }
From source file:org.kuali.rice.kim.impl.identity.PersonServiceImpl.java
/** * @see org.kuali.rice.kim.api.identity.PersonService#resolvePrincipalNamesToPrincipalIds(org.kuali.rice.krad.bo.BusinessObject, java.util.Map) */// w w w . j av a2s. c om @Override @SuppressWarnings("unchecked") public Map<String, String> resolvePrincipalNamesToPrincipalIds(BusinessObject businessObject, Map<String, String> fieldValues) { if (fieldValues == null) { return null; } if (businessObject == null) { return fieldValues; } StringBuffer resolvedPrincipalIdPropertyName = new StringBuffer(); // save off all criteria which are not references to Person properties // leave person properties out so they can be resolved and replaced by this method Map<String, String> processedFieldValues = getNonPersonSearchCriteria(businessObject, fieldValues); for (String propertyName : fieldValues.keySet()) { if (!StringUtils.isBlank(fieldValues.get(propertyName)) // property has a value && isPersonProperty(businessObject, propertyName) // is a property on a Person object ) { // strip off the prefix on the property int lastPropertyIndex = PropertyAccessorUtils.getLastNestedPropertySeparatorIndex(propertyName); String personPropertyName = lastPropertyIndex != -1 ? StringUtils.substring(propertyName, lastPropertyIndex + 1) : propertyName; // special case - the user ID if (StringUtils.equals(KIMPropertyConstants.Person.PRINCIPAL_NAME, personPropertyName)) { Class targetBusinessObjectClass = null; BusinessObject targetBusinessObject = null; resolvedPrincipalIdPropertyName.setLength(0); // clear the buffer without requiring a new object allocation on each iteration // get the property name up until the ".principalName" // this should be a reference to the Person object attached to the BusinessObject String personReferenceObjectPropertyName = lastPropertyIndex != -1 ? StringUtils.substring(propertyName, 0, lastPropertyIndex) : StringUtils.EMPTY; // check if the person was nested within another BO under the master BO. If so, go up one more level // otherwise, use the passed in BO class as the target class if (PropertyAccessorUtils.isNestedOrIndexedProperty(personReferenceObjectPropertyName)) { int lastTargetIndex = PropertyAccessorUtils .getLastNestedPropertySeparatorIndex(personReferenceObjectPropertyName); String targetBusinessObjectPropertyName = lastTargetIndex != -1 ? StringUtils.substring(personReferenceObjectPropertyName, 0, lastTargetIndex) : StringUtils.EMPTY; DataObjectWrapper<BusinessObject> wrapper = KradDataServiceLocator.getDataObjectService() .wrap(businessObject); targetBusinessObject = (BusinessObject) wrapper .getPropertyValueNullSafe(targetBusinessObjectPropertyName); if (targetBusinessObject != null) { targetBusinessObjectClass = targetBusinessObject.getClass(); resolvedPrincipalIdPropertyName.append(targetBusinessObjectPropertyName).append("."); } else { LOG.error("Could not find target property '" + propertyName + "' in class " + businessObject.getClass().getName() + ". Property value was null."); } } else { // not a nested Person property targetBusinessObjectClass = businessObject.getClass(); targetBusinessObject = businessObject; } if (targetBusinessObjectClass != null) { // use the relationship metadata in the KNS to determine the property on the // host business object to put back into the map now that the principal ID // (the value stored in application tables) has been resolved int lastIndex = PropertyAccessorUtils .getLastNestedPropertySeparatorIndex(personReferenceObjectPropertyName); String propName = lastIndex != -1 ? StringUtils.substring(personReferenceObjectPropertyName, lastIndex + 1) : personReferenceObjectPropertyName; DataObjectRelationship rel = getBusinessObjectMetaDataService() .getBusinessObjectRelationship(targetBusinessObject, propName); if (rel != null) { String sourcePrimitivePropertyName = rel .getParentAttributeForChildAttribute(KIMPropertyConstants.Person.PRINCIPAL_ID); resolvedPrincipalIdPropertyName.append(sourcePrimitivePropertyName); // get the principal - for translation of the principalName to principalId String principalName = fieldValues.get(propertyName); Principal principal = getIdentityService().getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), principal.getPrincipalId()); } else { processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); try { // if the principalName is bad, then we need to clear out the Person object // and base principalId property // so that their values are no longer accidentally used or re-populate // the object KRADUtils.setObjectProperty(targetBusinessObject, resolvedPrincipalIdPropertyName.toString(), null); KRADUtils.setObjectProperty(targetBusinessObject, propName, null); KRADUtils.setObjectProperty(targetBusinessObject, propName + ".principalName", principalName); } catch (Exception ex) { LOG.error( "Unable to blank out the person object after finding that the person with the given principalName does not exist.", ex); } } } else { LOG.error("Missing relationship for " + propName + " on " + targetBusinessObjectClass.getName()); } } else { // no target BO class - the code below probably will not work processedFieldValues.put(resolvedPrincipalIdPropertyName.toString(), null); } } // if the property does not seem to match the definition of a Person property but it // does end in principalName then... // this is to handle the case where the user ID is on an ADD line - a case excluded from isPersonProperty() } else if (propertyName.endsWith("." + KIMPropertyConstants.Person.PRINCIPAL_NAME)) { // if we're adding to a collection and we've got the principalName; let's populate universalUser String principalName = fieldValues.get(propertyName); if (StringUtils.isNotEmpty(principalName)) { String containerPropertyName = propertyName; if (containerPropertyName.startsWith(KRADConstants.MAINTENANCE_ADD_PREFIX)) { containerPropertyName = StringUtils.substringAfter(propertyName, KRADConstants.MAINTENANCE_ADD_PREFIX); } // get the class of the object that is referenced by the property name // if this is not true then there's a principalName collection or primitive attribute // directly on the BO on the add line, so we just ignore that since something is wrong here if (PropertyAccessorUtils.isNestedOrIndexedProperty(containerPropertyName)) { // the first part of the property is the collection name String collectionName = StringUtils.substringBefore(containerPropertyName, "."); // what is the class held by that collection? // JHK: I don't like this. This assumes that this method is only used by the maintenance // document service. If that will always be the case, this method should be moved over there. Class<? extends BusinessObject> collectionBusinessObjectClass = getMaintenanceDocumentDictionaryService() .getCollectionBusinessObjectClass(getMaintenanceDocumentDictionaryService() .getDocumentTypeName(businessObject.getClass()), collectionName); if (collectionBusinessObjectClass != null) { // we are adding to a collection; get the relationships for that object; // is there one for personUniversalIdentifier? List<DataObjectRelationship> relationships = getBusinessObjectMetaDataService() .getBusinessObjectRelationships(collectionBusinessObjectClass); // JHK: this seems like a hack - looking at all relationships for a BO does not guarantee that we get the right one // JHK: why not inspect the objects like above? Is it the property path problems because of the .add. portion? for (DataObjectRelationship rel : relationships) { String parentAttribute = rel.getParentAttributeForChildAttribute( KIMPropertyConstants.Person.PRINCIPAL_ID); if (parentAttribute == null) { continue; } // there is a relationship for personUserIdentifier; use that to find the universal user processedFieldValues.remove(propertyName); String fieldPrefix = StringUtils .substringBeforeLast(StringUtils.substringBeforeLast(propertyName, "." + KIMPropertyConstants.Person.PRINCIPAL_NAME), "."); String relatedPrincipalIdPropertyName = fieldPrefix + "." + parentAttribute; // KR-683 Special handling for extension objects if (EXTENSION.equals(StringUtils.substringAfterLast(fieldPrefix, ".")) && EXTENSION.equals(StringUtils.substringBefore(parentAttribute, "."))) { relatedPrincipalIdPropertyName = fieldPrefix + "." + StringUtils.substringAfter(parentAttribute, "."); } String currRelatedPersonPrincipalId = processedFieldValues .get(relatedPrincipalIdPropertyName); if (StringUtils.isBlank(currRelatedPersonPrincipalId)) { Principal principal = getIdentityService() .getPrincipalByPrincipalName(principalName); if (principal != null) { processedFieldValues.put(relatedPrincipalIdPropertyName, principal.getPrincipalId()); } else { processedFieldValues.put(relatedPrincipalIdPropertyName, null); } } } // relationship loop } else { if (LOG.isDebugEnabled()) { LOG.debug( "Unable to determine class for collection referenced as part of property: " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } else { if (LOG.isDebugEnabled()) { LOG.debug("Non-nested property ending with 'principalName': " + containerPropertyName + " on " + businessObject.getClass().getName()); } } } } } return processedFieldValues; }
From source file:org.kuali.rice.krad.data.provider.impl.DataObjectWrapperBase.java
/** * 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. *//*from ww w.jav a 2 s.c o m*/ 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); }
From source file:org.kuali.rice.krad.data.provider.impl.DataObjectWrapperBase.java
/** * 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. *///from w w w. jav a2s. c om 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; }
From source file:org.kuali.rice.krad.inquiry.InquirableImpl.java
/** * @see Inquirable#buildInquirableLink(java.lang.Object, * java.lang.String, org.kuali.rice.krad.uif.widget.Inquiry) *//* w ww . j a va2 s.c o m*/ @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); }
From source file:org.kuali.rice.krad.lookup.LookupUtils.java
/** * Looks for criteria against nested EBOs and performs a search against that EBO and updates the criteria. * * @param searchCriteria map of criteria currently set * @param unbounded indicates whether the complete result should be returned. When set to false the result is * limited (if necessary) to the max search result limit configured. * @return Map of adjusted criteria for nested EBOs * @throws InstantiationException/* w w w . j a va2s . c o m*/ * @throws IllegalAccessException */ public static Map<String, String> adjustCriteriaForNestedEBOs(Class<?> dataObjectClass, Map<String, String> searchCriteria, boolean unbounded) throws InstantiationException, IllegalAccessException { // remove the EBO criteria Map<String, String> nonEboFieldValues = removeExternalizableBusinessObjectFieldValues(dataObjectClass, searchCriteria); if (LOG.isDebugEnabled()) { LOG.debug("Non EBO properties removed: " + nonEboFieldValues); } // get the list of EBO properties attached to this object List<String> eboPropertyNames = getExternalizableBusinessObjectProperties(dataObjectClass, searchCriteria); if (LOG.isDebugEnabled()) { LOG.debug("EBO properties: " + eboPropertyNames); } // loop over those properties for (String eboPropertyName : eboPropertyNames) { // extract the properties as known to the EBO Map<String, String> eboFieldValues = LookupUtils .getExternalizableBusinessObjectFieldValues(eboPropertyName, searchCriteria); if (LOG.isDebugEnabled()) { LOG.debug("EBO properties for master EBO property: " + eboPropertyName); LOG.debug("properties: " + eboFieldValues); } // run search against attached EBO's module service ModuleService eboModuleService = KRADServiceLocatorWeb.getKualiModuleService() .getResponsibleModuleService( getExternalizableBusinessObjectClass(dataObjectClass, eboPropertyName)); // KULRICE-4401 made eboResults an empty list and only filled if service is found. List<?> eboResults = Collections.emptyList(); if (eboModuleService != null) { eboResults = eboModuleService.getExternalizableBusinessObjectsListForLookup( getExternalizableBusinessObjectClass(dataObjectClass, eboPropertyName), (Map) eboFieldValues, unbounded); } else { LOG.debug("EBO ModuleService is null: " + eboPropertyName); } // get the parent property type Class<?> eboParentClass; String eboParentPropertyName; if (PropertyAccessorUtils.isNestedOrIndexedProperty(eboPropertyName)) { eboParentPropertyName = StringUtils.substringBeforeLast(eboPropertyName, "."); try { eboParentClass = KradDataServiceLocator.getDataObjectService() .wrap(dataObjectClass.newInstance()).getPropertyType(eboParentPropertyName); } catch (Exception ex) { throw new RuntimeException("Unable to create an instance of the business object class: " + dataObjectClass.getName(), ex); } } else { eboParentClass = dataObjectClass; eboParentPropertyName = null; } if (LOG.isDebugEnabled()) { LOG.debug("determined EBO parent class/property name: " + eboParentClass + "/" + eboParentPropertyName); } // look that up in the DD (BOMDS) find the appropriate relationship // CHECK THIS: what if eboPropertyName is a nested attribute - need to strip off the // eboParentPropertyName if not null RelationshipDefinition rd = KRADServiceLocatorWeb.getLegacyDataAdapter() .getDictionaryRelationship(eboParentClass, eboPropertyName); if (LOG.isDebugEnabled()) { LOG.debug("Obtained RelationshipDefinition for " + eboPropertyName); LOG.debug(rd); } // copy the needed properties (primary only) to the field values KULRICE-4446 do // so only if the relationship definition exists // NOTE: this will work only for single-field PK unless the ORM // layer is directly involved // (can't make (field1,field2) in ( (v1,v2),(v3,v4) ) style // queries in the lookup framework if (KRADUtils.isNotNull(rd)) { if (rd.getPrimitiveAttributes().size() > 1) { throw new RuntimeException( "EBO Links don't work for relationships with multiple-field primary keys."); } String boProperty = rd.getPrimitiveAttributes().get(0).getSourceName(); String eboProperty = rd.getPrimitiveAttributes().get(0).getTargetName(); StringBuffer boPropertyValue = new StringBuffer(); // loop over the results, making a string that the lookup DAO will convert into an // SQL "IN" clause for (Object ebo : eboResults) { if (boPropertyValue.length() != 0) { boPropertyValue.append(SearchOperator.OR.op()); } try { boPropertyValue.append(PropertyUtils.getProperty(ebo, eboProperty).toString()); } catch (Exception ex) { LOG.warn("Unable to get value for " + eboProperty + " on " + ebo); } } if (eboParentPropertyName == null) { // non-nested property containing the EBO nonEboFieldValues.put(boProperty, boPropertyValue.toString()); } else { // property nested within the main searched-for BO that contains the EBO nonEboFieldValues.put(eboParentPropertyName + "." + boProperty, boPropertyValue.toString()); } } } return nonEboFieldValues; }
From source file:org.kuali.rice.krad.service.impl.DataObjectMetaDataServiceImpl.java
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/*w w w. j av a2s .c om*/ 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; }
From source file:org.kuali.rice.krad.service.impl.DictionaryValidationServiceImpl.java
/** * @see org.kuali.rice.krad.service.DictionaryValidationService#validateReferenceExistsAndIsActive(java.lang.Object * dataObject,//from w ww.ja v a2 s.com * 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; }
From source file:org.kuali.rice.krad.service.impl.KNSLegacyDataAdapterImpl.java
@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; }//from ww w . ja v a2 s .c o m inquiryParameters.put(keyConversion, keyName); } return inquiryParameters; }