use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SqlOperationServiceImpl method convertDbJsonToValue.
private Object[] convertDbJsonToValue(String jsonValue) {
try {
// Object[] values = JSON_OBJECT_MAPPER.readValue(jsonValue, Object[].class);
JsonAttributeValue attributeValue = JSON_OBJECT_MAPPER.readValue(jsonValue, JsonAttributeValue.class);
Object[] values = null;
if (attributeValue != null) {
values = attributeValue.getValues();
}
return values;
} catch (Exception ex) {
LOG.error("Failed to convert json value '{}' to array:", jsonValue, ex);
throw new MappingException(String.format("Failed to convert json value '%s' to array", jsonValue));
}
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SqlOperationServiceImpl method convertValueToDbJson.
private String convertValueToDbJson(Object propertyValue) {
try {
// String value = JSON_OBJECT_MAPPER.writeValueAsString(propertyValue);
JsonAttributeValue attributeValue;
if (propertyValue == null) {
attributeValue = new JsonAttributeValue();
}
if (propertyValue instanceof List) {
attributeValue = new JsonAttributeValue(((List) propertyValue).toArray());
} else if (propertyValue.getClass().isArray()) {
attributeValue = new JsonAttributeValue((Object[]) propertyValue);
} else {
attributeValue = new JsonAttributeValue(new Object[] { propertyValue });
}
String value = JSON_OBJECT_MAPPER.writeValueAsString(attributeValue);
return value;
} catch (Exception ex) {
LOG.error("Failed to convert '{}' to json value:", propertyValue, ex);
throw new MappingException(String.format("Failed to convert '%s' to json value", propertyValue));
}
}
use of io.jans.orm.exception.MappingException in project jans by JanssenProject.
the class SqlEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, ParsedKey baseDn, EntryData... searchResultEntries) {
List<T> result = new ArrayList<T>(searchResultEntries.length);
Map<String, List<AttributeData>> entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
int count = 0;
for (int i = 0; i < searchResultEntries.length; i++) {
count++;
EntryData entryData = searchResultEntries[i];
AttributeData attributeDataDn = entryData.getAttributeDate(SqlOperationService.DN);
if ((attributeDataDn == null) || (attributeDataDn.getValue() == null)) {
throw new MappingException("Failed to convert EntryData to Entry because DN is missing");
}
entriesAttributes.put(attributeDataDn.getValue().toString(), entryData.getAttributeData());
// Remove reference to allow java clean up object
searchResultEntries[i] = null;
// Allow java to clean up temporary objects
if (count >= 100) {
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
entriesAttributes = new LinkedHashMap<String, List<AttributeData>>(100);
count = 0;
}
}
List<T> currentResult = createEntities(entryClass, propertiesAnnotations, entriesAttributes);
result.addAll(currentResult);
return result;
}
use of io.jans.orm.exception.MappingException 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);
}
}
use of io.jans.orm.exception.MappingException 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;
}
Aggregations