Search in sources :

Example 21 with AttributeData

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

the class BaseEntryManager method dumpAttributes.

protected void dumpAttributes(String variableName, List<AttributeData> attributesToPersist) {
    System.out.println("\n" + variableName + ": START");
    for (AttributeData attribute : attributesToPersist) {
        System.out.println(String.format("%s\t\t%s\t%b", attribute.getName(), Arrays.toString(attribute.getValues()), attribute.getMultiValued()));
    }
    System.out.println(variableName + ": END");
}
Also used : AttributeData(io.jans.orm.model.AttributeData)

Example 22 with AttributeData

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

the class BaseEntryManager method getCustomObjectClasses.

protected String[] getCustomObjectClasses(Object entry, Class<?> entryClass) {
    List<String> result = new ArrayList<String>();
    List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
    for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
        String propertyName = propertiesAnnotation.getPropertyName();
        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);
        AttributeData attribute = getAttributeData(propertyName, propertyName, getter, entry, multiValued, false);
        if (attribute != null) {
            for (String objectClass : attribute.getStringValues()) {
                if (objectClass != null) {
                    result.add(objectClass);
                }
            }
        }
        break;
    }
    return result.toArray(new String[0]);
}
Also used : Getter(io.jans.orm.reflect.property.Getter) ArrayList(java.util.ArrayList) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) MappingException(io.jans.orm.exception.MappingException)

Example 23 with AttributeData

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

the class BaseEntryManager method createAttributesFilter.

protected Filter[] createAttributesFilter(List<AttributeData> attributes) {
    if ((attributes == null) || (attributes.size() == 0)) {
        return null;
    }
    List<Filter> results = new ArrayList<Filter>(attributes.size());
    for (AttributeData attribute : attributes) {
        String attributeName = attribute.getName();
        for (Object value : attribute.getValues()) {
            Filter filter = Filter.createEqualityFilter(attributeName, value);
            if ((attribute.getMultiValued() != null) && attribute.getMultiValued()) {
                filter.multiValued();
            }
            results.add(filter);
        }
    }
    return results.toArray(new Filter[results.size()]);
}
Also used : Filter(io.jans.orm.search.filter.Filter) ArrayList(java.util.ArrayList) JsonObject(io.jans.orm.annotation.JsonObject) AttributeData(io.jans.orm.model.AttributeData)

Example 24 with AttributeData

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

the class BaseEntryManager method getEntryKey.

private String getEntryKey(Object dnValue, boolean caseSensetive, List<PropertyAnnotation> propertiesAnnotations, List<AttributeData> attributesData) {
    StringBuilder sb = new StringBuilder("_HASH__").append((String.valueOf(dnValue)).toLowerCase()).append("__");
    List<String> processedProperties = new ArrayList<String>();
    Map<String, AttributeData> attributesDataMap = getAttributesDataMap(attributesData);
    for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
        Annotation ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), AttributeName.class);
        if (ldapAttribute == null) {
            continue;
        }
        String ldapAttributeName = ((AttributeName) ldapAttribute).name();
        if (StringHelper.isEmpty(ldapAttributeName)) {
            ldapAttributeName = propertiesAnnotation.getPropertyName();
        }
        processedProperties.add(ldapAttributeName);
        String[] values = null;
        AttributeData attributeData = attributesDataMap.get(ldapAttributeName);
        if ((attributeData != null) && (attributeData.getValues() != null)) {
            values = attributeData.getStringValues();
            Arrays.sort(values);
        }
        addPropertyWithValuesToKey(sb, ldapAttributeName, values);
    }
    for (AttributeData attributeData : attributesData) {
        if (processedProperties.contains(attributeData.getName())) {
            continue;
        }
        addPropertyWithValuesToKey(sb, attributeData.getName(), attributeData.getStringValues());
    }
    if (caseSensetive) {
        return sb.toString();
    } else {
        return sb.toString().toLowerCase();
    }
}
Also used : ArrayList(java.util.ArrayList) AttributeName(io.jans.orm.annotation.AttributeName) AttributeData(io.jans.orm.model.AttributeData) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation) Annotation(java.lang.annotation.Annotation) PropertyAnnotation(io.jans.orm.reflect.property.PropertyAnnotation)

Example 25 with AttributeData

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

the class SqlOperationServiceImpl method lookup.

@Override
public List<AttributeData> lookup(String key, String objectClass, String... attributes) throws SearchException, EntryConvertationException {
    Instant startTime = OperationDurationUtil.instance().now();
    TableMapping tableMapping = connectionProvider.getTableMappingByKey(key, objectClass);
    List<AttributeData> result = lookupImpl(tableMapping, key, attributes);
    Duration duration = OperationDurationUtil.instance().duration(startTime);
    OperationDurationUtil.instance().logDebug("SQL operation: lookup, duration: {}, table: {}, key: {}, attributes: {}", duration, tableMapping.getTableName(), key, attributes);
    return result;
}
Also used : Instant(java.time.Instant) TableMapping(io.jans.orm.sql.model.TableMapping) Duration(java.time.Duration) AttributeData(io.jans.orm.model.AttributeData)

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