Search in sources :

Example 16 with PropertyAnnotation

use of org.gluu.persist.model.PropertyAnnotation 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 17 with PropertyAnnotation

use of org.gluu.persist.model.PropertyAnnotation 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 18 with PropertyAnnotation

use of org.gluu.persist.model.PropertyAnnotation 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

PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)18 AttributeData (org.gluu.persist.model.AttributeData)14 MappingException (org.gluu.persist.exception.mapping.MappingException)13 ArrayList (java.util.ArrayList)9 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)7 Annotation (java.lang.annotation.Annotation)6 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)6 Filter (org.gluu.search.filter.Filter)5 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)5 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)4 SearchResult (com.unboundid.ldap.sdk.SearchResult)3 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 ParseException (java.text.ParseException)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 HashMap (java.util.HashMap)2 IdentityHashMap (java.util.IdentityHashMap)2 List (java.util.List)2