use of io.jans.orm.model.AttributeDataModification in project jans by JanssenProject.
the class SpannerEntryManager method merge.
@Override
public void merge(String dn, String[] objectClasses, List<AttributeDataModification> attributeDataModifications, Integer expirationValue) {
// Update entry
try {
List<AttributeDataModification> modifications = new ArrayList<AttributeDataModification>(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();
}
AttributeDataModification modification = null;
AttributeModificationType modificationType = attributeDataModification.getModificationType();
if ((AttributeModificationType.ADD == modificationType) || (AttributeModificationType.FORCE_UPDATE == modificationType)) {
modification = createModification(modificationType, toInternalAttribute(attributeName), multiValued, attributeValues, oldAttributeValues);
} else {
if ((AttributeModificationType.REMOVE == modificationType)) {
if ((attribute == null) && isEmptyAttributeValues(oldAttribute)) {
// It's RDBS case. We don't need to set null to already empty table cell
continue;
}
modification = createModification(AttributeModificationType.REMOVE, toInternalAttribute(oldAttributeName), multiValued, oldAttributeValues, null);
} else if ((AttributeModificationType.REPLACE == modificationType)) {
modification = createModification(AttributeModificationType.REPLACE, toInternalAttribute(attributeName), multiValued, attributeValues, oldAttributeValues);
}
}
if (modification != null) {
modifications.add(modification);
}
}
if (modifications.size() > 0) {
boolean result = getOperationService().updateEntry(toSQLKey(dn).getKey(), objectClasses[0], modifications);
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 io.jans.orm.model.AttributeDataModification 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 io.jans.orm.model.AttributeDataModification in project jans by JanssenProject.
the class BaseEntryManager method merge.
@SuppressWarnings("unchecked")
protected Void merge(Object entry, boolean isSchemaUpdate, boolean isConfigurationUpdate, AttributeModificationType schemaModificationType) {
if (entry == null) {
throw new MappingException("Entry to persist is null");
}
Class<?> entryClass = entry.getClass();
checkEntryClass(entryClass, isSchemaUpdate);
// Determine entry update method
boolean forceUpdate = isUseEntryForceUpdate(entryClass);
String[] objectClasses = getObjectClasses(entry, entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
Object dnValue = getDNValue(entry, entryClass);
Integer expirationValue = getExpirationValue(entry, entryClass, true);
List<AttributeData> attributesToPersist = getAttributesListForPersist(entry, propertiesAnnotations);
Map<String, AttributeData> attributesToPersistMap = getAttributesMap(attributesToPersist);
// Load entry
List<AttributeData> attributesFromLdap = null;
if (isSchemaUpdate || forceUpdate) {
// If it's schema modification request we don't need to load
// attributes from LDAP
attributesFromLdap = new ArrayList<AttributeData>();
} else {
List<String> currentLdapReturnAttributesList = buildAttributesListForUpdate(entry, objectClasses, propertiesAnnotations);
if (!isConfigurationUpdate) {
currentLdapReturnAttributesList.add("objectClass");
}
attributesFromLdap = find(dnValue.toString(), objectClasses, propertiesAnnotationsMap, currentLdapReturnAttributesList.toArray(EMPTY_STRING_ARRAY));
}
if (LOG.isTraceEnabled()) {
dumpAttributes("attributesFromLdap", attributesFromLdap);
dumpAttributes("attributesToPersist", attributesToPersist);
}
Map<String, AttributeData> attributesFromLdapMap = getAttributesMap(attributesFromLdap);
// Prepare list of modifications
// Process properties with Attribute annotation
List<AttributeDataModification> attributeDataModifications = collectAttributeModifications(propertiesAnnotations, attributesToPersistMap, attributesFromLdapMap, isSchemaUpdate, schemaModificationType, forceUpdate);
if (LOG.isTraceEnabled()) {
dumpAttributeDataModifications("attributeDataModifications before updateMergeChanges", attributeDataModifications);
}
updateMergeChanges(dnValue.toString(), entry, isSchemaUpdate | isConfigurationUpdate, entryClass, attributesFromLdapMap, attributeDataModifications, forceUpdate);
if (LOG.isTraceEnabled()) {
dumpAttributeDataModifications("attributeDataModifications after updateMergeChanges", attributeDataModifications);
}
LOG.debug(String.format("LDAP attributes for merge: %s", attributeDataModifications));
merge(dnValue.toString(), objectClasses, attributeDataModifications, expirationValue);
return null;
}
use of io.jans.orm.model.AttributeDataModification in project jans by JanssenProject.
the class BaseEntryManager method dumpAttributeDataModifications.
protected void dumpAttributeDataModifications(String variableName, List<AttributeDataModification> attributeDataModifications) {
System.out.println("\n" + variableName + ": START");
for (AttributeDataModification modification : attributeDataModifications) {
String newValues = "[]";
String oldValues = "[]";
if ((modification.getAttribute() != null) && (modification.getAttribute().getValues() != null)) {
newValues = Arrays.toString(modification.getAttribute().getValues());
}
if ((modification.getOldAttribute() != null) && (modification.getOldAttribute().getValues() != null)) {
oldValues = Arrays.toString(modification.getOldAttribute().getValues());
}
AttributeData attribute = modification.getAttribute();
if (attribute == null) {
attribute = modification.getOldAttribute();
}
System.out.println(String.format("%s\t\t%s\t%b\t\t%s\t->\t%s", attribute.getName(), modification.getModificationType().name(), attribute.getMultiValued(), oldValues, newValues));
}
System.out.println(variableName + ": END");
}
use of io.jans.orm.model.AttributeDataModification in project jans by JanssenProject.
the class SqlEntryManager method merge.
@Override
public void merge(String dn, String[] objectClasses, List<AttributeDataModification> attributeDataModifications, Integer expirationValue) {
// Update entry
try {
List<AttributeDataModification> modifications = new ArrayList<AttributeDataModification>(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();
}
AttributeDataModification modification = null;
AttributeModificationType modificationType = attributeDataModification.getModificationType();
if ((AttributeModificationType.ADD == modificationType) || (AttributeModificationType.FORCE_UPDATE == modificationType)) {
modification = createModification(modificationType, toInternalAttribute(attributeName), multiValued, attributeValues);
} else {
if ((AttributeModificationType.REMOVE == modificationType)) {
if ((attribute == null) && isEmptyAttributeValues(oldAttribute)) {
// It's RDBS case. We don't need to set null to already empty table cell
continue;
}
modification = createModification(AttributeModificationType.REMOVE, toInternalAttribute(oldAttributeName), multiValued, oldAttributeValues);
} else if ((AttributeModificationType.REPLACE == modificationType)) {
modification = createModification(AttributeModificationType.REPLACE, toInternalAttribute(attributeName), multiValued, attributeValues);
}
}
if (modification != null) {
modifications.add(modification);
}
}
if (modifications.size() > 0) {
boolean result = getOperationService().updateEntry(toSQLKey(dn).getKey(), objectClasses[0], modifications);
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);
}
}
Aggregations