use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class CouchbaseEntryManager method updateMergeChanges.
@Override
protected <T> void updateMergeChanges(String baseDn, T entry, boolean isConfigurationUpdate, Class<?> entryClass, Map<String, AttributeData> attributesFromDbMap, List<AttributeDataModification> attributeDataModifications, boolean forceUpdate) {
// Update object classes if entry contains custom object classes
if (!isConfigurationUpdate) {
String[] objectClasses = getObjectClasses(entry, entryClass);
if (ArrayHelper.isEmpty(objectClasses)) {
throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses to persist! Entry is invalid: '%s'", entry));
}
AttributeData objectClassAttributeData = attributesFromDbMap.get(OBJECT_CLASS.toLowerCase());
if (objectClassAttributeData == null) {
throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses in DB! Entry is invalid: '%s'", entry));
}
String[] objectClassesFromDb = objectClassAttributeData.getStringValues();
if (ArrayHelper.isEmpty(objectClassesFromDb)) {
throw new UnsupportedOperationException(String.format("There is no attribute with objectClasses in DB! Entry is invalid: '%s'", entry));
}
// We need to check only first element of each array because objectCLass in Couchbase is single value attribute
if (!StringHelper.equals(objectClassesFromDb[0], objectClasses[0])) {
attributeDataModifications.add(new AttributeDataModification(AttributeModificationType.REPLACE, new AttributeData(OBJECT_CLASS, objectClasses, false), new AttributeData(OBJECT_CLASS, objectClassesFromDb, false)));
}
}
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class CouchbaseEntryManager method createEntities.
protected <T> List<T> createEntities(Class<T> entryClass, List<PropertyAnnotation> propertiesAnnotations, ParsedKey baseDn, JsonObject... 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++;
JsonObject entry = searchResultEntries[i];
// String key = entry.getString(CouchbasegetOperationService().META_DOC_ID);
String dn = entry.getString(CouchbaseOperationService.DN);
entriesAttributes.put(dn, getAttributeDataList(entry));
// 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.model.AttributeData in project jans by JanssenProject.
the class CouchbaseEntryManager method getAttributeDataList.
private List<AttributeData> getAttributeDataList(JsonObject entry) {
if (entry == null) {
return null;
}
List<AttributeData> result = new ArrayList<AttributeData>();
for (String shortAttributeName : entry.getNames()) {
Object attributeObject = entry.get(shortAttributeName);
String attributeName = fromInternalAttribute(shortAttributeName);
Boolean multiValued = Boolean.FALSE;
Object[] attributeValueObjects;
if (attributeObject == null) {
attributeValueObjects = NO_OBJECTS;
}
if (attributeObject instanceof JsonArray) {
JsonArray jsonArray = (JsonArray) attributeObject;
ArrayList<Object> resultList = new ArrayList<Object>(jsonArray.size());
for (Iterator<Object> it = jsonArray.iterator(); it.hasNext(); ) {
resultList.add(it.next());
}
attributeValueObjects = resultList.toArray(NO_OBJECTS);
multiValued = Boolean.TRUE;
} else {
if ((attributeObject instanceof Boolean) || (attributeObject instanceof Integer) || (attributeObject instanceof Long) || (attributeObject instanceof JsonObject)) {
attributeValueObjects = new Object[] { attributeObject };
} else if (attributeObject instanceof String) {
// If it looks like date, treat as Date
Object valueAsDate = decodeTime(null, attributeObject.toString(), true);
Object value = valueAsDate == null ? attributeObject.toString() : valueAsDate;
attributeValueObjects = new Object[] { value };
} else {
Object value = attributeObject.toString();
attributeValueObjects = new Object[] { value };
}
}
unescapeValues(attributeValueObjects);
AttributeData tmpAttribute = new AttributeData(attributeName, attributeValueObjects);
if (multiValued != null) {
tmpAttribute.setMultiValued(multiValued);
}
result.add(tmpAttribute);
}
return result;
}
use of io.jans.orm.model.AttributeData in project jans by JanssenProject.
the class SpannerEntryManager 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(SpannerOperationService.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.model.AttributeData in project jans by JanssenProject.
the class LdapEntryManager method updateMergeChanges.
@Override
protected <T> void updateMergeChanges(String baseDn, T entry, boolean isConfigurationUpdate, Class<?> entryClass, Map<String, AttributeData> attributesFromLdapMap, List<AttributeDataModification> attributeDataModifications, boolean forceUpdate) {
// Update object classes if entry contains custom object classes
if (getSupportedLDAPVersion() > 2) {
if (!isConfigurationUpdate) {
String[] objectClasses = getObjectClasses(entry, entryClass);
String[] objectClassesFromLdap = attributesFromLdapMap.get(OBJECT_CLASS.toLowerCase()).getStringValues();
if (!Arrays.equals(objectClassesFromLdap, objectClasses)) {
attributeDataModifications.add(new AttributeDataModification(AttributeModificationType.REPLACE, new AttributeData(OBJECT_CLASS, objectClasses), new AttributeData(OBJECT_CLASS, objectClassesFromLdap)));
}
}
}
}
Aggregations