Search in sources :

Example 36 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class LdapEntryManager method createEntities.

protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
    List<T> result = new ArrayList<T>(searchResultEntries.length);
    Map<String, List<AttributeData>> entriesAttributes = new HashMap<String, List<AttributeData>>(100);
    int count = 0;
    for (int i = 0; i < searchResultEntries.length; i++) {
        count++;
        SearchResultEntry entry = searchResultEntries[i];
        entriesAttributes.put(entry.getDN(), getAttributeDataList(entry));
        // Remove reference to allow java clean up object
        searchResultEntries[i] = null;
        // Allow java to clean up temporary objects
        if (count >= 100) {
            List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
            result.addAll(currentResult);
            entriesAttributes = new HashMap<String, List<AttributeData>>(100);
            count = 0;
        }
    }
    List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
    result.addAll(currentResult);
    return result;
}
Also used : HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) AttributeData(io.jans.orm.model.AttributeData) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 37 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class LdapEntryManager method find.

@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
    try {
        // Load entry
        SearchResultEntry entry = getOperationService().lookup(dn, ldapReturnAttributes);
        List<AttributeData> result = getAttributeDataList(entry);
        if (result != null) {
            return result;
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
    }
    throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
Also used : EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) ParseException(java.text.ParseException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchScopeException(io.jans.orm.exception.operation.SearchScopeException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) ConnectionException(io.jans.orm.exception.operation.ConnectionException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 38 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class LdapEntryManager method persist.

@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
    List<Attribute> ldapAttributes = new ArrayList<Attribute>(attributes.size());
    for (AttributeData attribute : attributes) {
        String attributeName = attribute.getName();
        String[] attributeValues = attribute.getStringValues();
        if (ArrayHelper.isNotEmpty(attributeValues) && StringHelper.isNotEmpty(attributeValues[0])) {
            if (getOperationService().isCertificateAttribute(attributeName)) {
                byte[][] binaryValues = toBinaryValues(attributeValues);
                ldapAttributes.add(new Attribute(attributeName + ";binary", binaryValues));
            } else {
                ldapAttributes.add(new Attribute(attributeName, attributeValues));
            }
        }
    }
    // Persist entry
    try {
        boolean result = getOperationService().addEntry(dn, ldapAttributes);
        if (!result) {
            throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn));
        }
    } catch (ConnectionException ex) {
        throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex.getCause());
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex);
    }
}
Also used : Attribute(com.unboundid.ldap.sdk.Attribute) ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) ConnectionException(io.jans.orm.exception.operation.ConnectionException) MappingException(io.jans.orm.exception.MappingException) ParseException(java.text.ParseException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchScopeException(io.jans.orm.exception.operation.SearchScopeException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) ConnectionException(io.jans.orm.exception.operation.ConnectionException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException)

Example 39 with AttributeData

use of io.jans.orm.model.AttributeData 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 40 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class BaseEntryManager method getAttributesMap.

protected <T> Map<String, PropertyAnnotation> getAttributesMap(T entry, List<PropertyAnnotation> propertiesAnnotations, boolean isIgnoreAttributesList) {
    Map<String, PropertyAnnotation> attributes = new HashMap<String, PropertyAnnotation>();
    for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
        String propertyName = propertiesAnnotation.getPropertyName();
        Annotation ldapAttribute;
        if (!isIgnoreAttributesList) {
            ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), AttributesList.class);
            if (ldapAttribute != null) {
                if (entry == null) {
                    return null;
                } else {
                    List<AttributeData> attributesList = getAttributesFromAttributesList(entry, ldapAttribute, propertyName);
                    for (AttributeData attributeData : attributesList) {
                        String ldapAttributeName = attributeData.getName();
                        if (!attributes.containsKey(ldapAttributeName)) {
                            attributes.put(ldapAttributeName, propertiesAnnotation);
                        }
                    }
                }
            }
        }
        // Process properties with AttributeName annotation
        ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), AttributeName.class);
        if (ldapAttribute != null) {
            String ldapAttributeName = ((AttributeName) ldapAttribute).name();
            if (StringHelper.isEmpty(ldapAttributeName)) {
                ldapAttributeName = propertyName;
            }
            if (!attributes.containsKey(ldapAttributeName)) {
                attributes.put(ldapAttributeName, propertiesAnnotation);
            }
        }
    }
    if (attributes.size() == 0) {
        return null;
    }
    return attributes;
}
Also used : AttributesList(io.jans.orm.annotation.AttributesList) HashMap(java.util.HashMap) IdentityHashMap(java.util.IdentityHashMap) AttributeName(io.jans.orm.annotation.AttributeName) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Aggregations

AttributeData (io.jans.orm.model.AttributeData)62 MappingException (io.jans.orm.exception.MappingException)29 ArrayList (java.util.ArrayList)23 SearchException (io.jans.orm.exception.operation.SearchException)22 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)17 AuthenticationException (io.jans.orm.exception.AuthenticationException)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)14 AttributeDataModification (io.jans.orm.model.AttributeDataModification)13 JsonObject (io.jans.orm.annotation.JsonObject)10 LinkedList (java.util.LinkedList)10 DateTimeParseException (java.time.format.DateTimeParseException)8 List (java.util.List)8 ParsedKey (io.jans.orm.impl.model.ParsedKey)7 JsonObject (com.couchbase.client.java.document.json.JsonObject)6 AttributeName (io.jans.orm.annotation.AttributeName)6 PersistenceException (io.jans.orm.exception.operation.PersistenceException)6 Annotation (java.lang.annotation.Annotation)6 AttributeModificationType (io.jans.orm.model.AttributeDataModification.AttributeModificationType)5 LinkedHashMap (java.util.LinkedHashMap)5