Skip to content

Commit a6faa17

Browse files
committed
MLH-1226 Handle add list/set property value methods
1 parent e75eff6 commit a6faa17

File tree

2 files changed

+69
-1
lines changed

2 files changed

+69
-1
lines changed

graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusElement.java

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ public boolean isIdAssigned() {
335335
return true;
336336
}
337337

338-
private void recordInternalAttribute(String propertyName, Object finalValue) {
338+
protected void recordInternalAttribute(String propertyName, Object finalValue) {
339339
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
340340
RequestContext context = RequestContext.get();
341341
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
@@ -351,4 +351,69 @@ private void recordInternalAttribute(String propertyName, Object finalValue) {
351351
}
352352
}
353353
}
354+
355+
protected void recordInternalAttributeIncrementalAdd(String propertyName, Object value, Class cardinality) {
356+
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
357+
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
358+
359+
if (StringUtils.isNotEmpty(entityGuid)) {
360+
Collection<Object> currentValues = null;
361+
362+
if (cardinality == List.class) {
363+
currentValues = getMultiValuedProperty(propertyName, Object.class);
364+
} else {
365+
currentValues = getMultiValuedSetProperty(propertyName, Object.class);
366+
}
367+
368+
// Assumption: This method is being called after setting the property on element,
369+
// hence assuming currentValues is the final expected state and not adding `value` to `currentValues`
370+
371+
if (StringUtils.isNotEmpty(entityGuid)) {
372+
RequestContext context = RequestContext.get();
373+
374+
if (context.getAllInternalAttributesMap().get(entityGuid) != null) {
375+
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, currentValues);
376+
} else {
377+
Map<String, Object> map = new HashMap<>();
378+
map.put(propertyName, currentValues);
379+
context.getAllInternalAttributesMap().put(entityGuid, map);
380+
}
381+
}
382+
}
383+
}
384+
}
385+
386+
protected void recordInternalAttributeIncremental2(String propertyName, Object value, Class cardinality) {
387+
if (propertyName.startsWith(INTERNAL_PROPERTY_KEY_PREFIX)) {
388+
RequestContext context = RequestContext.get();
389+
String entityGuid = this.getProperty(GUID_PROPERTY_KEY, String.class);
390+
Collection<Object> values = null;
391+
392+
if (cardinality == List.class) {
393+
values = new ArrayList<>();
394+
} else {
395+
values = new HashSet<>();
396+
}
397+
398+
if (StringUtils.isNotEmpty(entityGuid)) {
399+
if (context.getAllInternalAttributesMap().get(entityGuid) != null) {
400+
Collection<Object> currentValueInRecord = (Collection) context.getAllInternalAttributesMap().get(entityGuid).get(propertyName);
401+
402+
if (currentValueInRecord == null) {
403+
values.add(value);
404+
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, values);
405+
} else {
406+
currentValueInRecord.add(value);
407+
context.getAllInternalAttributesMap().get(entityGuid).put(propertyName, currentValueInRecord);
408+
}
409+
} else {
410+
values.add(value);
411+
412+
Map<String, Object> map = new HashMap<>();
413+
map.put(propertyName, values);
414+
context.getAllInternalAttributesMap().put(entityGuid, map);
415+
}
416+
}
417+
}
418+
}
354419
}

graphdb/janus/src/main/java/org/apache/atlas/repository/graphdb/janus/AtlasJanusVertex.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Collection;
2222
import java.util.Iterator;
23+
import java.util.List;
2324
import java.util.Set;
2425
import java.util.stream.StreamSupport;
2526

@@ -55,6 +56,7 @@ public AtlasJanusVertex(AtlasJanusGraph graph, Vertex source) {
5556
public <T> void addProperty(String propertyName, T value) {
5657
try {
5758
getWrappedElement().property(VertexProperty.Cardinality.set, propertyName, value);
59+
recordInternalAttributeIncrementalAdd(propertyName, value, Set.class);
5860
} catch(SchemaViolationException e) {
5961
throw new AtlasSchemaViolationException(e);
6062
}
@@ -64,6 +66,7 @@ public <T> void addProperty(String propertyName, T value) {
6466
public <T> void addListProperty(String propertyName, T value) {
6567
try {
6668
getWrappedElement().property(VertexProperty.Cardinality.list, propertyName, value);
69+
recordInternalAttributeIncrementalAdd(propertyName, value, List.class);
6770
} catch(SchemaViolationException e) {
6871
throw new AtlasSchemaViolationException(e);
6972
}

0 commit comments

Comments
 (0)