Search in sources :

Example 1 with KimAttribute

use of org.kuali.kfs.kim.impl.common.attribute.KimAttribute in project cu-kfs by CU-CommunityApps.

the class OrgReviewRoleServiceImpl method getAttributeDefinition.

protected KimAttribute getAttributeDefinition(String kimTypeId, String attributeName) {
    // attempt to pull from cache
    Map<String, KimAttribute> typeAttributes = ATTRIBUTE_CACHE.get(kimTypeId);
    // if type has not been loaded, init
    if (typeAttributes == null) {
        KimType kimType = KimApiServiceLocator.getKimTypeInfoService().getKimType(kimTypeId);
        if (kimType != null) {
            List<KimTypeAttribute> attributes = kimType.getAttributeDefinitions();
            typeAttributes = new HashMap<>();
            if (attributes != null) {
                // build the map and put it into the cache
                for (KimTypeAttribute att : attributes) {
                    typeAttributes.put(att.getKimAttribute().getAttributeName(), att.getKimAttribute());
                }
            }
            synchronized (ATTRIBUTE_CACHE) {
                ATTRIBUTE_CACHE.put(kimTypeId, typeAttributes);
            }
        }
    }
    // now, see if the attribute is in there
    if (typeAttributes != null) {
        return typeAttributes.get(attributeName);
    }
    return null;
}
Also used : KimType(org.kuali.kfs.kim.impl.type.KimType) KimTypeAttribute(org.kuali.kfs.kim.impl.type.KimTypeAttribute) KimAttribute(org.kuali.kfs.kim.impl.common.attribute.KimAttribute)

Example 2 with KimAttribute

use of org.kuali.kfs.kim.impl.common.attribute.KimAttribute in project cu-kfs by CU-CommunityApps.

the class AttributeValidationHelper method getAttributeDefinitionByName.

protected KimAttribute getAttributeDefinitionByName(String attributeName) {
    CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.CACHE_NAME);
    Cache cache = cm.getCache(KimAttribute.CACHE_NAME);
    // CU Customization (KFSPTS-23531): Build a more specific cache key
    String cacheKey = MessageFormat.format(ATTRIBUTE_BY_NAME_CACHE_KEY_PATTERN, attributeName);
    ValueWrapper valueWrapper = cache.get(cacheKey);
    if (valueWrapper != null) {
        return (KimAttribute) valueWrapper.get();
    }
    Map<String, String> criteria = new HashMap<>();
    criteria.put(KRADPropertyConstants.ATTRIBUTE_NAME, attributeName);
    List<KimAttribute> attributeImpls = (List<KimAttribute>) getBusinessObjectService().findMatching(KimAttribute.class, criteria);
    KimAttribute attribute = null;
    if (!attributeImpls.isEmpty()) {
        attribute = attributeImpls.get(0);
    }
    cache.put(cacheKey, attribute);
    return attribute;
}
Also used : ValueWrapper(org.springframework.cache.Cache.ValueWrapper) HashMap(java.util.HashMap) CacheManager(org.springframework.cache.CacheManager) KimAttribute(org.kuali.kfs.kim.impl.common.attribute.KimAttribute) ArrayList(java.util.ArrayList) List(java.util.List) Cache(org.springframework.cache.Cache)

Example 3 with KimAttribute

use of org.kuali.kfs.kim.impl.common.attribute.KimAttribute in project cu-kfs by CU-CommunityApps.

the class AttributeValidationHelper method convertQualifiersToAttrIdxMap.

public Map<String, String> convertQualifiersToAttrIdxMap(List<? extends KimDocumentAttributeDataBusinessObjectBase> qualifiers) {
    Map<String, String> m = new HashMap<>();
    int i = 0;
    for (KimDocumentAttributeDataBusinessObjectBase data : qualifiers) {
        KimAttribute attrib = getAttributeDefinitionById(data.getKimAttrDefnId());
        if (attrib != null) {
            m.put(attrib.getAttributeName(), Integer.toString(i));
        } else {
            LOG.error("Unable to get attribute name for ID:" + data.getKimAttrDefnId());
        }
        i++;
    }
    return m;
}
Also used : KimDocumentAttributeDataBusinessObjectBase(org.kuali.kfs.kim.bo.ui.KimDocumentAttributeDataBusinessObjectBase) HashMap(java.util.HashMap) KimAttribute(org.kuali.kfs.kim.impl.common.attribute.KimAttribute)

Example 4 with KimAttribute

use of org.kuali.kfs.kim.impl.common.attribute.KimAttribute in project cu-kfs by CU-CommunityApps.

the class AttributeValidationHelper method getAttributeDefinitionById.

protected KimAttribute getAttributeDefinitionById(String id) {
    CacheManager cm = CoreImplServiceLocator.getCacheManagerRegistry().getCacheManagerByCacheName(KimAttribute.CACHE_NAME);
    Cache cache = cm.getCache(KimAttribute.CACHE_NAME);
    String cacheKey = "{" + KimAttribute.CACHE_NAME + "}id=" + id;
    ValueWrapper valueWrapper = cache.get(cacheKey);
    if (valueWrapper != null) {
        return (KimAttribute) valueWrapper.get();
    }
    KimAttribute attribute = getBusinessObjectService().findBySinglePrimaryKey(KimAttribute.class, id);
    cache.put(cacheKey, attribute);
    return attribute;
}
Also used : ValueWrapper(org.springframework.cache.Cache.ValueWrapper) CacheManager(org.springframework.cache.CacheManager) KimAttribute(org.kuali.kfs.kim.impl.common.attribute.KimAttribute) Cache(org.springframework.cache.Cache)

Example 5 with KimAttribute

use of org.kuali.kfs.kim.impl.common.attribute.KimAttribute in project cu-kfs by CU-CommunityApps.

the class AttributeValidationHelper method convertErrorsForMappedFields.

public List<AttributeError> convertErrorsForMappedFields(String errorPath, List<AttributeError> localErrors) {
    List<AttributeError> errors = new ArrayList<>();
    if (errorPath == null) {
        errorPath = KFSConstants.EMPTY_STRING;
    } else if (StringUtils.isNotEmpty(errorPath)) {
        errorPath = errorPath + ".";
    }
    for (AttributeError error : localErrors) {
        KimAttribute attribute = getAttributeDefinitionByName(error.getAttributeName());
        String attributeDefnId = attribute == null ? "" : attribute.getId();
        errors.add(AttributeError.Builder.create(errorPath + "qualifier(" + attributeDefnId + ").attrVal", error.getErrors()).build());
    }
    return errors;
}
Also used : AttributeError(org.kuali.kfs.core.api.uif.AttributeError) ArrayList(java.util.ArrayList) KimAttribute(org.kuali.kfs.kim.impl.common.attribute.KimAttribute)

Aggregations

KimAttribute (org.kuali.kfs.kim.impl.common.attribute.KimAttribute)6 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 Cache (org.springframework.cache.Cache)2 ValueWrapper (org.springframework.cache.Cache.ValueWrapper)2 CacheManager (org.springframework.cache.CacheManager)2 List (java.util.List)1 KfsKimDocumentAttributeData (org.kuali.kfs.coa.identity.KfsKimDocumentAttributeData)1 AttributeError (org.kuali.kfs.core.api.uif.AttributeError)1 KimDocumentAttributeDataBusinessObjectBase (org.kuali.kfs.kim.bo.ui.KimDocumentAttributeDataBusinessObjectBase)1 KimType (org.kuali.kfs.kim.impl.type.KimType)1 KimTypeAttribute (org.kuali.kfs.kim.impl.type.KimTypeAttribute)1