Search in sources :

Example 1 with MutationSpec

use of com.couchbase.client.java.subdoc.MutationSpec in project jans by JanssenProject.

the class CouchbaseEntryManager method merge.

@Override
public void merge(String dn, String[] objectClasses, List<AttributeDataModification> attributeDataModifications, Integer expirationValue) {
    // Update entry
    try {
        List<MutationSpec> modifications = new ArrayList<MutationSpec>(attributeDataModifications.size());
        for (AttributeDataModification attributeDataModification : attributeDataModifications) {
            AttributeData attribute = attributeDataModification.getAttribute();
            AttributeData oldAttribute = attributeDataModification.getOldAttribute();
            String attributeName = null;
            Object[] attributeValues = null;
            Boolean multiValued = null;
            if (attribute != null) {
                attributeName = attribute.getName();
                attributeValues = attribute.getValues();
                multiValued = attribute.getMultiValued();
            }
            String oldAttributeName = null;
            Object[] oldAttributeValues = null;
            if (oldAttribute != null) {
                oldAttributeName = oldAttribute.getName();
                oldAttributeValues = oldAttribute.getValues();
            }
            MutationSpec modification = null;
            if (AttributeModificationType.ADD.equals(attributeDataModification.getModificationType())) {
                modification = createModification(Mutation.DICT_ADD, toInternalAttribute(attributeName), multiValued, attributeValues);
            } else {
                if (AttributeModificationType.REMOVE.equals(attributeDataModification.getModificationType())) {
                    modification = createModification(Mutation.DELETE, toInternalAttribute(oldAttributeName), multiValued, oldAttributeValues);
                } else if (AttributeModificationType.REPLACE.equals(attributeDataModification.getModificationType())) {
                    modification = createModification(Mutation.REPLACE, toInternalAttribute(attributeName), multiValued, attributeValues);
                }
            }
            if (modification != null) {
                modifications.add(modification);
            }
        }
        if (modifications.size() > 0) {
            boolean result = getOperationService().updateEntry(toCouchbaseKey(dn).getKey(), modifications, expirationValue);
            if (!result) {
                throw new EntryPersistenceException(String.format("Failed to update entry: %s", dn));
            }
        }
    } catch (Exception ex) {
        throw new EntryPersistenceException(String.format("Failed to update entry: %s", dn), ex);
    }
}
Also used : AttributeDataModification(io.jans.orm.model.AttributeDataModification) ArrayList(java.util.ArrayList) EntryPersistenceException(io.jans.orm.exception.EntryPersistenceException) JsonObject(com.couchbase.client.java.document.json.JsonObject) MutationSpec(com.couchbase.client.java.subdoc.MutationSpec) 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 2 with MutationSpec

use of com.couchbase.client.java.subdoc.MutationSpec in project jans by JanssenProject.

the class CouchbaseOperationServiceImpl method updateEntry.

@Deprecated
protected boolean updateEntry(String key, JsonObject attrs) throws UnsupportedOperationException, PersistenceException {
    List<MutationSpec> mods = new ArrayList<MutationSpec>();
    for (Entry<String, Object> attrEntry : attrs.toMap().entrySet()) {
        String attributeName = attrEntry.getKey();
        Object attributeValue = attrEntry.getValue();
        if (attributeName.equalsIgnoreCase(CouchbaseOperationService.OBJECT_CLASS) || attributeName.equalsIgnoreCase(CouchbaseOperationService.DN) || attributeName.equalsIgnoreCase(CouchbaseOperationService.USER_PASSWORD)) {
            continue;
        } else {
            if (attributeValue != null) {
                mods.add(new MutationSpec(Mutation.REPLACE, attributeName, attributeValue));
            }
        }
    }
    return updateEntry(key, mods, null);
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.couchbase.client.java.document.json.JsonObject) MutationSpec(com.couchbase.client.java.subdoc.MutationSpec)

Aggregations

JsonObject (com.couchbase.client.java.document.json.JsonObject)2 MutationSpec (com.couchbase.client.java.subdoc.MutationSpec)2 ArrayList (java.util.ArrayList)2 AuthenticationException (io.jans.orm.exception.AuthenticationException)1 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)1 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)1 MappingException (io.jans.orm.exception.MappingException)1 SearchException (io.jans.orm.exception.operation.SearchException)1 AttributeData (io.jans.orm.model.AttributeData)1 AttributeDataModification (io.jans.orm.model.AttributeDataModification)1 DateTimeException (java.time.DateTimeException)1 DateTimeParseException (java.time.format.DateTimeParseException)1