Search in sources :

Example 11 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class AbstractEntryManager method checkEntryClass.

protected boolean checkEntryClass(Class<?> entryClass, boolean isAllowSchemaEntry) {
    if (entryClass == null) {
        throw new MappingException("Entry class is null");
    }
    // Check if entry is LDAP Entry
    List<Annotation> entryAnnotations = ReflectHelper.getClassAnnotations(entryClass, LDAP_ENTRY_TYPE_ANNOTATIONS);
    Annotation ldapSchemaEntry = ReflectHelper.getAnnotationByType(entryAnnotations, LdapSchemaEntry.class);
    Annotation ldapEntry = ReflectHelper.getAnnotationByType(entryAnnotations, LdapEntry.class);
    if (isAllowSchemaEntry) {
        if ((ldapSchemaEntry == null) && (ldapEntry == null)) {
            throw new MappingException("Entry should has LdapEntry or LdapSchemaEntry annotation");
        }
    } else {
        if (ldapEntry == null) {
            throw new MappingException("Entry should has LdapEntry annotation");
        }
    }
    return true;
}
Also used : Annotation(java.lang.annotation.Annotation) MappingException(org.gluu.site.ldap.persistence.exception.MappingException)

Example 12 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class AbstractEntryManager method getAttributeFromLdapAttribute.

private AttributeData getAttributeFromLdapAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
    Class<?> entryClass = entry.getClass();
    String ldapAttributeName = ((LdapAttribute) ldapAttribute).name();
    if (StringHelper.isEmpty(ldapAttributeName)) {
        ldapAttributeName = propertyName;
    }
    Getter getter = getGetter(entryClass, propertyName);
    if (getter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName);
    }
    Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapJsonObject.class);
    boolean jsonObject = ldapJsonObject != null;
    AttributeData attribute = getAttribute(propertyName, ldapAttributeName, getter, entry, jsonObject);
    return attribute;
}
Also used : Getter(org.gluu.site.ldap.persistence.property.Getter) LdapAttribute(org.gluu.site.ldap.persistence.annotation.LdapAttribute) Annotation(java.lang.annotation.Annotation) MappingException(org.gluu.site.ldap.persistence.exception.MappingException)

Example 13 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class AbstractEntryManager method persist.

public void persist(Object entry) {
    if (entry == null) {
        throw new MappingException("Entry to persist is null");
    }
    // Check entry class
    Class<?> entryClass = entry.getClass();
    checkEntryClass(entryClass, false);
    String[] objectClasses = getObjectClasses(entry, entryClass);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    // Add object classes
    attributes.add(new AttributeData(OBJECT_CLASS, objectClasses));
    log.debug(String.format("LDAP attributes for persist: %s", attributes));
    persist(dnValue.toString(), attributes);
}
Also used : LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) MappingException(org.gluu.site.ldap.persistence.exception.MappingException)

Example 14 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class AbstractEntryManager method getHashCode.

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) MappingException(org.gluu.site.ldap.persistence.exception.MappingException)

Example 15 with MappingException

use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.

the class AbstractEntryManager method getAttributesFromLdapAttributesList.

private List<AttributeData> getAttributesFromLdapAttributesList(Object entry, Annotation ldapAttribute, String propertyName) {
    Class<?> entryClass = entry.getClass();
    List<AttributeData> listAttributes = new ArrayList<AttributeData>();
    Getter getter = getGetter(entryClass, propertyName);
    if (getter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName);
    }
    Object propertyValue = getter.get(entry);
    if (propertyValue == null) {
        return null;
    }
    if (!(propertyValue instanceof List<?>)) {
        throw new MappingException("Entry property should has List base type");
    }
    Class<?> elementType = ReflectHelper.getListType(getter);
    String entryPropertyName = ((LdapAttributesList) ldapAttribute).name();
    Getter entryPropertyNameGetter = getGetter(elementType, entryPropertyName);
    if (entryPropertyNameGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyName);
    }
    String entryPropertyValue = ((LdapAttributesList) ldapAttribute).value();
    Getter entryPropertyValueGetter = getGetter(elementType, entryPropertyValue);
    if (entryPropertyValueGetter == null) {
        throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyValue);
    }
    for (Object entryAttribute : (List<?>) propertyValue) {
        AttributeData attribute = getAttribute(propertyName, entryPropertyNameGetter, entryPropertyValueGetter, entryAttribute, false);
        if (attribute != null) {
            listAttributes.add(attribute);
        }
    }
    return listAttributes;
}
Also used : Getter(org.gluu.site.ldap.persistence.property.Getter) LdapJsonObject(org.gluu.site.ldap.persistence.annotation.LdapJsonObject) LdapAttributesList(org.gluu.site.ldap.persistence.annotation.LdapAttributesList) MappingException(org.gluu.site.ldap.persistence.exception.MappingException) LdapAttributesList(org.gluu.site.ldap.persistence.annotation.LdapAttributesList)

Aggregations

MappingException (org.gluu.site.ldap.persistence.exception.MappingException)21 LdapJsonObject (org.gluu.site.ldap.persistence.annotation.LdapJsonObject)10 EntryPersistenceException (org.gluu.site.ldap.persistence.exception.EntryPersistenceException)9 EmptyEntryPersistenceException (org.gluu.site.ldap.persistence.exception.EmptyEntryPersistenceException)6 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)5 Annotation (java.lang.annotation.Annotation)5 ParseException (java.text.ParseException)5 ConnectionException (org.gluu.site.ldap.exception.ConnectionException)5 AuthenticationException (org.gluu.site.ldap.persistence.exception.AuthenticationException)5 InvalidArgumentException (org.gluu.site.ldap.persistence.exception.InvalidArgumentException)5 LdapAttributesList (org.gluu.site.ldap.persistence.annotation.LdapAttributesList)4 Getter (org.gluu.site.ldap.persistence.property.Getter)4 LdapAttribute (org.gluu.site.ldap.persistence.annotation.LdapAttribute)3 LdapEnum (org.gluu.site.ldap.persistence.annotation.LdapEnum)2 Setter (org.gluu.site.ldap.persistence.property.Setter)2 SimplePagedResultsControl (com.unboundid.ldap.sdk.controls.SimplePagedResultsControl)1 Method (java.lang.reflect.Method)1 AttributeModificationType (org.gluu.site.ldap.persistence.AttributeDataModification.AttributeModificationType)1 LdapEntry (org.gluu.site.ldap.persistence.annotation.LdapEntry)1