use of io.jans.orm.reflect.property.PropertyAnnotation 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]);
}
use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class BaseEntryManager method getExpirationValue.
protected <T> Integer getExpirationValue(Object entry, Class<T> entryClass, boolean merge) {
// Check if entry has Expiration property
PropertyAnnotation expirationProperty = getExpirationProperty(entryClass);
if (expirationProperty == null) {
return null;
}
String expirationPropertyName = expirationProperty.getPropertyName();
Expiration expirationAnnotation = (Expiration) ReflectHelper.getAnnotationByType(expirationProperty.getAnnotations(), Expiration.class);
if (merge && expirationAnnotation.ignoreDuringUpdate()) {
return null;
}
if (expirationPropertyName == null) {
// No entry expiration property
return null;
}
// Get Expiration value
Getter expirationGetter = getGetter(entryClass, expirationPropertyName);
if (expirationGetter == null) {
throw new MappingException("Entry should has getter for property " + expirationGetter);
}
Class<?> propertyType = expirationGetter.getReturnType();
if (!((propertyType == Integer.class) || (propertyType == Integer.TYPE))) {
throw new MappingException("Entry expiration property should has Integer type. Property: '" + expirationGetter + "'");
}
Object expirationValue = expirationGetter.get(entry);
if (expirationValue == null) {
// No entry expiration or null
return null;
}
Integer resultExpirationValue;
if (expirationValue instanceof Integer) {
resultExpirationValue = (Integer) expirationValue;
} else {
resultExpirationValue = Integer.valueOf((int) expirationValue);
}
// TTL can't be negative
if (resultExpirationValue < 0) {
resultExpirationValue = 0;
}
return resultExpirationValue;
}
use of io.jans.orm.reflect.property.PropertyAnnotation 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();
}
}
use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class SqlEntryManager method findEntriesImpl.
protected <T> PagedResult<EntryData> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
// 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);
}
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
LOG.trace("Search filter: {}", searchFilter);
// Prepare default sort
OrderSpecifier<?>[] defaultSort = getDefaultSort(entryClass);
if (StringHelper.isNotEmpty(sortBy)) {
OrderSpecifier<?> requestedSort = buildSort(sortBy, sortOrder);
if (ArrayHelper.isEmpty(defaultSort)) {
defaultSort = new OrderSpecifier[] { requestedSort };
} else {
defaultSort = ArrayHelper.arrayMerge(new OrderSpecifier[] { requestedSort }, defaultSort);
}
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ParsedKey keyWithInum = toSQLKey(baseDN);
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
PagedResult<EntryData> searchResult = null;
try {
SqlBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new SqlBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
}
searchResult = searchImpl(keyWithInum.getKey(), objectClasses[0], convertedExpression, scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression));
}
return searchResult;
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", keyWithInum.getKey()), ex);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression), ex);
}
}
use of io.jans.orm.reflect.property.PropertyAnnotation in project jans by JanssenProject.
the class LdapEntryManager method findEntriesVirtualListView.
@Deprecated
public <T> List<T> findEntriesVirtualListView(String baseDN, Class<T> entryClass, Filter filter, int start, int count, String sortBy, SortOrder sortOrder, PagedResult vlvResponse, String[] ldapReturnAttributes) {
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;
}
SearchResult searchResult = null;
try {
searchResult = getOperationService().searchVirtualListView(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (searchResult.getEntryCount() == 0) {
return new ArrayList<T>(0);
}
List<T> entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
return entries;
}
Aggregations