Search in sources :

Example 21 with AttributeData

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();
}
Also used : LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation)

Example 22 with AttributeData

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();
    }
}
Also used : ArrayList(java.util.ArrayList) LdapAttribute(org.gluu.site.ldap.persistence.annotation.LdapAttribute) AttributeData(org.gluu.persist.model.AttributeData) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation)

Example 23 with AttributeData

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);
}
Also used : Filter(org.gluu.search.filter.Filter) LdapObjectClass(org.gluu.site.ldap.persistence.annotation.LdapObjectClass) LdapCustomObjectClass(org.gluu.site.ldap.persistence.annotation.LdapCustomObjectClass) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) AttributeData(org.gluu.persist.model.AttributeData) MappingException(org.gluu.persist.exception.mapping.MappingException) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation)

Example 24 with AttributeData

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);
}
Also used : MappingException(org.gluu.persist.exception.mapping.MappingException) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) AttributeDataModification(org.gluu.persist.model.AttributeDataModification) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) AttributeData(org.gluu.persist.model.AttributeData)

Example 25 with AttributeData

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;
    }
}
Also used : Setter(org.gluu.persist.reflect.property.Setter) AttributeData(org.gluu.persist.model.AttributeData) PropertyAnnotation(org.gluu.persist.model.PropertyAnnotation) MappingException(org.gluu.persist.exception.mapping.MappingException)

Aggregations

AttributeData (org.gluu.persist.model.AttributeData)25 ArrayList (java.util.ArrayList)15 MappingException (org.gluu.persist.exception.mapping.MappingException)15 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)14 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)9 List (java.util.List)7 Annotation (java.lang.annotation.Annotation)6 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)6 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)6 HashMap (java.util.HashMap)4 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)4 AttributeDataModification (org.gluu.persist.model.AttributeDataModification)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 ParseException (java.text.ParseException)3 LinkedList (java.util.LinkedList)3 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)3 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)3 SearchException (org.gluu.persist.exception.operation.SearchException)3 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)3 Getter (org.gluu.persist.reflect.property.Getter)3