Search in sources :

Example 1 with Getter

use of org.gluu.persist.reflect.property.Getter in project oxCore by GluuFederation.

the class BaseEntryManager method getAttributeFromLdapAttribute.

private AttributeData getAttributeFromLdapAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
    Class<?> entryClass = entry.getClass();
    String ldapAttributeName = ((LdapAttribute) ldapAttribute).name();
    if (StringHelper.isEmpty(ldapAttributeName)) {
        ldapAttributeName = propertyName;
    }
    Getter getter = getGetter(entryClass, propertyName);
    if (getter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName);
    }
    Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapJsonObject.class);
    boolean jsonObject = ldapJsonObject != null;
    AttributeData attribute = getAttribute(propertyName, ldapAttributeName, getter, entry, jsonObject);
    return attribute;
}
Also used : Getter(org.gluu.persist.reflect.property.Getter) LdapAttribute(org.gluu.site.ldap.persistence.annotation.LdapAttribute) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException)

Example 2 with Getter

use of org.gluu.persist.reflect.property.Getter in project oxCore by GluuFederation.

the class BaseEntryManager method getCustomObjectClasses.

protected String[] getCustomObjectClasses(Object entry, Class<?> entryClass) {
    List<String> result = new ArrayList<String>();
    List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
    for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
        String propertyName = propertiesAnnotation.getPropertyName();
        Getter getter = getGetter(entryClass, propertyName);
        if (getter == null) {
            throw new MappingException("Entry should has getter for property " + propertyName);
        }
        AttributeData attribute = getAttribute(propertyName, propertyName, getter, entry, false);
        if (attribute != null) {
            for (String objectClass : attribute.getValues()) {
                if (objectClass != null) {
                    result.add(objectClass);
                }
            }
        }
        break;
    }
    return result.toArray(new String[0]);
}
Also used : Getter(org.gluu.persist.reflect.property.Getter) ArrayList(java.util.ArrayList) AttributeData(org.gluu.persist.model.AttributeData) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) MappingException(org.gluu.persist.exception.mapping.MappingException)

Example 3 with Getter

use of org.gluu.persist.reflect.property.Getter in project oxCore by GluuFederation.

the class BaseEntryManager method getAttributesFromLdapAttributesList.

private List<AttributeData> getAttributesFromLdapAttributesList(Object entry, Annotation ldapAttribute, String propertyName) {
    Class<?> entryClass = entry.getClass();
    List<AttributeData> listAttributes = new ArrayList<AttributeData>();
    Getter getter = getGetter(entryClass, propertyName);
    if (getter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName);
    }
    Object propertyValue = getter.get(entry);
    if (propertyValue == null) {
        return null;
    }
    if (!(propertyValue instanceof List<?>)) {
        throw new MappingException("Entry property should has List base type");
    }
    Class<?> elementType = ReflectHelper.getListType(getter);
    String entryPropertyName = ((LdapAttributesList) ldapAttribute).name();
    Getter entryPropertyNameGetter = getGetter(elementType, entryPropertyName);
    if (entryPropertyNameGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyName);
    }
    String entryPropertyValue = ((LdapAttributesList) ldapAttribute).value();
    Getter entryPropertyValueGetter = getGetter(elementType, entryPropertyValue);
    if (entryPropertyValueGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyValue);
    }
    for (Object entryAttribute : (List<?>) propertyValue) {
        AttributeData attribute = getAttribute(propertyName, entryPropertyNameGetter, entryPropertyValueGetter, entryAttribute, false);
        if (attribute != null) {
            listAttributes.add(attribute);
        }
    }
    return listAttributes;
}
Also used : Getter(org.gluu.persist.reflect.property.Getter) ArrayList(java.util.ArrayList) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) LdapAttributesList(org.gluu.site.ldap.persistence.annotation.LdapAttributesList) ArrayList(java.util.ArrayList) List(java.util.List) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException) LdapAttributesList(org.gluu.site.ldap.persistence.annotation.LdapAttributesList)

Example 4 with Getter

use of org.gluu.persist.reflect.property.Getter in project oxCore by GluuFederation.

the class BaseEntryManager method getDNValue.

protected <T> Object getDNValue(Object entry, Class<T> entryClass) {
    // Check if entry has DN property
    String dnProperty = getDNPropertyName(entryClass);
    // Get DN value
    Getter dnGetter = getGetter(entryClass, dnProperty);
    if (dnGetter == null) {
        throw new MappingException("Entry should has getter for property " + dnProperty);
    }
    Object dnValue = dnGetter.get(entry);
    if (StringHelper.isEmptyString(dnValue)) {
        throw new MappingException("Entry should has not null base DN property value");
    }
    return dnValue;
}
Also used : Getter(org.gluu.persist.reflect.property.Getter) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) MappingException(org.gluu.persist.exception.mapping.MappingException)

Example 5 with Getter

use of org.gluu.persist.reflect.property.Getter in project oxCore by GluuFederation.

the class BaseEntryManager method getGetter.

protected <T> Getter getGetter(Class<T> entryClass, String propertyName) {
    String key = entryClass.getName() + "." + propertyName;
    Getter getter = classGetters.get(key);
    if (getter == null) {
        synchronized (CLASS_GETTERS_LOCK) {
            getter = classGetters.get(key);
            if (getter == null) {
                getter = ReflectHelper.getGetter(entryClass, propertyName);
                classGetters.put(key, getter);
            }
        }
    }
    return getter;
}
Also used : Getter(org.gluu.persist.reflect.property.Getter)

Aggregations

Getter (org.gluu.persist.reflect.property.Getter)5 MappingException (org.gluu.persist.exception.mapping.MappingException)4 AttributeData (org.gluu.persist.model.AttributeData)3 ArrayList (java.util.ArrayList)2 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)2 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)2 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)1 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)1