Search in sources :

Example 16 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.

the class BaseEntryManager method getAttributeDataFromAttribute.

private AttributeData getAttributeDataFromAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
    Class<?> entryClass = entry.getClass();
    String ldapAttributeName = ((AttributeName) 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);
    }
    Class<?> parameterType = getSetterPropertyType(entryClass, propertyName);
    boolean multiValued = isMultiValued(parameterType);
    Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), JsonObject.class);
    boolean jsonObject = ldapJsonObject != null;
    AttributeData attribute = getAttributeData(propertyName, ldapAttributeName, getter, entry, multiValued, jsonObject);
    return attribute;
}
Also used : Getter(io.jans.orm.reflect.property.Getter) AttributeName(io.jans.orm.annotation.AttributeName) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException)

Example 17 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.

the class BaseEntryManager method contains.

@Override
public boolean contains(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);
    String[] ldapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
    return contains(dnValue.toString(), entryClass, propertiesAnnotations, attributes, objectClasses, ldapReturnAttributes);
}
Also used : JsonObject(io.jans.orm.annotation.JsonObject) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 18 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.

the class BaseEntryManager method convertToPropertyAnnotationList.

private List<PropertyAnnotation> convertToPropertyAnnotationList(Map<String, List<Annotation>> annotations) {
    List<PropertyAnnotation> result = new ArrayList<PropertyAnnotation>(annotations.size());
    for (Entry<String, List<Annotation>> entry : annotations.entrySet()) {
        result.add(new PropertyAnnotation(entry.getKey(), entry.getValue()));
    }
    Collections.sort(result);
    return result;
}
Also used : ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) AttributesList(io.jans.orm.annotation.AttributesList) List(java.util.List) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 19 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.

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(io.jans.orm.reflect.property.Setter) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Example 20 with PropertyAnnotation

use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.

the class BaseEntryManager method persist.

@Override
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);
    List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
    Object dnValue = getDNValue(entry, entryClass);
    Integer expirationValue = getExpirationValue(entry, entryClass, false);
    List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
    // Add object classes
    String[] objectClasses = getObjectClasses(entry, entryClass);
    attributes.add(new AttributeData(OBJECT_CLASS, objectClasses, true));
    LOG.debug(String.format("LDAP attributes for persist: %s", attributes));
    persist(dnValue.toString(), objectClasses, attributes, expirationValue);
}
Also used : JsonObject(io.jans.orm.annotation.JsonObject) AttributeData(io.jans.orm.model.AttributeData) MappingException(io.jans.orm.exception.MappingException) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Aggregations

PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)42 MappingException (io.jans.orm.exception.MappingException)28 Filter (io.jans.orm.search.filter.Filter)19 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)18 AuthenticationException (io.jans.orm.exception.AuthenticationException)17 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)17 SearchException (io.jans.orm.exception.operation.SearchException)17 AttributeData (io.jans.orm.model.AttributeData)14 ParsedKey (io.jans.orm.impl.model.ParsedKey)9 DateTimeParseException (java.time.format.DateTimeParseException)9 ArrayList (java.util.ArrayList)9 AttributeName (io.jans.orm.annotation.AttributeName)8 JsonObject (io.jans.orm.annotation.JsonObject)8 EntryData (io.jans.orm.model.EntryData)8 Annotation (java.lang.annotation.Annotation)6 JsonObject (com.couchbase.client.java.document.json.JsonObject)5 AttributesList (io.jans.orm.annotation.AttributesList)5 ConvertedExpression (io.jans.orm.couchbase.model.ConvertedExpression)5 DateTimeException (java.time.DateTimeException)5 ConvertedExpression (io.jans.orm.cloud.spanner.model.ConvertedExpression)4