private boolean isTraitType(AtlasType t) { return (t != null && t.getTypeCategory() == TypeCategory.CLASSIFICATION); }
private boolean isTraitType(AtlasType t) { return (t != null && t.getTypeCategory() == TypeCategory.CLASSIFICATION); }
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; }
public static boolean isReference(AtlasType type) { return isReference(type.getTypeCategory()); }
public static boolean isReference(AtlasType type) { return isReference(type.getTypeCategory()); }
void visitMapReferences(AtlasType keyType, AtlasType valueType, Object val) throws AtlasBaseException { if (keyType == null || valueType == null || val == null) { return; } if (isPrimitive(keyType.getTypeCategory()) && isPrimitive(valueType.getTypeCategory())) { return; } if (Map.class.isAssignableFrom(val.getClass())) { Iterator<Map.Entry> it = ((Map) val).entrySet().iterator(); while (it.hasNext()) { Map.Entry e = it.next(); visitAttribute(keyType, e.getKey()); visitAttribute(valueType, e.getValue()); } } }
void visitMapReferences(AtlasType keyType, AtlasType valueType, Object val) throws AtlasBaseException { if (keyType == null || valueType == null || val == null) { return; } if (isPrimitive(keyType.getTypeCategory()) && isPrimitive(valueType.getTypeCategory())) { return; } if (Map.class.isAssignableFrom(val.getClass())) { Iterator<Map.Entry> it = ((Map) val).entrySet().iterator(); while (it.hasNext()) { Map.Entry e = it.next(); visitAttribute(keyType, e.getKey()); visitAttribute(valueType, e.getValue()); } } }
void visitCollectionReferences(AtlasType elemType, Object val) throws AtlasBaseException { if (elemType == null || val == null || isPrimitive(elemType.getTypeCategory())) { return; } Iterator it = null; if (val instanceof Collection) { it = ((Collection) val).iterator(); } else if (val instanceof Iterable) { it = ((Iterable) val).iterator(); } else if (val instanceof Iterator) { it = (Iterator) val; } if (it != null) { while (it.hasNext()) { Object elem = it.next(); visitAttribute(elemType, elem); } } }
void visitCollectionReferences(AtlasType elemType, Object val) throws AtlasBaseException { if (elemType == null || val == null || isPrimitive(elemType.getTypeCategory())) { return; } Iterator it = null; if (val instanceof Collection) { it = ((Collection) val).iterator(); } else if (val instanceof Iterable) { it = ((Iterable) val).iterator(); } else if (val instanceof Iterator) { it = (Iterator) val; } if (it != null) { while (it.hasNext()) { Object elem = it.next(); visitAttribute(elemType, elem); } } }
private String getCollectionElementType(AtlasType elemType) { if(elemType.getTypeCategory() == TypeCategory.OBJECT_ID_TYPE) { return ((AtlasBuiltInTypes.AtlasObjectIdType)elemType).getObjectType(); } else { return elemType.getTypeName(); } }
private String getCollectionElementType(AtlasType elemType) { if(elemType.getTypeCategory() == TypeCategory.OBJECT_ID_TYPE) { return ((AtlasBuiltInTypes.AtlasObjectIdType)elemType).getObjectType(); } else { return elemType.getTypeName(); } }
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; }
@Override public AtlasType getType(String typeName) throws AtlasBaseException { AtlasType type; if(typeName.equals("PII") || typeName.equals("Dimension")) { type = mock(AtlasType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.CLASSIFICATION); } else { type = mock(AtlasEntityType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.ENTITY); } if(typeName.equals("PIII")) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND); } when(type.getTypeName()).thenReturn(typeName); return type; }
@Override public AtlasType getType(String typeName) throws AtlasBaseException { AtlasType type; if(typeName.equals("PII") || typeName.equals("Dimension")) { type = mock(AtlasType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.CLASSIFICATION); } else { type = mock(AtlasEntityType.class); when(type.getTypeCategory()).thenReturn(TypeCategory.ENTITY); } if(typeName.equals("PIII")) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND); } when(type.getTypeName()).thenReturn(typeName); return type; }
private Object mapCollectionElementsToVertex(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException { switch(ctx.getAttrType().getTypeCategory()) { case PRIMITIVE: case ENUM: case MAP: case ARRAY: return ctx.getValue(); case STRUCT: return mapStructValue(ctx, context); case OBJECT_ID_TYPE: AtlasEntityType instanceType = getInstanceType(ctx.getValue()); ctx.setElementType(instanceType); return mapObjectIdValueUsingRelationship(ctx, context); default: throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, ctx.getAttrType().getTypeCategory().name()); } }
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()); } } }
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()); } } }
private void mapAttribute(AtlasAttribute attribute, Object attrValue, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException { if (attrValue == null) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AtlasType attrType = attribute.getAttributeType(); if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) { if (attributeDef.getDefaultValue() != null) { attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue()); } else { if (attribute.getAttributeDef().getIsOptional()) { attrValue = attrType.createOptionalDefaultValue(); } else { attrValue = attrType.createDefaultValue(); } } } } AttributeMutationContext ctx = new AttributeMutationContext(op, vertex, attribute, attrValue); mapToVertexByTypeCategory(ctx, context); }
private void mapAttribute(AtlasAttribute attribute, Object attrValue, AtlasVertex vertex, EntityOperation op, EntityMutationContext context) throws AtlasBaseException { if (attrValue == null) { AtlasAttributeDef attributeDef = attribute.getAttributeDef(); AtlasType attrType = attribute.getAttributeType(); if (attrType.getTypeCategory() == TypeCategory.PRIMITIVE) { if (attributeDef.getDefaultValue() != null) { attrValue = attrType.createDefaultValue(attributeDef.getDefaultValue()); } else { if (attribute.getAttributeDef().getIsOptional()) { attrValue = attrType.createOptionalDefaultValue(); } else { attrValue = attrType.createDefaultValue(); } } } } AttributeMutationContext ctx = new AttributeMutationContext(op, vertex, attribute, attrValue); mapToVertexByTypeCategory(ctx, context); }