Search in sources :

Example 26 with PropertyAnnotation

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

the class LdapEntryManager method remove.

@Override
public <T> int remove(String baseDN, Class<T> entryClass, Filter filter, int count) {
    if (StringHelper.isEmptyString(baseDN)) {
        throw new MappingException("Base DN to find entries is null");
    }
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    // Find entries
    Filter searchFilter;
    if (objectClasses.length > 0) {
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    DeleteBatchOperation batchOperation = new DeleteBatchOperation<T>(this);
    SearchResult searchResult = null;
    try {
        LdapBatchOperationWraper<T> batchOperationWraper = new LdapBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), batchOperationWraper, 0, 100, count, null, LdapOperationService.DN);
    } catch (Exception ex) {
        throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
    }
    if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
        throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter));
    }
    return batchOperation.getCountEntries();
}
Also used : SearchResult(com.unboundid.ldap.sdk.SearchResult) 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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) EntryDeleteException(io.jans.orm.exception.EntryDeleteException)

Example 27 with PropertyAnnotation

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

the class LdapEntryManager method findPagedEntries.

@Override
public <T> PagedResult<T> findPagedEntries(String baseDN, Class<T> entryClass, Filter filter, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, int start, int count, int chunkSize) {
    if (StringHelper.isEmptyString(baseDN)) {
        throw new MappingException("Base DN to find entries is null");
    }
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    String[] currentLdapReturnAttributes = ldapReturnAttributes;
    if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
        currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
    }
    // Find entries
    Filter searchFilter;
    if (objectClasses.length > 0) {
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    List<SearchResultEntry> searchResultEntries;
    PagedResult<T> vlvResponse = new PagedResult<T>();
    try {
        searchResultEntries = getOperationService().searchSearchResultEntryList(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, chunkSize, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
    }
    List<T> entries = new ArrayList<T>(0);
    if (searchResultEntries.size() > 0) {
        entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResultEntries.toArray(new SearchResultEntry[] {}));
    }
    vlvResponse.setEntries(entries);
    return vlvResponse;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) 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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) PagedResult(io.jans.orm.model.PagedResult) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 28 with PropertyAnnotation

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

the class BaseEntryManager method preparePropertyAnnotationTypes.

protected <T> void preparePropertyAnnotationTypes(Class<T> entry, Map<String, PropertyAnnotation> propertiesAnnotationsMap) {
    for (PropertyAnnotation propertiesAnnotation : propertiesAnnotationsMap.values()) {
        String propertyName = propertiesAnnotation.getPropertyName();
        Class<?> parameterType = getSetterPropertyType(entry, propertyName);
        propertiesAnnotation.setParameterType(parameterType);
    }
}
Also used : PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 29 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation 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 30 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation 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

PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)42 MappingException (io.jans.orm.exception.MappingException)28 Filter (io.jans.orm.search.filter.Filter)19 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)18 AuthenticationException (io.jans.orm.exception.AuthenticationException)17 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)17 SearchException (io.jans.orm.exception.operation.SearchException)17 AttributeData (io.jans.orm.model.AttributeData)14 ParsedKey (io.jans.orm.impl.model.ParsedKey)9 DateTimeParseException (java.time.format.DateTimeParseException)9 ArrayList (java.util.ArrayList)9 AttributeName (io.jans.orm.annotation.AttributeName)8 JsonObject (io.jans.orm.annotation.JsonObject)8 EntryData (io.jans.orm.model.EntryData)8 Annotation (java.lang.annotation.Annotation)6 JsonObject (com.couchbase.client.java.document.json.JsonObject)5 AttributesList (io.jans.orm.annotation.AttributesList)5 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)5 DateTimeException (java.time.DateTimeException)5 ConvertedExpression (io.jans.orm.cloud.spanner.model.ConvertedExpression)4