use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.
the class AbstractEntryManager 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, LdapSchemaEntry.class);
Annotation ldapEntry = ReflectHelper.getAnnotationByType(entryAnnotations, LdapEntry.class);
if (isAllowSchemaEntry) {
if ((ldapSchemaEntry == null) && (ldapEntry == null)) {
throw new MappingException("Entry should has LdapEntry or LdapSchemaEntry annotation");
}
} else {
if (ldapEntry == null) {
throw new MappingException("Entry should has LdapEntry annotation");
}
}
return true;
}
use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.
the class AbstractEntryManager 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.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.
the class AbstractEntryManager method persist.
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);
String[] objectClasses = getObjectClasses(entry, entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Object dnValue = getDNValue(entry, entryClass);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
// Add object classes
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.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.
the class AbstractEntryManager method getHashCode.
public int getHashCode(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);
String key = getEntryKey(dnValue, false, propertiesAnnotations, attributes);
if (log.isDebugEnabled()) {
log.debug(String.format("Entry key HashCode is: %s", key.hashCode()));
}
return key.hashCode();
}
use of org.gluu.site.ldap.persistence.exception.MappingException in project oxCore by GluuFederation.
the class AbstractEntryManager method getAttributesFromLdapAttributesList.
private List<AttributeData> getAttributesFromLdapAttributesList(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 = ((LdapAttributesList) ldapAttribute).name();
Getter entryPropertyNameGetter = getGetter(elementType, entryPropertyName);
if (entryPropertyNameGetter == null) {
throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyName);
}
String entryPropertyValue = ((LdapAttributesList) ldapAttribute).value();
Getter entryPropertyValueGetter = getGetter(elementType, entryPropertyValue);
if (entryPropertyValueGetter == null) {
throw new MappingException("Entry should has getter for property " + propertyName + "." + entryPropertyValue);
}
for (Object entryAttribute : (List<?>) propertyValue) {
AttributeData attribute = getAttribute(propertyName, entryPropertyNameGetter, entryPropertyValueGetter, entryAttribute, false);
if (attribute != null) {
listAttributes.add(attribute);
}
}
return listAttributes;
}
Aggregations