Search in sources :

Example 11 with EntryData

use of io.jans.orm.model.EntryData in project jans by JanssenProject.

the class SpannerOperationServiceImpl method getEntryDataList.

private List<EntryData> getEntryDataList(String objectClass, ResultSet resultSet) throws EntryConvertationException {
    List<EntryData> entryDataList = new LinkedList<>();
    List<AttributeData> attributeDataList = null;
    do {
        attributeDataList = getAttributeDataList(objectClass, resultSet, false);
        if (attributeDataList != null) {
            EntryData entryData = new EntryData(attributeDataList);
            entryDataList.add(entryData);
        }
    } while (attributeDataList != null);
    return entryDataList;
}
Also used : EntryData(io.jans.orm.model.EntryData) LinkedList(java.util.LinkedList) AttributeData(io.jans.orm.model.AttributeData)

Example 12 with EntryData

use of io.jans.orm.model.EntryData in project jans by JanssenProject.

the class SpannerOperationServiceImpl method search.

@Override
public <O> PagedResult<EntryData> search(String key, String objectClass, ConvertedExpression expression, SearchScope scope, String[] attributes, Sort[] orderBy, SpannerBatchOperationWraper<O> batchOperationWraper, SearchReturnDataType returnDataType, int start, int count, int pageSize) throws SearchException {
    Instant startTime = OperationDurationUtil.instance().now();
    TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
    PagedResult<EntryData> result = searchImpl(tableMapping, key, expression, scope, attributes, orderBy, batchOperationWraper, returnDataType, start, count, pageSize);
    Duration duration = OperationDurationUtil.instance().duration(startTime);
    OperationDurationUtil.instance().logDebug("SQL operation: search, duration: {}, table: {}, key: {}, expression: {}, scope: {}, attributes: {}, orderBy: {}, batchOperationWraper: {}, returnDataType: {}, start: {}, count: {}, pageSize: {}", duration, tableMapping.getTableName(), key, expression, scope, attributes, orderBy, batchOperationWraper, returnDataType, start, count, pageSize);
    return result;
}
Also used : EntryData(io.jans.orm.model.EntryData) Instant(java.time.Instant) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) Duration(java.time.Duration)

Example 13 with EntryData

use of io.jans.orm.model.EntryData in project jans by JanssenProject.

the class SqlEntryManager 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 = toSqlFilter(searchFilter, propertiesAnnotationsMap);
    } catch (SearchException ex) {
        throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
    }
    PagedResult<EntryData> searchResult;
    try {
        searchResult = searchImpl(toSQLKey(baseDN).getKey(), objectClasses[0], convertedExpression, 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 : 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) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Filter(io.jans.orm.search.filter.Filter) ConvertedExpression(io.jans.orm.sql.model.ConvertedExpression)

Example 14 with EntryData

use of io.jans.orm.model.EntryData 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)

Example 15 with EntryData

use of io.jans.orm.model.EntryData in project jans by JanssenProject.

the class SqlEntryManager method createEntities.

protected <T> List<T> createEntities(String baseDN, Class<T> entryClass, PagedResult<EntryData> searchResult) {
    ParsedKey keyWithInum = toSQLKey(baseDN);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    List<T> entries = createEntities(entryClass, propertiesAnnotations, keyWithInum, searchResult.getEntries().toArray(new EntryData[searchResult.getEntriesCount()]));
    return entries;
}
Also used : EntryData(io.jans.orm.model.EntryData) ParsedKey(io.jans.orm.impl.model.ParsedKey) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Aggregations

EntryData (io.jans.orm.model.EntryData)16 MappingException (io.jans.orm.exception.MappingException)8 SearchException (io.jans.orm.exception.operation.SearchException)8 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)8 AuthenticationException (io.jans.orm.exception.AuthenticationException)6 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)6 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)6 Filter (io.jans.orm.search.filter.Filter)6 LinkedList (java.util.LinkedList)6 ParsedKey (io.jans.orm.impl.model.ParsedKey)4 AttributeData (io.jans.orm.model.AttributeData)4 ConvertedExpression (io.jans.orm.cloud.spanner.model.ConvertedExpression)3 ConvertedExpression (io.jans.orm.sql.model.ConvertedExpression)3 DateTimeParseException (java.time.format.DateTimeParseException)3 EntryConvertationException (io.jans.orm.exception.operation.EntryConvertationException)2 PagedResult (io.jans.orm.model.PagedResult)2 Duration (java.time.Duration)2 Instant (java.time.Instant)2 ArrayList (java.util.ArrayList)2 LinkedHashMap (java.util.LinkedHashMap)2