use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class LdapEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, SearchResultEntry... searchResultEntries) {
List<T> result = new ArrayList<T>(searchResultEntries.length);
Map<String, List<AttributeData>> entriesAttributes = new HashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
SearchResultEntry entry = searchResultEntries[i];
entriesAttributes.put(entry.getDN(), getAttributeDataList(entry));
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
entriesAttributes = new HashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
return result;
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class LdapEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
try {
// Load entry
SearchResultEntry entry = getOperationService().lookup(dn, ldapReturnAttributes);
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class LdapEntryManager method persist.
@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
List<Attribute> ldapAttributes = new ArrayList<Attribute>(attributes.size());
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
String[] attributeValues = attribute.getStringValues();
if (ArrayHelper.isNotEmpty(attributeValues) && StringHelper.isNotEmpty(attributeValues[0])) {
if (getOperationService().isCertificateAttribute(attributeName)) {
byte[][] binaryValues = toBinaryValues(attributeValues);
ldapAttributes.add(new Attribute(attributeName + ";binary", binaryValues));
} else {
ldapAttributes.add(new Attribute(attributeName, attributeValues));
}
}
}
// Persist entry
try {
boolean result = getOperationService().addEntry(dn, ldapAttributes);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn));
}
} catch (ConnectionException ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex.getCause());
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: %s", dn), ex);
}
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class BaseEntryManager method findEntries.
@Override
@SuppressWarnings("unchecked")
public <T> List<T> findEntries(Object entry, int count) {
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, 0, count, DEFAULT_PAGINATION_SIZE);
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class BaseEntryManager method getAttributesMap.
protected <T> Map<String, PropertyAnnotation> getAttributesMap(T entry, List<PropertyAnnotation> propertiesAnnotations, boolean isIgnoreAttributesList) {
Map<String, PropertyAnnotation> attributes = new HashMap<String, PropertyAnnotation>();
for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
String propertyName = propertiesAnnotation.getPropertyName();
Annotation ldapAttribute;
if (!isIgnoreAttributesList) {
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), AttributesList.class);
if (ldapAttribute != null) {
if (entry == null) {
return null;
} else {
List<AttributeData> attributesList = getAttributesFromAttributesList(entry, ldapAttribute, propertyName);
for (AttributeData attributeData : attributesList) {
String ldapAttributeName = attributeData.getName();
if (!attributes.containsKey(ldapAttributeName)) {
attributes.put(ldapAttributeName, propertiesAnnotation);
}
}
}
}
}
// Process properties with AttributeName annotation
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), AttributeName.class);
if (ldapAttribute != null) {
String ldapAttributeName = ((AttributeName) ldapAttribute).name();
if (StringHelper.isEmpty(ldapAttributeName)) {
ldapAttributeName = propertyName;
}
if (!attributes.containsKey(ldapAttributeName)) {
attributes.put(ldapAttributeName, propertiesAnnotation);
}
}
}
if (attributes.size() == 0) {
return null;
}
return attributes;
}
Aggregations