Search in sources :

Example 6 with ParsedKey

use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.

the class CouchbaseEntryManager method find.

@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
    try {
        // Load entry
        ParsedKey keyWithInum = toCouchbaseKey(dn);
        ScanConsistency scanConsistency = getScanConsistency(keyWithInum.getName(), propertiesAnnotationsMap);
        JsonObject entry = getOperationService().lookup(keyWithInum.getKey(), scanConsistency, toInternalAttributes(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 : ParsedKey(io.jans.orm.impl.model.ParsedKey) ScanConsistency(com.couchbase.client.java.query.consistency.ScanConsistency) JsonObject(com.couchbase.client.java.document.json.JsonObject) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) 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)

Example 7 with ParsedKey

use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.

the class CouchbaseEntryManager method createEntities.

protected <T> List<T> createEntities(String baseDN, Class<T> entryClass, PagedResult<JsonObject> searchResult) {
    ParsedKey keyWithInum = toCouchbaseKey(baseDN);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    List<T> entries = createEntities(entryClass, propertiesAnnotations, keyWithInum, searchResult.getEntries().toArray(new JsonObject[searchResult.getEntriesCount()]));
    return entries;
}
Also used : ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) ParsedKey(io.jans.orm.impl.model.ParsedKey) JsonObject(com.couchbase.client.java.document.json.JsonObject) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 8 with ParsedKey

use of io.jans.orm.impl.model.ParsedKey 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 9 with ParsedKey

use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.

the class SqlEntryManager method findEntriesImpl.

protected <T> PagedResult<EntryData> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
    // 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);
    }
    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: {}", ArrayHelper.toString(objectClasses));
    LOG.trace("Search filter: {}", searchFilter);
    // Prepare default sort
    OrderSpecifier<?>[] defaultSort = getDefaultSort(entryClass);
    if (StringHelper.isNotEmpty(sortBy)) {
        OrderSpecifier<?> requestedSort = buildSort(sortBy, sortOrder);
        if (ArrayHelper.isEmpty(defaultSort)) {
            defaultSort = new OrderSpecifier[] { requestedSort };
        } else {
            defaultSort = ArrayHelper.arrayMerge(new OrderSpecifier[] { requestedSort }, defaultSort);
        }
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toSQLKey(baseDN);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toSqlFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
    }
    PagedResult<EntryData> searchResult = null;
    try {
        SqlBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new SqlBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(keyWithInum.getKey(), objectClasses[0], convertedExpression, scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
        if (searchResult == null) {
            throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression));
        }
        return searchResult;
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", keyWithInum.getKey()), ex);
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : EntryData(io.jans.orm.model.EntryData) SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) 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) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) OrderSpecifier(com.querydsl.core.types.OrderSpecifier)

Example 10 with ParsedKey

use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.

the class SqlEntryManager method exportEntry.

@Override
public List<AttributeData> exportEntry(String dn, String objectClass) {
    if (StringHelper.isEmpty(objectClass)) {
        throw new MappingException("Object class isn't defined!");
    }
    try {
        // Load entry
        ParsedKey keyWithInum = toSQLKey(dn);
        List<AttributeData> entry = getOperationService().lookup(keyWithInum.getKey(), objectClass);
        if (entry != null) {
            return entry;
        }
        return null;
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entry: '%s'", dn), ex);
    }
}
Also used : ParsedKey(io.jans.orm.impl.model.ParsedKey) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) AttributeData(io.jans.orm.model.AttributeData) 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) MappingException(io.jans.orm.exception.MappingException)

Aggregations

ParsedKey (io.jans.orm.impl.model.ParsedKey)17 AuthenticationException (io.jans.orm.exception.AuthenticationException)14 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)14 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)14 MappingException (io.jans.orm.exception.MappingException)14 SearchException (io.jans.orm.exception.operation.SearchException)14 DateTimeParseException (java.time.format.DateTimeParseException)11 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)9 AttributeData (io.jans.orm.model.AttributeData)8 Filter (io.jans.orm.search.filter.Filter)6 JsonObject (com.couchbase.client.java.document.json.JsonObject)5 DateTimeException (java.time.DateTimeException)5 EntryData (io.jans.orm.model.EntryData)4 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)3 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)3 ISO_INSTANT (java.time.format.DateTimeFormatter.ISO_INSTANT)2 ArrayList (java.util.ArrayList)2 ScanConsistency (com.couchbase.client.java.query.consistency.ScanConsistency)1 Sort (com.couchbase.client.java.query.dsl.Sort)1 OrderSpecifier (com.querydsl.core.types.OrderSpecifier)1