use of io.jans.orm.model.AttributeData 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);
}
}
use of io.jans.orm.model.AttributeData 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;
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class SqlEntryManager method createModification.
private AttributeDataModification createModification(final AttributeModificationType type, final String attributeName, final Boolean multiValued, final Object... attributeValues) {
String realAttributeName = attributeName;
Object[] realValues = attributeValues;
if (StringHelper.equalsIgnoreCase(SqlOperationService.USER_PASSWORD, realAttributeName)) {
realValues = getOperationService().createStoragePassword(StringHelper.toStringArray(attributeValues));
}
escapeValues(realValues);
if (Boolean.TRUE.equals(multiValued)) {
return new AttributeDataModification(type, new AttributeData(realAttributeName, realValues, multiValued));
} else {
if ((realValues == null) || (realValues.length == 0)) {
return new AttributeDataModification(type, new AttributeData(realAttributeName, null));
}
return new AttributeDataModification(type, new AttributeData(realAttributeName, realValues[0]));
}
}
use of io.jans.orm.model.AttributeData 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);
}
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class SqlEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
try {
// Load entry
ParsedKey keyWithInum = toSQLKey(dn);
List<AttributeData> result = getOperationService().lookup(keyWithInum.getKey(), objectClasses[0], toInternalAttributes(ldapReturnAttributes));
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: '%s'", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: '%s'", dn));
}
Aggregations