use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class LdapEntryManager method remove.
@Override
public <T> int remove(String baseDN, Class<T> entryClass, Filter filter, int count) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
DeleteBatchOperation batchOperation = new DeleteBatchOperation<T>(this);
SearchResult searchResult = null;
try {
LdapBatchOperationWraper<T> batchOperationWraper = new LdapBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
searchResult = getOperationService().search(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), batchOperationWraper, 0, 100, count, null, LdapOperationService.DN);
} catch (Exception ex) {
throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryDeleteException(String.format("Failed to delete entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
return batchOperation.getCountEntries();
}
use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class LdapEntryManager method findPagedEntries.
@Override
public <T> PagedResult<T> findPagedEntries(String baseDN, Class<T> entryClass, Filter filter, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, int start, int count, int chunkSize) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
List<SearchResultEntry> searchResultEntries;
PagedResult<T> vlvResponse = new PagedResult<T>();
try {
searchResultEntries = getOperationService().searchSearchResultEntryList(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, chunkSize, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
List<T> entries = new ArrayList<T>(0);
if (searchResultEntries.size() > 0) {
entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResultEntries.toArray(new SearchResultEntry[] {}));
}
vlvResponse.setEntries(entries);
return vlvResponse;
}
use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class BaseEntryManager method preparePropertyAnnotationTypes.
protected <T> void preparePropertyAnnotationTypes(Class<T> entry, Map<String, PropertyAnnotation> propertiesAnnotationsMap) {
for (PropertyAnnotation propertiesAnnotation : propertiesAnnotationsMap.values()) {
String propertyName = propertiesAnnotation.getPropertyName();
Class<?> parameterType = getSetterPropertyType(entry, propertyName);
propertiesAnnotation.setParameterType(parameterType);
}
}
use of io.jans.orm.reflect.property.PropertyAnnotation 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.reflect.property.PropertyAnnotation 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