Search in sources :

Example 16 with MappingException

use of io.jans.orm.exception.MappingException in project jans by JanssenProject.

the class BaseEntryManager method setCustomObjectClasses.

protected void setCustomObjectClasses(Object entry, Class<?> entryClass, String[] objectClasses) {
    List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
    for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
        String propertyName = propertiesAnnotation.getPropertyName();
        Setter setter = getSetter(entryClass, propertyName);
        if (setter == null) {
            throw new MappingException("Entry should has setter for property " + propertyName);
        }
        AttributeData attribute = new AttributeData(propertyName, objectClasses);
        setPropertyValue(propertyName, setter, entry, attribute, false);
        break;
    }
}
Also used : Setter(io.jans.orm.reflect.property.Setter) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Example 17 with MappingException

use of io.jans.orm.exception.MappingException in project jans by JanssenProject.

the class BaseEntryManager method persist.

@Override
public void persist(Object entry) {
    if (entry == null) {
        throw new MappingException("Entry to persist is null");
    }
    // Check entry class
    Class<?> entryClass = entry.getClass();
    checkEntryClass(entryClass, false);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    Integer expirationValue = getExpirationValue(entry, entryClass, false);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    // Add object classes
    String[] objectClasses = getObjectClasses(entry, entryClass);
    attributes.add(new AttributeData(OBJECT_CLASS, objectClasses, true));
    LOG.debug(String.format("LDAP attributes for persist: %s", attributes));
    persist(dnValue.toString(), objectClasses, attributes, expirationValue);
}
Also used : JsonObject(io.jans.orm.annotation.JsonObject) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 18 with MappingException

use of io.jans.orm.exception.MappingException 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 19 with MappingException

use of io.jans.orm.exception.MappingException in project jans by JanssenProject.

the class BaseEntryManager method checkEntryClass.

protected boolean checkEntryClass(Class<?> entryClass, boolean isAllowSchemaEntry) {
    if (entryClass == null) {
        throw new MappingException("Entry class is null");
    }
    // Check if entry is LDAP Entry
    List<Annotation> entryAnnotations = ReflectHelper.getClassAnnotations(entryClass, LDAP_ENTRY_TYPE_ANNOTATIONS);
    Annotation ldapSchemaEntry = ReflectHelper.getAnnotationByType(entryAnnotations, SchemaEntry.class);
    Annotation ldapEntry = ReflectHelper.getAnnotationByType(entryAnnotations, DataEntry.class);
    if (isAllowSchemaEntry) {
        if ((ldapSchemaEntry == null) && (ldapEntry == null)) {
            throw new MappingException(String.format("Entry should has DataEntry or SchemaEntry annotation", entryClass));
        }
    } else {
        if (ldapEntry == null) {
            throw new MappingException(String.format("Entry '%s' should has DataEntry annotation", entryClass));
        }
    }
    return true;
}
Also used : PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) MappingException(io.jans.orm.exception.MappingException)

Example 20 with MappingException

use of io.jans.orm.exception.MappingException 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)

Aggregations

MappingException (io.jans.orm.exception.MappingException)43 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)27 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)19 SearchException (io.jans.orm.exception.operation.SearchException)18 AuthenticationException (io.jans.orm.exception.AuthenticationException)16 Filter (io.jans.orm.search.filter.Filter)16 AttributeData (io.jans.orm.model.AttributeData)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)14 JsonObject (io.jans.orm.annotation.JsonObject)12 ArrayList (java.util.ArrayList)11 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)7 Annotation (java.lang.annotation.Annotation)7 SearchResult (com.unboundid.ldap.sdk.SearchResult)6 ConnectionException (io.jans.orm.exception.operation.ConnectionException)6 EntryData (io.jans.orm.model.EntryData)6 DateTimeParseException (java.time.format.DateTimeParseException)6 List (java.util.List)6 Getter (io.jans.orm.reflect.property.Getter)5 ParseException (java.text.ParseException)5 DataEntry (io.jans.orm.annotation.DataEntry)4