Search in sources :

Example 1 with Getter

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

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(io.jans.orm.reflect.property.Getter)

Example 2 with Getter

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

the class BaseEntryManager method getAttributeDataFromAttribute.

private AttributeData getAttributeDataFromAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
    Class<?> entryClass = entry.getClass();
    String ldapAttributeName = ((AttributeName) 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);
    }
    Class<?> parameterType = getSetterPropertyType(entryClass, propertyName);
    boolean multiValued = isMultiValued(parameterType);
    Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), JsonObject.class);
    boolean jsonObject = ldapJsonObject != null;
    AttributeData attribute = getAttributeData(propertyName, ldapAttributeName, getter, entry, multiValued, jsonObject);
    return attribute;
}
Also used : Getter(io.jans.orm.reflect.property.Getter) AttributeName(io.jans.orm.annotation.AttributeName) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException)

Example 3 with Getter

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

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);
        }
        Class<?> parameterType = getSetterPropertyType(entryClass, propertyName);
        boolean multiValued = isMultiValued(parameterType);
        AttributeData attribute = getAttributeData(propertyName, propertyName, getter, entry, multiValued, false);
        if (attribute != null) {
            for (String objectClass : attribute.getStringValues()) {
                if (objectClass != null) {
                    result.add(objectClass);
                }
            }
        }
        break;
    }
    return result.toArray(new String[0]);
}
Also used : Getter(io.jans.orm.reflect.property.Getter) ArrayList(java.util.ArrayList) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Example 4 with Getter

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

the class BaseEntryManager method getExpirationValue.

protected <T> Integer getExpirationValue(Object entry, Class<T> entryClass, boolean merge) {
    // Check if entry has Expiration property
    PropertyAnnotation expirationProperty = getExpirationProperty(entryClass);
    if (expirationProperty == null) {
        return null;
    }
    String expirationPropertyName = expirationProperty.getPropertyName();
    Expiration expirationAnnotation = (Expiration) ReflectHelper.getAnnotationByType(expirationProperty.getAnnotations(), Expiration.class);
    if (merge && expirationAnnotation.ignoreDuringUpdate()) {
        return null;
    }
    if (expirationPropertyName == null) {
        // No entry expiration property
        return null;
    }
    // Get Expiration value
    Getter expirationGetter = getGetter(entryClass, expirationPropertyName);
    if (expirationGetter == null) {
        throw new MappingException("Entry should has getter for property " + expirationGetter);
    }
    Class<?> propertyType = expirationGetter.getReturnType();
    if (!((propertyType == Integer.class) || (propertyType == Integer.TYPE))) {
        throw new MappingException("Entry expiration property should has Integer type. Property: '" + expirationGetter + "'");
    }
    Object expirationValue = expirationGetter.get(entry);
    if (expirationValue == null) {
        // No entry expiration or null
        return null;
    }
    Integer resultExpirationValue;
    if (expirationValue instanceof Integer) {
        resultExpirationValue = (Integer) expirationValue;
    } else {
        resultExpirationValue = Integer.valueOf((int) expirationValue);
    }
    // TTL can't be negative
    if (resultExpirationValue < 0) {
        resultExpirationValue = 0;
    }
    return resultExpirationValue;
}
Also used : Getter(io.jans.orm.reflect.property.Getter) Expiration(io.jans.orm.annotation.Expiration) JsonObject(io.jans.orm.annotation.JsonObject) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Example 5 with Getter

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

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(io.jans.orm.reflect.property.Getter) JsonObject(io.jans.orm.annotation.JsonObject) 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