Search in sources :

Example 21 with MappingException

use of org.gluu.persist.exception.mapping.MappingException 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 22 with MappingException

use of org.gluu.persist.exception.mapping.MappingException 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 23 with MappingException

use of org.gluu.persist.exception.mapping.MappingException 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

MappingException (org.gluu.persist.exception.mapping.MappingException)23 PropertyAnnotation (org.gluu.persist.model.PropertyAnnotation)15 AttributeData (org.gluu.persist.model.AttributeData)12 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)12 EntryPersistenceException (org.gluu.persist.exception.mapping.EntryPersistenceException)9 ArrayList (java.util.ArrayList)8 Filter (org.gluu.search.filter.Filter)7 SearchException (org.gluu.persist.exception.operation.SearchException)5 SearchResult (com.unboundid.ldap.sdk.SearchResult)4 Annotation (java.lang.annotation.Annotation)4 ParseException (java.text.ParseException)4 List (java.util.List)4 InvalidArgumentException (org.gluu.persist.exception.mapping.InvalidArgumentException)4 AuthenticationException (org.gluu.persist.exception.operation.AuthenticationException)4 ConnectionException (org.gluu.persist.exception.operation.ConnectionException)4 SearchScopeException (org.gluu.persist.exception.operation.SearchScopeException)4 Getter (org.gluu.persist.reflect.property.Getter)4 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)4 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)3 HashMap (java.util.HashMap)2