use of io.jans.orm.reflect.property.Getter in project jans by JanssenProject.
the class BaseEntryManager method getGetter.
protected <T> Getter getGetter(Class<T> entryClass, String propertyName) {
String key = entryClass.getName() + "." + propertyName;
Getter getter = classGetters.get(key);
if (getter == null) {
synchronized (CLASS_GETTERS_LOCK) {
getter = classGetters.get(key);
if (getter == null) {
getter = ReflectHelper.getGetter(entryClass, propertyName);
classGetters.put(key, getter);
}
}
}
return getter;
}
use of io.jans.orm.reflect.property.Getter in project jans by JanssenProject.
the class BaseEntryManager method getAttributeDataFromAttribute.
private AttributeData getAttributeDataFromAttribute(Object entry, Annotation ldapAttribute, PropertyAnnotation propertiesAnnotation, String propertyName) {
Class<?> entryClass = entry.getClass();
String ldapAttributeName = ((AttributeName) 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);
}
Class<?> parameterType = getSetterPropertyType(entryClass, propertyName);
boolean multiValued = isMultiValued(parameterType);
Annotation ldapJsonObject = ReflectHelper.getAnnotationByType(propertiesAnnotation.getAnnotations(), JsonObject.class);
boolean jsonObject = ldapJsonObject != null;
AttributeData attribute = getAttributeData(propertyName, ldapAttributeName, getter, entry, multiValued, jsonObject);
return attribute;
}
use of io.jans.orm.reflect.property.Getter 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.Getter 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.Getter in project jans by JanssenProject.
the class BaseEntryManager method getDNValue.
protected <T> Object getDNValue(Object entry, Class<T> entryClass) {
// Check if entry has DN property
String dnProperty = getDNPropertyName(entryClass);
// Get DN value
Getter dnGetter = getGetter(entryClass, dnProperty);
if (dnGetter == null) {
throw new MappingException("Entry should has getter for property " + dnProperty);
}
Object dnValue = dnGetter.get(entry);
if (StringHelper.isEmptyString(dnValue)) {
throw new MappingException("Entry should has not null base DN property value");
}
return dnValue;
}
Aggregations