use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class BaseEntryManager method getHashCode.
@Override
public int getHashCode(Object entry) {
if (entry == null) {
throw new MappingException("Entry to persist is null");
}
// Check entry class
Class<?> entryClass = entry.getClass();
checkEntryClass(entryClass, false);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Object dnValue = getDNValue(entry, entryClass);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
String key = getEntryKey(dnValue, false, propertiesAnnotations, attributes);
if (LOG.isDebugEnabled()) {
LOG.debug(String.format("Entry key HashCode is: %s", key.hashCode()));
}
return key.hashCode();
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class BaseEntryManager method getEntryKey.
private String getEntryKey(Object dnValue, boolean caseSensetive, List<PropertyAnnotation> propertiesAnnotations, List<AttributeData> attributesData) {
StringBuilder sb = new StringBuilder("_HASH__").append(((String) dnValue).toLowerCase()).append("__");
List<String> processedProperties = new ArrayList<String>();
Map<String, AttributeData> attributesDataMap = getAttributesDataMap(attributesData);
for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
Annotation ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapAttribute.class);
if (ldapAttribute == null) {
continue;
}
String ldapAttributeName = ((LdapAttribute) ldapAttribute).name();
if (StringHelper.isEmpty(ldapAttributeName)) {
ldapAttributeName = propertiesAnnotation.getPropertyName();
}
processedProperties.add(ldapAttributeName);
String[] values = null;
AttributeData attributeData = attributesDataMap.get(ldapAttributeName);
if ((attributeData != null) && (attributeData.getValues() != null)) {
values = attributeData.getValues().clone();
Arrays.sort(values);
}
addPropertyWithValuesToKey(sb, ldapAttributeName, values);
}
for (AttributeData attributeData : attributesData) {
if (processedProperties.contains(attributeData.getName())) {
continue;
}
addPropertyWithValuesToKey(sb, attributeData.getName(), attributeData.getValues());
}
if (caseSensetive) {
return sb.toString();
} else {
return sb.toString().toLowerCase();
}
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class BaseEntryManager method findEntries.
@Override
@SuppressWarnings("unchecked")
public <T> List<T> findEntries(Object entry, int sizeLimit) {
if (entry == null) {
throw new MappingException("Entry to find is null");
}
// Check entry class
Class<T> entryClass = (Class<T>) entry.getClass();
checkEntryClass(entryClass, false);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Object dnValue = getDNValue(entry, entryClass);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
Filter searchFilter = createFilterByEntry(entry, entryClass, attributes);
return findEntries(dnValue.toString(), entryClass, searchFilter, SearchScope.SUB, null, sizeLimit, DEFAULT_PAGINATION_SIZE);
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class BaseEntryManager method merge.
@SuppressWarnings("unchecked")
protected <T> T merge(T entry, boolean isSchemaUpdate, AttributeModificationType schemaModificationType) {
if (entry == null) {
throw new MappingException("Entry to persist is null");
}
Class<?> entryClass = entry.getClass();
checkEntryClass(entryClass, isSchemaUpdate);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Object dnValue = getDNValue(entry, entryClass);
List<AttributeData> attributesToPersist = getAttributesListForPersist(entry, propertiesAnnotations);
Map<String, AttributeData> attributesToPersistMap = getAttributesMap(attributesToPersist);
// Load entry
List<AttributeData> attributesFromLdap;
if (isSchemaUpdate) {
// If it's schema modification request we don't need to load
// attributes from LDAP
attributesFromLdap = new ArrayList<AttributeData>();
} else {
List<String> currentLdapReturnAttributesList = getLdapAttributesList(entry, propertiesAnnotations, false);
currentLdapReturnAttributesList.add("objectClass");
attributesFromLdap = find(dnValue.toString(), currentLdapReturnAttributesList.toArray(EMPTY_STRING_ARRAY));
}
Map<String, AttributeData> attributesFromLdapMap = getAttributesMap(attributesFromLdap);
// Prepare list of modifications
// Process properties with LdapAttribute annotation
List<AttributeDataModification> attributeDataModifications = collectAttributeModifications(propertiesAnnotations, attributesToPersistMap, attributesFromLdapMap, isSchemaUpdate, schemaModificationType);
updateMergeChanges(entry, isSchemaUpdate, entryClass, attributesFromLdapMap, attributeDataModifications);
LOG.debug(String.format("LDAP attributes for merge: %s", attributeDataModifications));
merge(dnValue.toString(), attributeDataModifications);
return (T) find(entryClass, dnValue.toString(), null, propertiesAnnotations);
}
use of org.gluu.persist.model.AttributeData in project oxCore by GluuFederation.
the class BaseEntryManager method setCustomObjectClasses.
protected void setCustomObjectClasses(Object entry, Class<?> entryClass, String[] objectClasses) {
List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
String propertyName = propertiesAnnotation.getPropertyName();
Setter setter = getSetter(entryClass, propertyName);
if (setter == null) {
throw new MappingException("Entry should has setter for property " + propertyName);
}
AttributeData attribute = new AttributeData(propertyName, objectClasses);
setPropertyValue(propertyName, setter, entry, attribute, false);
break;
}
}
Aggregations