Search in sources :

Example 31 with MappingException

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

the class BaseEntryManager method findEntries.

@Override
@SuppressWarnings("unchecked")
public <T> List<T> findEntries(Object entry, int count) {
    if (entry == null) {
        throw new MappingException("Entry to find is null");
    }
    // Check entry class
    Class<T> entryClass = (Class<T>) entry.getClass();
    checkEntryClass(entryClass, false);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    Filter searchFilter = createFilterByEntry(entry, entryClass, attributes);
    return findEntries(dnValue.toString(), entryClass, searchFilter, SearchScope.SUB, null, 0, count, DEFAULT_PAGINATION_SIZE);
}
Also used : Filter(io.jans.orm.search.filter.Filter) CustomObjectClass(io.jans.orm.annotation.CustomObjectClass) ObjectClass(io.jans.orm.annotation.ObjectClass) 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 32 with MappingException

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

the class BaseEntryManager method getHashCode.

@Override
public int getHashCode(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);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    String key = getEntryKey(dnValue, false, propertiesAnnotations, attributes);
    if (LOG.isDebugEnabled()) {
        LOG.debug(String.format("Entry key HashCode is: %s", key.hashCode()));
    }
    return key.hashCode();
}
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 33 with MappingException

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

Example 34 with MappingException

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

Example 35 with MappingException

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

the class BaseEntryManager method getSetterPropertyType.

private <T> Class<?> getSetterPropertyType(Class<T> entry, String propertyName) {
    Setter propertyValueSetter = getSetter(entry, propertyName);
    if (propertyValueSetter == null) {
        throw new MappingException("Entry should has setter for property " + propertyName);
    }
    Class<?> parameterType = ReflectHelper.getSetterType(propertyValueSetter);
    return parameterType;
}
Also used : Setter(io.jans.orm.reflect.property.Setter) 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