Search in sources :

Example 41 with MappingException

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

the class SpannerConnectionProvider method getTableMappingByKey.

public TableMapping getTableMappingByKey(String key, String objectClass, String tableName) {
    Map<String, StructField> columTypes = tableColumnsMap.get(tableName);
    if (!tableColumnsMap.containsKey(tableName)) {
        throw new MappingException(String.format("Table '%s' metadata is not exists '", tableName));
    }
    if ("_".equals(key)) {
        return new TableMapping("", tableName, objectClass, columTypes);
    }
    String[] baseNameParts = key.split("_");
    if (ArrayHelper.isEmpty(baseNameParts)) {
        throw new KeyConversionException("Failed to determine base key part!");
    }
    TableMapping tableMapping = new TableMapping(baseNameParts[0], tableName, objectClass, columTypes);
    return tableMapping;
}
Also used : StructField(com.google.cloud.spanner.Type.StructField) KeyConversionException(io.jans.orm.exception.KeyConversionException) TableMapping(io.jans.orm.cloud.spanner.model.TableMapping) MappingException(io.jans.orm.exception.MappingException)

Example 42 with MappingException

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

use of io.jans.orm.exception.MappingException 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

MappingException (io.jans.orm.exception.MappingException)43 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)27 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)19 SearchException (io.jans.orm.exception.operation.SearchException)18 AuthenticationException (io.jans.orm.exception.AuthenticationException)16 Filter (io.jans.orm.search.filter.Filter)16 AttributeData (io.jans.orm.model.AttributeData)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)14 JsonObject (io.jans.orm.annotation.JsonObject)12 ArrayList (java.util.ArrayList)11 SearchScopeException (io.jans.orm.exception.operation.SearchScopeException)7 Annotation (java.lang.annotation.Annotation)7 SearchResult (com.unboundid.ldap.sdk.SearchResult)6 ConnectionException (io.jans.orm.exception.operation.ConnectionException)6 EntryData (io.jans.orm.model.EntryData)6 DateTimeParseException (java.time.format.DateTimeParseException)6 List (java.util.List)6 Getter (io.jans.orm.reflect.property.Getter)5 ParseException (java.text.ParseException)5 DataEntry (io.jans.orm.annotation.DataEntry)4