use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SpannerEntryManager method contains.
@Override
protected <T> boolean contains(String baseDN, String[] objectClasses, Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, Filter filter, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to check contain entries is null");
}
// Create filter
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
String key = toSQLKey(baseDN).getKey();
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
PagedResult<EntryData> searchResult = null;
try {
searchResult = searchImpl(key, objectClasses[0], convertedExpression, SearchScope.SUB, ldapReturnAttributes, null, null, SearchReturnDataType.SEARCH, 0, 1, 0);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: '%s', filter: '%s'", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: '%s', filter: '%s'", baseDN, searchFilter), ex);
}
return (searchResult != null) && (searchResult.getEntriesCount() > 0);
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SpannerEntryManager method countEntries.
@Override
public <T> int countEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
String key = toSQLKey(baseDN).getKey();
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(key, objectClasses[0], searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
PagedResult<EntryData> searchResult;
try {
searchResult = searchImpl(toSQLKey(baseDN).getKey(), objectClasses[0], convertedExpression, scope, null, null, null, SearchReturnDataType.COUNT, 0, 0, 0);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: '%s', filter: '%s'", baseDN, searchFilter), ex);
}
return searchResult.getTotalEntriesCount();
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SpannerEntryManager method exportEntry.
@Override
public List<AttributeData> exportEntry(String dn, String objectClass) {
if (StringHelper.isEmpty(objectClass)) {
throw new MappingException("Object class isn't defined!");
}
try {
// Load entry
ParsedKey keyWithInum = toSQLKey(dn);
List<AttributeData> entry = getOperationService().lookup(keyWithInum.getKey(), objectClass);
if (entry != null) {
return entry;
}
return null;
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: '%s'", dn), ex);
}
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class CouchbaseEntryManager method contains.
@Override
protected <T> boolean contains(String baseDN, String[] objectClasses, Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, Filter filter, String[] ldapReturnAttributes) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to check contain entries is null");
}
// Create filter
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult = null;
try {
ParsedKey keyWithInum = toCouchbaseKey(baseDN);
searchResult = searchImpl(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), SearchScope.SUB, ldapReturnAttributes, null, null, SearchReturnDataType.SEARCH, 1, 1, 0);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
return (searchResult != null) && (searchResult.getEntriesCount() > 0);
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class CouchbaseEntryManager method countEntries.
@Override
public <T> int countEntries(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope) {
if (StringHelper.isEmptyString(baseDN)) {
throw new MappingException("Base DN to find entries is null");
}
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter %s to expression", searchFilter));
}
PagedResult<JsonObject> searchResult;
try {
searchResult = searchImpl(toCouchbaseKey(baseDN).getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), scope, null, null, null, SearchReturnDataType.COUNT, 0, 0, 0);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to calculate the number of entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
return searchResult.getTotalEntriesCount();
}
Aggregations