use of io.jans.orm.reflect.property.Getter in project jans by JanssenProject.
the class BaseEntryManager method getAttributesFromAttributesList.
private List<AttributeData> getAttributesFromAttributesList(Object entry, Annotation ldapAttribute, String propertyName) {
Class<?> entryClass = entry.getClass();
List<AttributeData> listAttributes = new ArrayList<AttributeData>();
Getter getter = getGetter(entryClass, propertyName);
if (getter == null) {
throw new MappingException("Entry should has getter for property " + propertyName);
}
Object propertyValue = getter.get(entry);
if (propertyValue == null) {
return null;
}
if (!(propertyValue instanceof List<?>)) {
throw new MappingException("Entry property should has List base type");
}
Class<?> elementType = ReflectHelper.getListType(getter);
String entryPropertyName = ((AttributesList) ldapAttribute).name();
Getter entryPropertyNameGetter = getGetter(elementType, entryPropertyName);
if (entryPropertyNameGetter == null) {
throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyName);
}
String entryPropertyValue = ((AttributesList) ldapAttribute).value();
Getter entryPropertyValueGetter = getGetter(elementType, entryPropertyValue);
if (entryPropertyValueGetter == null) {
throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyValue);
}
String entryPropertyMultivalued = ((AttributesList) ldapAttribute).multiValued();
Getter entryPropertyMultivaluedGetter = null;
if (StringHelper.isNotEmpty(entryPropertyMultivalued)) {
entryPropertyMultivaluedGetter = getGetter(elementType, entryPropertyMultivalued);
}
if (entryPropertyMultivaluedGetter != null) {
Class<?> propertyType = entryPropertyMultivaluedGetter.getReturnType();
if (!propertyType.equals(Boolean.TYPE)) {
throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyMultivalued + " with boolean type");
}
}
for (Object entryAttribute : (List<?>) propertyValue) {
Boolean multiValued = null;
if (entryPropertyMultivaluedGetter != null) {
multiValued = (boolean) entryPropertyMultivaluedGetter.get(entryAttribute);
}
AttributeData attribute = getAttributeData(propertyName, entryPropertyNameGetter, entryPropertyValueGetter, entryAttribute, Boolean.TRUE.equals(multiValued), false);
if (attribute != null) {
if (multiValued == null) {
// Detect if attribute has more than one value
multiValued = attribute.getValues().length > 1;
}
attribute.setMultiValued(multiValued);
listAttributes.add(attribute);
}
}
return listAttributes;
}
Aggregations