Search in sources :

Example 11 with ParsedKey

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

the class SqlEntryManager method find.

@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
    try {
        // Load entry
        ParsedKey keyWithInum = toSQLKey(dn);
        List<AttributeData> result = getOperationService().lookup(keyWithInum.getKey(), objectClasses[0], toInternalAttributes(ldapReturnAttributes));
        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) 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)

Example 12 with ParsedKey

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

the class SqlEntryManager method persist.

@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
    ArrayList<AttributeData> resultAttributes = new ArrayList<>(attributes.size() + 1);
    for (AttributeData attribute : attributes) {
        String attributeName = attribute.getName();
        Object[] attributeValues = attribute.getValues();
        Boolean multiValued = attribute.getMultiValued();
        if (ArrayHelper.isNotEmpty(attributeValues) && (attributeValues[0] != null)) {
            Object[] realValues = attributeValues;
            // We need to store only one objectClass value in SQL
            if (StringHelper.equalsIgnoreCase(SqlOperationService.OBJECT_CLASS, attributeName)) {
                if (!ArrayHelper.isEmpty(realValues)) {
                    realValues = new Object[] { realValues[0] };
                    multiValued = false;
                }
            }
            // Process userPassword
            if (StringHelper.equalsIgnoreCase(SqlOperationService.USER_PASSWORD, attributeName)) {
                realValues = getOperationService().createStoragePassword(StringHelper.toStringArray(attributeValues));
            }
            escapeValues(realValues);
            AttributeData resultAttributeData;
            if (Boolean.TRUE.equals(multiValued)) {
                resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues, multiValued);
            } else {
                resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues[0]);
            }
            resultAttributes.add(resultAttributeData);
        }
    }
    // Persist entry
    try {
        ParsedKey parsedKey = toSQLKey(dn);
        resultAttributes.add(new AttributeData(SqlOperationService.DN, dn));
        resultAttributes.add(new AttributeData(SqlOperationService.DOC_ID, parsedKey.getKey()));
        boolean result = getOperationService().addEntry(parsedKey.getKey(), objectClasses[0], resultAttributes);
        if (!result) {
            throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn));
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn), ex);
    }
}
Also used : ArrayList(java.util.ArrayList) 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)

Example 13 with ParsedKey

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

the class CouchbaseEntryManager method findEntriesImpl.

protected <T> PagedResult<JsonObject> 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
    Sort[] defaultSort = getDefaultSort(entryClass);
    if (StringHelper.isNotEmpty(sortBy)) {
        Sort requestedSort = buildSort(sortBy, sortOrder);
        if (ArrayHelper.isEmpty(defaultSort)) {
            defaultSort = new Sort[] { requestedSort };
        } else {
            defaultSort = ArrayHelper.arrayMerge(new Sort[] { requestedSort }, defaultSort);
        }
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    ParsedKey keyWithInum = toCouchbaseKey(baseDN);
    ConvertedExpression convertedExpression;
    try {
        convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
    }
    PagedResult<JsonObject> searchResult = null;
    try {
        CouchbaseBatchOperationWraper<T> batchOperationWraper = null;
        if (batchOperation != null) {
            batchOperationWraper = new CouchbaseBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
        }
        searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), 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 (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
    }
}
Also used : SearchException(io.jans.orm.exception.operation.SearchException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) 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) ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression) ParsedKey(io.jans.orm.impl.model.ParsedKey) Sort(com.couchbase.client.java.query.dsl.Sort)

Example 14 with ParsedKey

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

the class SpannerEntryManager method find.

@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
    try {
        // Load entry
        ParsedKey keyWithInum = toSQLKey(dn);
        List<AttributeData> result = getOperationService().lookup(keyWithInum.getKey(), objectClasses[0], toInternalAttributes(ldapReturnAttributes));
        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) 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) AuthenticationException(io.jans.orm.exception.AuthenticationException)

Example 15 with ParsedKey

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

the class SqlEntryManager method contains.

@Override
protected <T> boolean contains(String baseDN, String[] objectClasses, Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, Filter filter, String[] ldapReturnAttributes) {
    if (StringHelper.isEmptyString(baseDN)) {
        throw new MappingException("Base DN to check contain entries is null");
    }
    // Create filter
    Filter searchFilter;
    if (objectClasses.length > 0) {
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    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 {
        ParsedKey keyWithInum = toSQLKey(baseDN);
        searchResult = searchImpl(keyWithInum.getKey(), objectClasses[0], convertedExpression, SearchScope.SUB, ldapReturnAttributes, null, null, SearchReturnDataType.SEARCH, 0, 1, 0);
        if (searchResult == null) {
            throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: '%s', filter: '%s'", baseDN, searchFilter));
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: '%s', filter: '%s'", baseDN, searchFilter), ex);
    }
    return (searchResult != null) && (searchResult.getEntriesCount() > 0);
}
Also used : EntryData(io.jans.orm.model.EntryData) 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) 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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

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