use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method findEntries.
@Override
@SuppressWarnings("unchecked")
public <T> List<T> findEntries(Object entry, int count) {
if (entry == null) {
throw new MappingException("Entry to find is null");
}
// Check entry class
Class<T> entryClass = (Class<T>) entry.getClass();
checkEntryClass(entryClass, false);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Object dnValue = getDNValue(entry, entryClass);
List<AttributeData> attributes = getAttributesListForPersist(entry, propertiesAnnotations);
Filter searchFilter = createFilterByEntry(entry, entryClass, attributes);
return findEntries(dnValue.toString(), entryClass, searchFilter, SearchScope.SUB, null, 0, count, DEFAULT_PAGINATION_SIZE);
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method getHashCode.
@Override
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 io.jans.orm.exception.MappingException 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;
}
use of io.jans.orm.exception.MappingException 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;
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class BaseEntryManager method getSetterPropertyType.
private <T> Class<?> getSetterPropertyType(Class<T> entry, String propertyName) {
Setter propertyValueSetter = getSetter(entry, propertyName);
if (propertyValueSetter == null) {
throw new MappingException("Entry should has setter for property " + propertyName);
}
Class<?> parameterType = ReflectHelper.getSetterType(propertyValueSetter);
return parameterType;
}
Aggregations