Search in sources :

Example 1 with EntryDeleteException

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

the class SpannerEntryManager method removeImpl.

protected <T> int removeImpl(String dn, Class<T> entryClass, Filter filter, int count) {
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    Filter searchFilter;
    if (objectClasses.length > 0) {
        LOG.trace("Filter: {}", filter);
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        throw new EntryDeleteException(String.format("Failed to delete entries with DN: '%s', filter: '%s' because objectClass is not specified", dn, filter));
    }
    // Find entries
    LOG.trace("-------------------------------------------------------");
    LOG.trace("Filter: {}", filter);
    LOG.trace("objectClasses count: {} ", objectClasses.length);
    LOG.trace("objectClasses: {}", objectClasses.toString());
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare properties types to allow build filter properly
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    String key = toSQLKey(dn).getKey();
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toSqlFilterWithEmptyAlias(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryDeleteException(String.format("Failed to convert filter '%s' to expression", searchFilter));
    }
    try {
        int processed = (int) getOperationService().delete(key, objectClasses[0], convertedExpression, count);
        return processed;
    } catch (Exception ex) {
        throw new EntryDeleteException(String.format("Failed to delete entries with key: '%s', expression: '%s'", key, convertedExpression), ex);
    }
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.cloud.spanner.model.ConvertedExpression) SearchException(io.jans.orm.exception.operation.SearchException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) MappingException(io.jans.orm.exception.MappingException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 2 with EntryDeleteException

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

the class CouchbaseEntryManager method removeImpl.

protected <T> int removeImpl(String dn, Class<T> entryClass, Filter filter, int count) {
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    Filter searchFilter;
    if (objectClasses.length > 0) {
        LOG.trace("Filter: {}", filter);
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    // Find entries
    LOG.trace("-------------------------------------------------------");
    LOG.trace("Filter: {}", filter);
    LOG.trace("objectClasses count: {} ", objectClasses.length);
    LOG.trace("objectClasses: {}", objectClasses.toString());
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare properties types to allow build filter properly
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toCouchbaseKey(dn);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryDeleteException(String.format("Failed to convert filter %s to expression", searchFilter), ex);
    }
    try {
        int processed = getOperationService().delete(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), count);
        return processed;
    } catch (Exception ex) {
        throw new EntryDeleteException(String.format("Failed to delete entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) SearchException(io.jans.orm.exception.operation.SearchException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) MappingException(io.jans.orm.exception.MappingException) DateTimeException(java.time.DateTimeException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) DateTimeParseException(java.time.format.DateTimeParseException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchException(io.jans.orm.exception.operation.SearchException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 3 with EntryDeleteException

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

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

the class LdapEntryManager method removeSubtreeThroughIteration.

private void removeSubtreeThroughIteration(String dn) {
    SearchScope scope = SearchScope.SUB;
    SearchResult searchResult = null;
    try {
        searchResult = getOperationService().search(dn, toLdapFilter(Filter.createPresenceFilter("objectClass")), toLdapSearchScope(scope), null, 0, 0, 0, null, "dn");
        if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
            throw new EntryPersistenceException(String.format("Failed to find sub-entries of entry '%s' for removal", dn));
        }
    } catch (SearchScopeException ex) {
        throw new AuthenticationException(String.format("Failed to convert scope: %s", scope), ex);
    } catch (SearchException ex) {
        throw new EntryDeleteException(String.format("Failed to find sub-entries of entry '%s' for removal", dn), ex);
    }
    List<String> removeEntriesDn = new ArrayList<String>(searchResult.getEntryCount());
    for (SearchResultEntry searchResultEntry : searchResult.getSearchEntries()) {
        removeEntriesDn.add(searchResultEntry.getDN());
    }
    Collections.sort(removeEntriesDn, LINE_LENGHT_COMPARATOR);
    for (String removeEntryDn : removeEntriesDn) {
        remove(removeEntryDn);
    }
}
Also used : AuthenticationException(io.jans.orm.exception.AuthenticationException) SearchScope(io.jans.orm.model.SearchScope) ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchException(io.jans.orm.exception.operation.SearchException) SearchResult(com.unboundid.ldap.sdk.SearchResult) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchScopeException(io.jans.orm.exception.operation.SearchScopeException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 5 with EntryDeleteException

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

the class SqlEntryManager method removeImpl.

protected <T> int removeImpl(String dn, Class<T> entryClass, Filter filter, int count) {
    // Check entry class
    checkEntryClass(entryClass, false);
    String[] objectClasses = getTypeObjectClasses(entryClass);
    Filter searchFilter;
    if (objectClasses.length > 0) {
        LOG.trace("Filter: {}", filter);
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        throw new EntryDeleteException(String.format("Failed to delete entries with DN: '%s', filter: '%s' because objectClass is not specified", dn, filter));
    }
    // Find entries
    LOG.trace("-------------------------------------------------------");
    LOG.trace("Filter: {}", filter);
    LOG.trace("objectClasses count: {} ", objectClasses.length);
    LOG.trace("objectClasses: {}", objectClasses.toString());
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare properties types to allow build filter properly
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toSQLKey(dn);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toSqlFilterWithEmptyAlias(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryDeleteException(String.format("Failed to convert filter '%s' to expression", searchFilter), ex);
    }
    try {
        int processed = (int) getOperationService().delete(keyWithInum.getKey(), objectClasses[0], convertedExpression, count);
        return processed;
    } catch (Exception ex) {
        throw new EntryDeleteException(String.format("Failed to delete entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) SearchException(io.jans.orm.exception.operation.SearchException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) MappingException(io.jans.orm.exception.MappingException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchException(io.jans.orm.exception.operation.SearchException) DateTimeParseException(java.time.format.DateTimeParseException) AuthenticationException(io.jans.orm.exception.AuthenticationException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Aggregations

AuthenticationException (io.jans.orm.exception.AuthenticationException)5 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)5 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)5 SearchException (io.jans.orm.exception.operation.SearchException)5 MappingException (io.jans.orm.exception.MappingException)4 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)4 Filter (io.jans.orm.search.filter.Filter)4 SearchResult (com.unboundid.ldap.sdk.SearchResult)2 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)2 ParsedKey (io.jans.orm.impl.model.ParsedKey)2 DateTimeParseException (java.time.format.DateTimeParseException)2 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 ConvertedExpression (io.jans.orm.cloud.spanner.model.ConvertedExpression)1 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)1 ConnectionException (io.jans.orm.exception.operation.ConnectionException)1 SearchScope (io.jans.orm.model.SearchScope)1 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)1 ParseException (java.text.ParseException)1 DateTimeException (java.time.DateTimeException)1 ArrayList (java.util.ArrayList)1