use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method setCustomObjectClasses.
protected void setCustomObjectClasses(Object entry, Class<?> entryClass, String[] objectClasses) {
List<PropertyAnnotation> customObjectAnnotations = getEntryCustomObjectClassAnnotations(entryClass);
for (PropertyAnnotation propertiesAnnotation : customObjectAnnotations) {
String propertyName = propertiesAnnotation.getPropertyName();
Setter setter = getSetter(entryClass, propertyName);
if (setter == null) {
throw new MappingException("Entry should has setter for property " + propertyName);
}
AttributeData attribute = new AttributeData(propertyName, objectClasses);
setPropertyValue(propertyName, setter, entry, attribute, false);
break;
}
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
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);
Integer expirationValue = getExpirationValue(entry, entryClass, false);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
// Add object classes
String[] objectClasses = getObjectClasses(entry, entryClass);
attributes.add(new AttributeData(OBJECT_CLASS, objectClasses, true));
LOG.debug(String.format("LDAP attributes for persist: %s", attributes));
persist(dnValue.toString(), objectClasses, attributes, expirationValue);
}
use of io.jans.orm.exception.MappingException 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.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method checkEntryClass.
protected boolean checkEntryClass(Class<?> entryClass, boolean isAllowSchemaEntry) {
if (entryClass == null) {
throw new MappingException("Entry class is null");
}
// Check if entry is LDAP Entry
List<Annotation> entryAnnotations = ReflectHelper.getClassAnnotations(entryClass, LDAP_ENTRY_TYPE_ANNOTATIONS);
Annotation ldapSchemaEntry = ReflectHelper.getAnnotationByType(entryAnnotations, SchemaEntry.class);
Annotation ldapEntry = ReflectHelper.getAnnotationByType(entryAnnotations, DataEntry.class);
if (isAllowSchemaEntry) {
if ((ldapSchemaEntry == null) && (ldapEntry == null)) {
throw new MappingException(String.format("Entry should has DataEntry or SchemaEntry annotation", entryClass));
}
} else {
if (ldapEntry == null) {
throw new MappingException(String.format("Entry '%s' should has DataEntry annotation", entryClass));
}
}
return true;
}
use of io.jans.orm.exception.MappingException 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;
}
Aggregations