Search in sources :

Example 16 with AttributeData

use of io.jans.orm.model.AttributeData in project jans by JanssenProject.

the class BaseEntryManager method dumpAttributeDataModifications.

protected void dumpAttributeDataModifications(String variableName, List<AttributeDataModification> attributeDataModifications) {
    System.out.println("\n" + variableName + ": START");
    for (AttributeDataModification modification : attributeDataModifications) {
        String newValues = "[]";
        String oldValues = "[]";
        if ((modification.getAttribute() != null) && (modification.getAttribute().getValues() != null)) {
            newValues = Arrays.toString(modification.getAttribute().getValues());
        }
        if ((modification.getOldAttribute() != null) && (modification.getOldAttribute().getValues() != null)) {
            oldValues = Arrays.toString(modification.getOldAttribute().getValues());
        }
        AttributeData attribute = modification.getAttribute();
        if (attribute == null) {
            attribute = modification.getOldAttribute();
        }
        System.out.println(String.format("%s\t\t%s\t%b\t\t%s\t->\t%s", attribute.getName(), modification.getModificationType().name(), attribute.getMultiValued(), oldValues, newValues));
    }
    System.out.println(variableName + ": END");
}
Also used : AttributeDataModification(io.jans.orm.model.AttributeDataModification) AttributeData(io.jans.orm.model.AttributeData)

Example 17 with AttributeData

use of io.jans.orm.model.AttributeData 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 18 with AttributeData

use of io.jans.orm.model.AttributeData 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 19 with AttributeData

use of io.jans.orm.model.AttributeData 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 AttributeData

use of io.jans.orm.model.AttributeData 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

AttributeData (io.jans.orm.model.AttributeData)62 MappingException (io.jans.orm.exception.MappingException)29 ArrayList (java.util.ArrayList)23 SearchException (io.jans.orm.exception.operation.SearchException)22 EntryPersistenceException (io.jans.orm.exception.EntryPersistenceException)17 AuthenticationException (io.jans.orm.exception.AuthenticationException)15 EntryDeleteException (io.jans.orm.exception.EntryDeleteException)15 PropertyAnnotation (io.jans.orm.reflect.property.PropertyAnnotation)14 AttributeDataModification (io.jans.orm.model.AttributeDataModification)13 JsonObject (io.jans.orm.annotation.JsonObject)10 LinkedList (java.util.LinkedList)10 DateTimeParseException (java.time.format.DateTimeParseException)8 List (java.util.List)8 ParsedKey (io.jans.orm.impl.model.ParsedKey)7 JsonObject (com.couchbase.client.java.document.json.JsonObject)6 AttributeName (io.jans.orm.annotation.AttributeName)6 PersistenceException (io.jans.orm.exception.operation.PersistenceException)6 Annotation (java.lang.annotation.Annotation)6 AttributeModificationType (io.jans.orm.model.AttributeDataModification.AttributeModificationType)5 LinkedHashMap (java.util.LinkedHashMap)5