use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class SpannerEntryManager method createEntities.
protected <T> List<T> createEntities(String baseDN, Class<T> entryClass, PagedResult<EntryData> searchResult) {
ParsedKey keyWithInum = toSQLKey(baseDN);
List<PropertyAnnotation> propertiesAnnotations = getEntryPropertyAnnotations(entryClass);
List<T> entries = createEntities(entryClass, propertiesAnnotations, keyWithInum, searchResult.getEntries().toArray(new EntryData[searchResult.getEntriesCount()]));
return entries;
}
use of io.jans.orm.impl.model.ParsedKey in project jans by JanssenProject.
the class SpannerEntryManager method persist.
@Override
protected void persist(String dn, String[] objectClasses, List<AttributeData> attributes, Integer expiration) {
ArrayList<AttributeData> resultAttributes = new ArrayList<>(attributes.size() + 1);
for (AttributeData attribute : attributes) {
String attributeName = attribute.getName();
Object[] attributeValues = attribute.getValues();
Boolean multiValued = attribute.getMultiValued();
if (ArrayHelper.isNotEmpty(attributeValues) && (attributeValues[0] != null)) {
Object[] realValues = attributeValues;
// We need to store only one objectClass value in SQL
if (StringHelper.equalsIgnoreCase(SpannerOperationService.OBJECT_CLASS, attributeName)) {
if (!ArrayHelper.isEmpty(realValues)) {
realValues = new Object[] { realValues[0] };
multiValued = false;
}
}
// Process userPassword
if (StringHelper.equalsIgnoreCase(SpannerOperationService.USER_PASSWORD, attributeName)) {
realValues = getOperationService().createStoragePassword(StringHelper.toStringArray(attributeValues));
}
escapeValues(realValues);
AttributeData resultAttributeData;
if (Boolean.TRUE.equals(multiValued)) {
resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues, multiValued);
} else {
resultAttributeData = new AttributeData(toInternalAttribute(attributeName), realValues[0]);
}
resultAttributes.add(resultAttributeData);
}
}
// Persist entry
try {
ParsedKey parsedKey = toSQLKey(dn);
resultAttributes.add(new AttributeData(SpannerOperationService.DN, dn));
resultAttributes.add(new AttributeData(SpannerOperationService.DOC_ID, parsedKey.getKey()));
boolean result = getOperationService().addEntry(parsedKey.getKey(), objectClasses[0], resultAttributes);
if (!result) {
throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to persist entry: '%s'", dn), ex);
}
}
use of io.jans.orm.impl.model.ParsedKey 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.impl.model.ParsedKey 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.impl.model.ParsedKey in project jans by JanssenProject.
the class CouchbaseEntryManager method exportEntry.
@Override
public List<AttributeData> exportEntry(String dn) {
try {
// Load entry
ParsedKey keyWithInum = toCouchbaseKey(dn);
JsonObject entry = getOperationService().lookup(keyWithInum.getKey(), null);
List<AttributeData> result = getAttributeDataList(entry);
if (result != null) {
return result;
}
return null;
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
}
Aggregations