use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class CouchbaseEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
try {
// Load entry
ParsedKey keyWithInum = toCouchbaseKey(dn);
ScanConsistency scanConsistency = getScanConsistency(keyWithInum.getName(), propertiesAnnotationsMap);
JsonObject entry = getOperationService().lookup(keyWithInum.getKey(), scanConsistency, toInternalAttributes(ldapReturnAttributes));
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn));
}
use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class CouchbaseEntryManager method createEntities.
protected <T> List<T> createEntities(String baseDN, Class<T> entryClass, PagedResult<JsonObject> searchResult) {
ParsedKey keyWithInum = toCouchbaseKey(baseDN);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
List<T> entries = createEntities(entryClass, propertiesAnnotations, keyWithInum, searchResult.getEntries().toArray(new JsonObject[searchResult.getEntriesCount()]));
return entries;
}
use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class CouchbaseEntryManager method removeImpl.
protected <T> int removeImpl(String dn, Class<T> entryClass, Filter filter, int count) {
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", objectClasses.toString());
LOG.trace("Search filter: {}", searchFilter);
// Prepare properties types to allow build filter properly
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ParsedKey keyWithInum = toCouchbaseKey(dn);
ConvertedExpression convertedExpression;
try {
convertedExpression = toCouchbaseFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryDeleteException(String.format("Failed to convert filter %s to expression", searchFilter), ex);
}
try {
int processed = getOperationService().delete(keyWithInum.getKey(), getScanConsistency(convertedExpression), convertedExpression.expression(), count);
return processed;
} catch (Exception ex) {
throw new EntryDeleteException(String.format("Failed to delete entries with key: %s, expression: %s", keyWithInum.getKey(), convertedExpression), ex);
}
}
use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class SqlEntryManager method findEntriesImpl.
protected <T> PagedResult<EntryData> findEntriesImpl(String baseDN, Class<T> entryClass, Filter filter, SearchScope scope, String[] ldapReturnAttributes, String sortBy, SortOrder sortOrder, BatchOperation<T> batchOperation, SearchReturnDataType returnDataType, int start, int count, int chunkSize) {
// Check entry class
checkEntryClass(entryClass, false);
String[] objectClasses = getTypeObjectClasses(entryClass);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
}
Filter searchFilter;
if (objectClasses.length > 0) {
LOG.trace("Filter: {}", filter);
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
// Find entries
LOG.trace("-------------------------------------------------------");
LOG.trace("Filter: {}", filter);
LOG.trace("objectClasses count: {} ", objectClasses.length);
LOG.trace("objectClasses: {}", ArrayHelper.toString(objectClasses));
LOG.trace("Search filter: {}", searchFilter);
// Prepare default sort
OrderSpecifier<?>[] defaultSort = getDefaultSort(entryClass);
if (StringHelper.isNotEmpty(sortBy)) {
OrderSpecifier<?> requestedSort = buildSort(sortBy, sortOrder);
if (ArrayHelper.isEmpty(defaultSort)) {
defaultSort = new OrderSpecifier[] { requestedSort };
} else {
defaultSort = ArrayHelper.arrayMerge(new OrderSpecifier[] { requestedSort }, defaultSort);
}
}
// Prepare properties types to allow build filter properly
Map<String, PropertyAnnotation> propertiesAnnotationsMap = prepareEntryPropertiesTypes(entryClass, propertiesAnnotations);
ParsedKey keyWithInum = toSQLKey(baseDN);
ConvertedExpression convertedExpression;
try {
convertedExpression = toSqlFilter(searchFilter, propertiesAnnotationsMap);
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to convert filter '%s' to expression", searchFilter));
}
PagedResult<EntryData> searchResult = null;
try {
SqlBatchOperationWraper<T> batchOperationWraper = null;
if (batchOperation != null) {
batchOperationWraper = new SqlBatchOperationWraper<T>(batchOperation, this, entryClass, propertiesAnnotations);
}
searchResult = searchImpl(keyWithInum.getKey(), objectClasses[0], convertedExpression, scope, currentLdapReturnAttributes, defaultSort, batchOperationWraper, returnDataType, start, count, chunkSize);
if (searchResult == null) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression));
}
return searchResult;
} catch (SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s'", keyWithInum.getKey()), ex);
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with key: '%s', expression: '%s'", keyWithInum.getKey(), convertedExpression), ex);
}
}
use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class SqlEntryManager 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);
}
}
Aggregations