Search in sources :

Example 21 with MappingException

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

the class SqlOperationServiceImpl method convertDbJsonToValue.

private Object[] convertDbJsonToValue(String jsonValue) {
    try {
        // Object[] values = JSON_OBJECT_MAPPER.readValue(jsonValue, Object[].class);
        JsonAttributeValue attributeValue = JSON_OBJECT_MAPPER.readValue(jsonValue, JsonAttributeValue.class);
        Object[] values = null;
        if (attributeValue != null) {
            values = attributeValue.getValues();
        }
        return values;
    } catch (Exception ex) {
        LOG.error("Failed to convert json value '{}' to array:", jsonValue, ex);
        throw new MappingException(String.format("Failed to convert json value '%s' to array", jsonValue));
    }
}
Also used : JsonAttributeValue(io.jans.orm.sql.model.JsonAttributeValue) QueryException(com.querydsl.core.QueryException) DeleteException(io.jans.orm.exception.operation.DeleteException) MappingException(io.jans.orm.exception.MappingException) PersistenceException(io.jans.orm.exception.operation.PersistenceException) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SQLException(java.sql.SQLException) SearchException(io.jans.orm.exception.operation.SearchException) EntryNotFoundException(io.jans.orm.exception.operation.EntryNotFoundException) MappingException(io.jans.orm.exception.MappingException)

Example 22 with MappingException

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

the class SqlOperationServiceImpl method convertValueToDbJson.

private String convertValueToDbJson(Object propertyValue) {
    try {
        // String value = JSON_OBJECT_MAPPER.writeValueAsString(propertyValue);
        JsonAttributeValue attributeValue;
        if (propertyValue == null) {
            attributeValue = new JsonAttributeValue();
        }
        if (propertyValue instanceof List) {
            attributeValue = new JsonAttributeValue(((List) propertyValue).toArray());
        } else if (propertyValue.getClass().isArray()) {
            attributeValue = new JsonAttributeValue((Object[]) propertyValue);
        } else {
            attributeValue = new JsonAttributeValue(new Object[] { propertyValue });
        }
        String value = JSON_OBJECT_MAPPER.writeValueAsString(attributeValue);
        return value;
    } catch (Exception ex) {
        LOG.error("Failed to convert '{}' to json value:", propertyValue, ex);
        throw new MappingException(String.format("Failed to convert '%s' to json value", propertyValue));
    }
}
Also used : JsonAttributeValue(io.jans.orm.sql.model.JsonAttributeValue) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) QueryException(com.querydsl.core.QueryException) DeleteException(io.jans.orm.exception.operation.DeleteException) MappingException(io.jans.orm.exception.MappingException) PersistenceException(io.jans.orm.exception.operation.PersistenceException) EntryConvertationException(io.jans.orm.exception.operation.EntryConvertationException) DuplicateEntryException(io.jans.orm.exception.operation.DuplicateEntryException) SQLException(java.sql.SQLException) SearchException(io.jans.orm.exception.operation.SearchException) EntryNotFoundException(io.jans.orm.exception.operation.EntryNotFoundException) MappingException(io.jans.orm.exception.MappingException)

Example 23 with MappingException

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

the class SqlEntryManager method createEntities.

protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, ParsedKey baseDn, EntryData... searchResultEntries) {
    List<T> result = new ArrayList<T>(searchResultEntries.length);
    Map<String, List<AttributeData>> entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
    int count = 0;
    for (int i = 0; i < searchResultEntries.length; i++) {
        count++;
        EntryData entryData = searchResultEntries[i];
        AttributeData attributeDataDn = entryData.getAttributeDate(SqlOperationService.DN);
        if ((attributeDataDn == null) || (attributeDataDn.getValue() == null)) {
            throw new MappingException("Failed to convert EntryData to Entry because DN is missing");
        }
        entriesAttributes.put(attributeDataDn.getValue().toString(), entryData.getAttributeData());
        // Remove reference to allow java clean up object
        searchResultEntries[i] = null;
        // Allow java to clean up temporary objects
        if (count >= 100) {
            List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
            result.addAll(currentResult);
            entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
            count = 0;
        }
    }
    List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
    result.addAll(currentResult);
    return result;
}
Also used : EntryData(io.jans.orm.model.EntryData) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) List(java.util.List) AttributeData(io.jans.orm.model.AttributeData) LinkedHashMap(java.util.LinkedHashMap) MappingException(io.jans.orm.exception.MappingException)

Example 24 with MappingException

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

Example 25 with MappingException

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

the class LdapEntryManager method findEntriesVirtualListView.

@Deprecated
public <T> List<T> findEntriesVirtualListView(String baseDN, Class<T> entryClass, Filter filter, int start, int count, String sortBy, SortOrder sortOrder, PagedResult vlvResponse, String[] ldapReturnAttributes) {
    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);
    String[] currentLdapReturnAttributes = ldapReturnAttributes;
    if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
        currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
    }
    // Find entries
    Filter searchFilter;
    if (objectClasses.length > 0) {
        searchFilter = addObjectClassFilter(filter, objectClasses);
    } else {
        searchFilter = filter;
    }
    SearchResult searchResult = null;
    try {
        searchResult = getOperationService().searchVirtualListView(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
        if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
            throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
    }
    if (searchResult.getEntryCount() == 0) {
        return new ArrayList<T>(0);
    }
    List<T> entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
    return entries;
}
Also used : ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) SearchResult(com.unboundid.ldap.sdk.SearchResult) MappingException(io.jans.orm.exception.MappingException) ParseException(java.text.ParseException) EntryDeleteException(io.jans.orm.exception.EntryDeleteException) SearchScopeException(io.jans.orm.exception.operation.SearchScopeException) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) ConnectionException(io.jans.orm.exception.operation.ConnectionException) 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) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

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