Search in sources :

Example 6 with Getter

use of io.jans.orm.reflect.property.Getter in project jans by JanssenProject.

the class BaseEntryManager method getAttributesFromAttributesList.

private List<AttributeData> getAttributesFromAttributesList(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 = ((AttributesList) ldapAttribute).name();
    Getter entryPropertyNameGetter = getGetter(elementType, entryPropertyName);
    if (entryPropertyNameGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyName);
    }
    String entryPropertyValue = ((AttributesList) ldapAttribute).value();
    Getter entryPropertyValueGetter = getGetter(elementType, entryPropertyValue);
    if (entryPropertyValueGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyValue);
    }
    String entryPropertyMultivalued = ((AttributesList) ldapAttribute).multiValued();
    Getter entryPropertyMultivaluedGetter = null;
    if (StringHelper.isNotEmpty(entryPropertyMultivalued)) {
        entryPropertyMultivaluedGetter = getGetter(elementType, entryPropertyMultivalued);
    }
    if (entryPropertyMultivaluedGetter != null) {
        Class<?> propertyType = entryPropertyMultivaluedGetter.getReturnType();
        if (!propertyType.equals(Boolean.TYPE)) {
            throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyMultivalued + " with boolean type");
        }
    }
    for (Object entryAttribute : (List<?>) propertyValue) {
        Boolean multiValued = null;
        if (entryPropertyMultivaluedGetter != null) {
            multiValued = (boolean) entryPropertyMultivaluedGetter.get(entryAttribute);
        }
        AttributeData attribute = getAttributeData(propertyName, entryPropertyNameGetter, entryPropertyValueGetter, entryAttribute, Boolean.TRUE.equals(multiValued), false);
        if (attribute != null) {
            if (multiValued == null) {
                // Detect if attribute has more than one value
                multiValued = attribute.getValues().length > 1;
            }
            attribute.setMultiValued(multiValued);
            listAttributes.add(attribute);
        }
    }
    return listAttributes;
}
Also used : AttributesList(io.jans.orm.annotation.AttributesList) Getter(io.jans.orm.reflect.property.Getter) ArrayList(java.util.ArrayList) JsonObject(io.jans.orm.annotation.JsonObject) ArrayList(java.util.ArrayList) AttributesList(io.jans.orm.annotation.AttributesList) List(java.util.List) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException)

Aggregations

Getter (io.jans.orm.reflect.property.Getter)6 MappingException (io.jans.orm.exception.MappingException)5 JsonObject (io.jans.orm.annotation.JsonObject)3 AttributeData (io.jans.orm.model.AttributeData)3 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)3 ArrayList (java.util.ArrayList)2 AttributeName (io.jans.orm.annotation.AttributeName)1 AttributesList (io.jans.orm.annotation.AttributesList)1 Expiration (io.jans.orm.annotation.Expiration)1 Annotation (java.lang.annotation.Annotation)1 List (java.util.List)1