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);
}
}
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);
}
Aggregations