use of org.gluu.persist.model.PropertyAnnotation in project oxCore by GluuFederation.
the class BaseEntryManager method getAttributeFromLdapAttribute.
private AttributeData getAttributeFromLdapAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
Class<?> entryClass = entry.getClass();
String ldapAttributeName = ((LdapAttribute) 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);
}
Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapJsonObject.class);
boolean jsonObject = ldapJsonObject != null;
AttributeData attribute = getAttribute(propertyName, ldapAttributeName, getter, entry, jsonObject);
return attribute;
}
use of org.gluu.persist.model.PropertyAnnotation in project oxCore by GluuFederation.
the class BaseEntryManager method getAttributesListForPersist.
protected List<AttributeData> getAttributesListForPersist(Object entry, List<PropertyAnnotation> propertiesAnnotations) {
// Prepare list of properties to persist
List<AttributeData> attributes = new ArrayList<AttributeData>();
for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
String propertyName = propertiesAnnotation.getPropertyName();
Annotation ldapAttribute;
// Process properties with LdapAttribute annotation
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapAttribute.class);
if (ldapAttribute != null) {
AttributeData attribute = getAttributeFromLdapAttribute(entry, ldapAttribute, propertiesAnnotation, propertyName);
if (attribute != null) {
attributes.add(attribute);
}
continue;
}
// Process properties with LdapAttributesList annotation
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapAttributesList.class);
if (ldapAttribute != null) {
List<AttributeData> listAttributes = getAttributesFromLdapAttributesList(entry, ldapAttribute, propertyName);
if (listAttributes != null) {
attributes.addAll(listAttributes);
}
continue;
}
}
return attributes;
}
use of org.gluu.persist.model.PropertyAnnotation in project oxCore by GluuFederation.
the class BaseEntryManager method getLdapAttributesList.
private <T> List<String> getLdapAttributesList(T entry, List<PropertyAnnotation> propertiesAnnotations, boolean isIgnoreLdapAttributesList) {
List<String> attributes = new ArrayList<String>();
for (PropertyAnnotation propertiesAnnotation : propertiesAnnotations) {
String propertyName = propertiesAnnotation.getPropertyName();
Annotation ldapAttribute;
if (!isIgnoreLdapAttributesList) {
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapAttributesList.class);
if (ldapAttribute != null) {
if (entry == null) {
return null;
} else {
List<AttributeData> ldapAttributesList = getAttributesFromLdapAttributesList(entry, ldapAttribute, propertyName);
for (AttributeData attributeData : ldapAttributesList) {
String ldapAttributeName = attributeData.getName();
attributes.add(ldapAttributeName);
}
}
}
}
// Process properties with LdapAttribute annotation
ldapAttribute = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), LdapAttribute.class);
if (ldapAttribute != null) {
String ldapAttributeName = ((LdapAttribute) ldapAttribute).name();
if (StringHelper.isEmpty(ldapAttributeName)) {
ldapAttributeName = propertyName;
}
attributes.add(ldapAttributeName);
}
}
if (attributes.size() == 0) {
return null;
}
return attributes;
}
use of org.gluu.persist.model.PropertyAnnotation in project oxCore by GluuFederation.
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);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
// Add object classes
String[] objectClasses = getObjectClasses(entry, entryClass);
attributes.add(new AttributeData(OBJECT_CLASS, objectClasses));
LOG.debug(String.format("LDAP attributes for persist: %s", attributes));
persist(dnValue.toString(), attributes);
}
use of org.gluu.persist.model.PropertyAnnotation in project oxCore by GluuFederation.
the class LdapEntryManager method findEntriesVirtualListView.
@Deprecated
public <T> List<T> findEntriesVirtualListView(String baseDN, Class<T> entryClass, Filter filter, int startIndex, int count, String sortBy, SortOrder sortOrder, ListViewResponse 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 = getLdapAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = this.ldapOperationService.searchVirtualListView(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), startIndex, 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