private static AtlasEdge getEdgeIfExists(AtlasMapType mapType, Map<String, Object> currentMap, String keyStr) { AtlasEdge ret = null; if (isReference(mapType.getValueType())) { Object val = currentMap.get(keyStr); if (val != null) { ret = (AtlasEdge) val; } } return ret; }
AtlasEntityType getReferencedEntityType(AtlasType type) { if (type instanceof AtlasArrayType) { type = ((AtlasArrayType)type).getElementType(); } if (type instanceof AtlasMapType) { type = ((AtlasMapType)type).getValueType(); } return type instanceof AtlasEntityType ? (AtlasEntityType)type : null; }
private static AtlasEdge getEdgeIfExists(AtlasMapType mapType, Map<String, Object> currentMap, String keyStr) { AtlasEdge ret = null; if (isReference(mapType.getValueType())) { Object val = currentMap.get(keyStr); if (val != null) { ret = (AtlasEdge) val; } } return ret; }
AtlasEntityType getReferencedEntityType(AtlasType type) { if (type instanceof AtlasArrayType) { type = ((AtlasArrayType)type).getElementType(); } if (type instanceof AtlasMapType) { type = ((AtlasMapType)type).getValueType(); } return type instanceof AtlasEntityType ? (AtlasEntityType)type : null; }
@Override public Map fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v1Obj != null) { if (v1Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v1Map = (Map)v1Obj; ret = new HashMap<>(); for (Object key : v1Map.keySet()) { Object value = v1Map.get(key); Object v2Key = keyConverter.fromV1ToV2(key, keyType, ctx); Object v2Value = valueConverter.fromV1ToV2(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v1Obj.getClass().getCanonicalName()); } } return ret; }
private Map<String, Object> removeUnusedMapEntries(AtlasAttribute attribute, AtlasVertex vertex, Map<String, Object> currentMap, Map<String, Object> newMap) throws AtlasBaseException { Map<String, Object> additionalMap = new HashMap<>(); AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); for (String currentKey : currentMap.keySet()) { //Delete the edge reference if its not part of new edges created/updated AtlasEdge currentEdge = (AtlasEdge) currentMap.get(currentKey); if (!newMap.values().contains(currentEdge)) { boolean deleted = deleteHandler.deleteEdgeReference(currentEdge, mapType.getValueType().getTypeCategory(), attribute.isOwnedRef(), true, vertex); if (!deleted) { additionalMap.put(currentKey, currentEdge); } } } return additionalMap; }
private Map<String, Object> removeUnusedMapEntries(AtlasAttribute attribute, AtlasVertex vertex, Map<String, Object> currentMap, Map<String, Object> newMap) throws AtlasBaseException { Map<String, Object> additionalMap = new HashMap<>(); AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); for (String currentKey : currentMap.keySet()) { //Delete the edge reference if its not part of new edges created/updated AtlasEdge currentEdge = (AtlasEdge) currentMap.get(currentKey); if (!newMap.values().contains(currentEdge)) { boolean deleted = deleteDelegate.getHandler().deleteEdgeReference(currentEdge, mapType.getValueType().getTypeCategory(), attribute.isOwnedRef(), true, vertex); if (!deleted) { additionalMap.put(currentKey, currentEdge); } } } return additionalMap; }
public static Map<String, Object> getMapElementsProperty(AtlasMapType mapType, AtlasVertex instanceVertex, String propertyName, AtlasAttribute attribute) { AtlasType mapValueType = mapType.getValueType(); if (isReference(mapValueType)) { return getReferenceMap(instanceVertex, attribute); } else { return (Map) instanceVertex.getProperty(propertyName, Map.class); } }
AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory());
@Override public Map fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException { Map ret = null; if (v1Obj != null) { if (v1Obj instanceof Map) { AtlasMapType mapType = (AtlasMapType)type; AtlasType keyType = mapType.getKeyType(); AtlasType valueType = mapType.getValueType(); AtlasFormatConverter keyConverter = converterRegistry.getConverter(keyType.getTypeCategory()); AtlasFormatConverter valueConverter = converterRegistry.getConverter(valueType.getTypeCategory()); Map v1Map = (Map)v1Obj; ret = new HashMap<>(); for (Object key : v1Map.keySet()) { Object value = v1Map.get(key); Object v2Key = keyConverter.fromV1ToV2(key, keyType, ctx); Object v2Value = valueConverter.fromV1ToV2(value, valueType, ctx); ret.put(v2Key, v2Value); } } else { throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map", v1Obj.getClass().getCanonicalName()); } } return ret; }
private boolean isRelationshipAttribute(AtlasAttribute attribute) throws AtlasBaseException { boolean ret = true; AtlasType attrType = attribute.getAttributeType(); if (attrType.getTypeCategory() == ARRAY) { attrType = ((AtlasArrayType) attrType).getElementType(); } else if (attrType.getTypeCategory() == MAP) { attrType = ((AtlasMapType) attrType).getValueType(); } if (attrType.getTypeCategory() != OBJECT_ID_TYPE) { ret = false; } return ret; }
private static void addIfCollectionAttribute(AtlasAttribute attr, Map<String, List<String>> collectionProperties) { AtlasType attrType = attr.getAttributeType(); TypeCategory attrTypeCategory = attrType.getTypeCategory(); switch (attrTypeCategory) { case ARRAY: { TypeCategory arrayElementType = ((AtlasArrayType) attrType).getElementType().getTypeCategory(); if (nonPrimitives.contains(arrayElementType)) { addVertexProperty(attrTypeCategory.toString(), attr.getVertexPropertyName(), collectionProperties); } } break; case MAP: { TypeCategory mapValueType = ((AtlasMapType) attrType).getValueType().getTypeCategory(); if (nonPrimitives.contains(mapValueType)) { addVertexProperty(attrTypeCategory.toString(), attr.getVertexPropertyName(), collectionProperties); } else { addVertexProperty(attrTypeCategory.toString() + "_PRIMITIVE", attr.getVertexPropertyName(), collectionProperties); } } break; } }
private void updateInConsistentOwnedMapVertices(AttributeMutationContext ctx, AtlasMapType mapType, Object val) { if (mapType.getValueType().getTypeCategory() == TypeCategory.OBJECT_ID_TYPE) { AtlasEdge edge = (AtlasEdge) val; if (ctx.getAttribute().isOwnedRef() && getStatus(edge) == DELETED && getStatus(edge.getInVertex()) == DELETED) { //Resurrect the vertex and edge to ACTIVE state AtlasGraphUtilsV2.setEncodedProperty(edge, STATE_PROPERTY_KEY, ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(edge.getInVertex(), STATE_PROPERTY_KEY, ACTIVE.name()); } } }
@Override public String getTypeFromEdge(GremlinQueryComposer.Context context, String item) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(item); if(attr == null) { return null; } AtlasType at = attr.getAttributeType(); switch (at.getTypeCategory()) { case ARRAY: AtlasArrayType arrType = ((AtlasArrayType)at); return getCollectionElementType(arrType.getElementType()); case MAP: AtlasMapType mapType = ((AtlasMapType)at); return getCollectionElementType(mapType.getValueType()); } return context.getActiveEntityType().getAttribute(item).getTypeName(); }
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); } }
private void updateInConsistentOwnedMapVertices(AttributeMutationContext ctx, AtlasMapType mapType, Object val) { if (mapType.getValueType().getTypeCategory() == TypeCategory.OBJECT_ID_TYPE && !ctx.getAttributeDef().isSoftReferenced()) { AtlasEdge edge = (AtlasEdge) val; if (ctx.getAttribute().isOwnedRef() && getStatus(edge) == DELETED && getStatus(edge.getInVertex()) == DELETED) { //Resurrect the vertex and edge to ACTIVE state AtlasGraphUtilsV2.setEncodedProperty(edge, STATE_PROPERTY_KEY, ACTIVE.name()); AtlasGraphUtilsV2.setEncodedProperty(edge.getInVertex(), STATE_PROPERTY_KEY, ACTIVE.name()); } } }
@Override public String getTypeFromEdge(GremlinQueryComposer.Context context, String item) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return ""; } AtlasStructType.AtlasAttribute attr = et.getAttribute(item); if(attr == null) { return null; } AtlasType at = attr.getAttributeType(); switch (at.getTypeCategory()) { case ARRAY: AtlasArrayType arrType = ((AtlasArrayType)at); return getCollectionElementType(arrType.getElementType()); case MAP: AtlasMapType mapType = ((AtlasMapType)at); return getCollectionElementType(mapType.getValueType()); } return context.getActiveEntityType().getAttribute(item).getTypeName(); }
@Override public boolean isPrimitive(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return false; } if(isSystemAttribute(attributeName)) { return true; } AtlasType at = et.getAttributeType(attributeName); if(at == null) { return false; } TypeCategory tc = at.getTypeCategory(); if (isPrimitiveUsingTypeCategory(tc)) return true; if ((tc != null) && (tc == TypeCategory.ARRAY)) { AtlasArrayType ct = ((AtlasArrayType)at); return isPrimitiveUsingTypeCategory(ct.getElementType().getTypeCategory()); } if ((tc != null) && (tc == TypeCategory.MAP)) { AtlasMapType ct = ((AtlasMapType)at); return isPrimitiveUsingTypeCategory(ct.getValueType().getTypeCategory()); } return false; }
@Override public boolean isPrimitive(GremlinQueryComposer.Context context, String attributeName) { AtlasEntityType et = context.getActiveEntityType(); if(et == null) { return false; } if(isSystemAttribute(attributeName)) { return true; } AtlasType at = et.getAttributeType(attributeName); if(at == null) { return false; } TypeCategory tc = at.getTypeCategory(); if (isPrimitiveUsingTypeCategory(tc)) return true; if ((tc != null) && (tc == TypeCategory.ARRAY)) { AtlasArrayType ct = ((AtlasArrayType)at); return isPrimitiveUsingTypeCategory(ct.getElementType().getTypeCategory()); } if ((tc != null) && (tc == TypeCategory.MAP)) { AtlasMapType ct = ((AtlasMapType)at); return isPrimitiveUsingTypeCategory(ct.getValueType().getTypeCategory()); } return false; }
private void addType(AtlasType type, ExportService.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); } else if (type instanceof AtlasRelationshipType) { addRelationshipType((AtlasRelationshipType)type, context); } }