Search in sources :

Example 46 with AttributeData

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

the class CouchbaseEntryManager method updateMergeChanges.

@Override
protected <T> void updateMergeChanges(String baseDn, T entry, boolean isConfigurationUpdate, Class<?> entryClass, Map<String, AttributeData> attributesFromDbMap, List<AttributeDataModification> attributeDataModifications, boolean forceUpdate) {
    // Update object classes if entry contains custom object classes
    if (!isConfigurationUpdate) {
        String[] objectClasses = getObjectClasses(entry, entryClass);
        if (ArrayHelper.isEmpty(objectClasses)) {
            throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses to persist! Entry is invalid: '%s'", entry));
        }
        AttributeData objectClassAttributeData = attributesFromDbMap.get(OBJECT_CLASS.toLowerCase());
        if (objectClassAttributeData == null) {
            throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses in DB! Entry is invalid: '%s'", entry));
        }
        String[] objectClassesFromDb = objectClassAttributeData.getStringValues();
        if (ArrayHelper.isEmpty(objectClassesFromDb)) {
            throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses in DB! Entry is invalid: '%s'", entry));
        }
        // We need to check only first element of each array because objectCLass in Couchbase is single value attribute
        if (!StringHelper.equals(objectClassesFromDb[0], objectClasses[0])) {
            attributeDataModifications.add(new AttributeDataModification(AttributeModificationType.REPLACE, new AttributeData(OBJECT_CLASS, objectClasses, false), new AttributeData(OBJECT_CLASS, objectClassesFromDb, false)));
        }
    }
}
Also used : AttributeDataModification(io.jans.orm.model.AttributeDataModification) AttributeData(io.jans.orm.model.AttributeData)

Example 47 with AttributeData

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

the class CouchbaseEntryManager method createEntities.

protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, ParsedKey baseDn, JsonObject... 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++;
        JsonObject entry = searchResultEntries[i];
        // String key = entry.getString(CouchbasegetOperationService().META_DOC_ID);
        String dn = entry.getString(CouchbaseOperationService.DN);
        entriesAttributes.put(dn, getAttributeDataList(entry));
        // 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 : ISO_INSTANT(java.time.format.DateTimeFormatter.ISO_INSTANT) ArrayList(java.util.ArrayList) JsonObject(com.couchbase.client.java.document.json.JsonObject) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) AttributeData(io.jans.orm.model.AttributeData) LinkedHashMap(java.util.LinkedHashMap)

Example 48 with AttributeData

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

the class CouchbaseEntryManager method getAttributeDataList.

private List<AttributeData> getAttributeDataList(JsonObject entry) {
    if (entry == null) {
        return null;
    }
    List<AttributeData> result = new ArrayList<AttributeData>();
    for (String shortAttributeName : entry.getNames()) {
        Object attributeObject = entry.get(shortAttributeName);
        String attributeName = fromInternalAttribute(shortAttributeName);
        Boolean multiValued = Boolean.FALSE;
        Object[] attributeValueObjects;
        if (attributeObject == null) {
            attributeValueObjects = NO_OBJECTS;
        }
        if (attributeObject instanceof JsonArray) {
            JsonArray jsonArray = (JsonArray) attributeObject;
            ArrayList<Object> resultList = new ArrayList<Object>(jsonArray.size());
            for (Iterator<Object> it = jsonArray.iterator(); it.hasNext(); ) {
                resultList.add(it.next());
            }
            attributeValueObjects = resultList.toArray(NO_OBJECTS);
            multiValued = Boolean.TRUE;
        } else {
            if ((attributeObject instanceof Boolean) || (attributeObject instanceof Integer) || (attributeObject instanceof Long) || (attributeObject instanceof JsonObject)) {
                attributeValueObjects = new Object[] { attributeObject };
            } else if (attributeObject instanceof String) {
                // If it looks like date, treat as Date
                Object valueAsDate = decodeTime(null, attributeObject.toString(), true);
                Object value = valueAsDate == null ? attributeObject.toString() : valueAsDate;
                attributeValueObjects = new Object[] { value };
            } else {
                Object value = attributeObject.toString();
                attributeValueObjects = new Object[] { value };
            }
        }
        unescapeValues(attributeValueObjects);
        AttributeData tmpAttribute = new AttributeData(attributeName, attributeValueObjects);
        if (multiValued != null) {
            tmpAttribute.setMultiValued(multiValued);
        }
        result.add(tmpAttribute);
    }
    return result;
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.couchbase.client.java.document.json.JsonObject) JsonArray(com.couchbase.client.java.document.json.JsonArray) JsonObject(com.couchbase.client.java.document.json.JsonObject) AttributeData(io.jans.orm.model.AttributeData)

Example 49 with AttributeData

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

the class SpannerEntryManager 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(SpannerOperationService.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 50 with AttributeData

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

the class LdapEntryManager method updateMergeChanges.

@Override
protected <T> void updateMergeChanges(String baseDn, T entry, boolean isConfigurationUpdate, Class<?> entryClass, Map<String, AttributeData> attributesFromLdapMap, List<AttributeDataModification> attributeDataModifications, boolean forceUpdate) {
    // Update object classes if entry contains custom object classes
    if (getSupportedLDAPVersion() > 2) {
        if (!isConfigurationUpdate) {
            String[] objectClasses = getObjectClasses(entry, entryClass);
            String[] objectClassesFromLdap = attributesFromLdapMap.get(OBJECT_CLASS.toLowerCase()).getStringValues();
            if (!Arrays.equals(objectClassesFromLdap, objectClasses)) {
                attributeDataModifications.add(new AttributeDataModification(AttributeModificationType.REPLACE, new AttributeData(OBJECT_CLASS, objectClasses), new AttributeData(OBJECT_CLASS, objectClassesFromLdap)));
            }
        }
    }
}
Also used : AttributeDataModification(io.jans.orm.model.AttributeDataModification) AttributeData(io.jans.orm.model.AttributeData)

Aggregations

AttributeData (io.jans.orm.model.AttributeData)62 MappingException (io.jans.orm.exception.MappingException)29 ArrayList (java.util.ArrayList)23 SearchException (io.jans.orm.exception.operation.SearchException)22 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)17 AuthenticationException (io.jans.orm.exception.AuthenticationException)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)14 AttributeDataModification (io.jans.orm.model.AttributeDataModification)13 JsonObject (io.jans.orm.annotation.JsonObject)10 LinkedList (java.util.LinkedList)10 DateTimeParseException (java.time.format.DateTimeParseException)8 List (java.util.List)8 ParsedKey (io.jans.orm.impl.model.ParsedKey)7 JsonObject (com.couchbase.client.java.document.json.JsonObject)6 AttributeName (io.jans.orm.annotation.AttributeName)6 PersistenceException (io.jans.orm.exception.operation.PersistenceException)6 Annotation (java.lang.annotation.Annotation)6 AttributeModificationType (io.jans.orm.model.AttributeDataModification.AttributeModificationType)5 LinkedHashMap (java.util.LinkedHashMap)5