Search in sources :

Example 11 with EntryPersistenceException

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

the class CouchbaseEntryManager 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 = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
    }
    PagedResult<JsonObject> searchResult = null;
    try {
        ParsedKey keyWithInum = toCouchbaseKey(baseDN);
        searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), SearchScope.SUB, ldapReturnAttributes, null, null, SearchReturnDataType.SEARCH, 1, 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 : 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) 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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 12 with EntryPersistenceException

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

the class CouchbaseEntryManager method exportEntry.

@Override
public List<AttributeData> exportEntry(String dn) {
    try {
        // Load entry
        ParsedKey keyWithInum = toCouchbaseKey(dn);
        JsonObject entry = getOperationService().lookup(keyWithInum.getKey(), null);
        List<AttributeData> result = getAttributeDataList(entry);
        if (result != null) {
            return result;
        }
        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) 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 13 with EntryPersistenceException

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

the class CouchbaseEntryManager method persist.

@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
    JsonObject jsonObject = JsonObject.create();
    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 Couchbase
            if (StringHelper.equalsIgnoreCase(CouchbaseOperationService.OBJECT_CLASS, attributeName)) {
                if (!ArrayHelper.isEmpty(realValues)) {
                    realValues = new Object[] { realValues[0] };
                    multiValued = false;
                }
            }
            // Process userPassword
            if (StringHelper.equalsIgnoreCase(CouchbaseOperationService.USER_PASSWORD, attributeName)) {
                realValues = getOperationService().createStoragePassword(StringHelper.toStringArray(attributeValues));
            }
            escapeValues(realValues);
            if ((multiValued == null) || !multiValued) {
                jsonObject.put(toInternalAttribute(attributeName), realValues[0]);
            } else {
                jsonObject.put(toInternalAttribute(attributeName), JsonArray.from(realValues));
            }
        }
    }
    jsonObject.put(CouchbaseOperationService.DN, dn);
    // Persist entry
    try {
        boolean result = getOperationService().addEntry(toCouchbaseKey(dn).getKey(), jsonObject, expiration);
        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 : JsonObject(com.couchbase.client.java.document.json.JsonObject) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) 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 14 with EntryPersistenceException

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

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

the class CouchbaseEntryManager method countEntries.

@Override
public <T> int countEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope) {
    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;
    }
    // Prepare properties types to allow build filter properly
    Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
    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;
    try {
        searchResult = searchImpl(toCouchbaseKey(baseDN).getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), scope, null, null, null, SearchReturnDataType.COUNT, 0, 0, 0);
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
    }
    return searchResult.getTotalEntriesCount();
}
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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.couchbase.model.ConvertedExpression)

Aggregations

EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)61 SearchException (io.jans.orm.exception.operation.SearchException)33 AuthenticationException (io.jans.orm.exception.AuthenticationException)31 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)30 MappingException (io.jans.orm.exception.MappingException)30 Filter (io.jans.orm.search.filter.Filter)24 AttributeData (io.jans.orm.model.AttributeData)16 DateTimeParseException (java.time.format.DateTimeParseException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)13 ParsedKey (io.jans.orm.impl.model.ParsedKey)12 ArrayList (java.util.ArrayList)11 Date (java.util.Date)10 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)9 JsonObject (com.couchbase.client.java.document.json.JsonObject)8 ConnectionException (io.jans.orm.exception.operation.ConnectionException)8 ParseException (java.text.ParseException)8 DateTimeException (java.time.DateTimeException)7 List (java.util.List)7 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)6 EntryData (io.jans.orm.model.EntryData)6