use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class SqlEntryManager method find.
@Override
protected List<AttributeData> find(String dn, String[] objectClasses, Map<String, PropertyAnnotation> propertiesAnnotationsMap, String... ldapReturnAttributes) {
try {
// Load entry
ParsedKey keyWithInum = toSQLKey(dn);
List<AttributeData> result = getOperationService().lookup(keyWithInum.getKey(), objectClasses[0], toInternalAttributes(ldapReturnAttributes));
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.exception.EntryPersistenceException in project jans by JanssenProject.
the class SqlEntryManager 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(SqlOperationService.OBJECT_CLASS, attributeName)) {
if (!ArrayHelper.isEmpty(realValues)) {
realValues = new Object[] { realValues[0] };
multiValued = false;
}
}
// Process userPassword
if (StringHelper.equalsIgnoreCase(SqlOperationService.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(SqlOperationService.DN, dn));
resultAttributes.add(new AttributeData(SqlOperationService.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.exception.EntryPersistenceException in project jans by JanssenProject.
the class StatService method createBranch.
public void createBranch(String branchDn, String ou) {
try {
SimpleBranch branch = new SimpleBranch();
branch.setOrganizationalUnitName(ou);
branch.setDn(branchDn);
entryManager.persist(branch);
} catch (EntryPersistenceException ex) {
// Check if another process added this branch already
if (!entryManager.contains(branchDn, SimpleBranch.class)) {
throw ex;
}
}
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class LdapEntryManager method findEntriesVirtualListView.
@Deprecated
public <T> List<T> findEntriesVirtualListView(String baseDN, Class<T> entryClass, Filter filter, int start, int count, String sortBy, SortOrder sortOrder, PagedResult vlvResponse, String[] ldapReturnAttributes) {
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);
String[] currentLdapReturnAttributes = ldapReturnAttributes;
if (ArrayHelper.isEmpty(currentLdapReturnAttributes)) {
currentLdapReturnAttributes = getAttributes(null, propertiesAnnotations, false);
}
// Find entries
Filter searchFilter;
if (objectClasses.length > 0) {
searchFilter = addObjectClassFilter(filter, objectClasses);
} else {
searchFilter = filter;
}
SearchResult searchResult = null;
try {
searchResult = getOperationService().searchVirtualListView(baseDN, toLdapFilter(searchFilter), toLdapSearchScope(SearchScope.SUB), start, count, sortBy, sortOrder, vlvResponse, currentLdapReturnAttributes);
if (!ResultCode.SUCCESS.equals(searchResult.getResultCode())) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter));
}
} catch (Exception ex) {
throw new EntryPersistenceException(String.format("Failed to find entries with baseDN: %s, filter: %s", baseDN, searchFilter), ex);
}
if (searchResult.getEntryCount() == 0) {
return new ArrayList<T>(0);
}
List<T> entries = createEntitiesVirtualListView(entryClass, propertiesAnnotations, searchResult.getSearchEntries().toArray(new SearchResultEntry[searchResult.getSearchEntries().size()]));
return entries;
}
use of io.jans.orm.exception.EntryPersistenceException in project jans by JanssenProject.
the class LdapEntryManager method exportEntry.
@Override
public List<AttributeData> exportEntry(String dn) {
try {
SearchResultEntry searchResultEntry = getOperationService().lookup(dn, (String[]) null);
List<AttributeData> result = getAttributeDataList(searchResultEntry);
if (result != null) {
return result;
}
return null;
} catch (ConnectionException | SearchException ex) {
throw new EntryPersistenceException(String.format("Failed to find entry: %s", dn), ex);
}
}
Aggregations