use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.
the class EntityGraphMapper method mapArrayValue.
public List mapArrayValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> mapArrayValue({})", ctx);
}
AtlasAttribute attribute = ctx.getAttribute();
List newElements = (List) ctx.getValue();
AtlasArrayType arrType = (AtlasArrayType) attribute.getAttributeType();
AtlasType elementType = arrType.getElementType();
List<Object> currentElements = getArrayElementsProperty(elementType, ctx.getReferringVertex(), ctx.getVertexProperty());
boolean isReference = AtlasGraphUtilsV1.isReference(elementType);
AtlasAttribute inverseRefAttribute = attribute.getInverseRefAttribute();
List<Object> newElementsCreated = new ArrayList<>();
if (CollectionUtils.isNotEmpty(newElements)) {
for (int index = 0; index < newElements.size(); index++) {
AtlasEdge existingEdge = getEdgeAt(currentElements, index, elementType);
AttributeMutationContext arrCtx = new AttributeMutationContext(ctx.getOp(), ctx.getReferringVertex(), ctx.getAttribute(), newElements.get(index), ctx.getVertexProperty(), elementType, existingEdge);
Object newEntry = mapCollectionElementsToVertex(arrCtx, context);
if (isReference && newEntry instanceof AtlasEdge && inverseRefAttribute != null) {
// Update the inverse reference value.
AtlasEdge newEdge = (AtlasEdge) newEntry;
addInverseReference(arrCtx, inverseRefAttribute, newEdge);
}
newElementsCreated.add(newEntry);
}
}
if (isReference) {
List<AtlasEdge> additionalEdges = removeUnusedArrayEntries(attribute, (List) currentElements, (List) newElementsCreated);
newElementsCreated.addAll(additionalEdges);
}
// for dereference on way out
setArrayElementsProperty(elementType, ctx.getReferringVertex(), ctx.getVertexProperty(), newElementsCreated);
if (LOG.isDebugEnabled()) {
LOG.debug("<== mapArrayValue({})", ctx);
}
return newElementsCreated;
}
use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.
the class ExportService method addType.
private void addType(AtlasType type, ExportContext context) {
if (type.getTypeCategory() == TypeCategory.PRIMITIVE) {
return;
}
if (type instanceof AtlasArrayType) {
AtlasArrayType arrayType = (AtlasArrayType) type;
addType(arrayType.getElementType(), context);
} else if (type instanceof AtlasMapType) {
AtlasMapType mapType = (AtlasMapType) type;
addType(mapType.getKeyType(), context);
addType(mapType.getValueType(), context);
} else if (type instanceof AtlasEntityType) {
addEntityType((AtlasEntityType) type, context);
} else if (type instanceof AtlasClassificationType) {
addClassificationType((AtlasClassificationType) type, context);
} else if (type instanceof AtlasStructType) {
addStructType((AtlasStructType) type, context);
} else if (type instanceof AtlasEnumType) {
addEnumType((AtlasEnumType) type, context);
}
}
use of org.apache.atlas.type.AtlasArrayType in project incubator-atlas by apache.
the class AtlasArrayFormatConverter method fromV1ToV2.
@Override
public Collection fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
Collection ret = null;
if (v1Obj != null) {
if (v1Obj instanceof Set) {
ret = new LinkedHashSet();
} else {
ret = new ArrayList();
}
AtlasArrayType arrType = (AtlasArrayType) type;
AtlasType elemType = arrType.getElementType();
AtlasFormatConverter elemConverter = converterRegistry.getConverter(elemType.getTypeCategory());
if (v1Obj instanceof Collection) {
Collection v1List = (Collection) v1Obj;
for (Object v1Elem : v1List) {
Object convertedVal = elemConverter.fromV1ToV2(v1Elem, elemType, ctx);
ret.add(convertedVal);
}
} else {
Object convertedVal = elemConverter.fromV1ToV2(v1Obj, elemType, ctx);
ret.add(convertedVal);
}
}
return ret;
}
Aggregations