private Map<String, AtlasObjectId> mapVertexToMapForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) { Map<String, AtlasObjectId> ret = null; Map softRefVal = entityVertex.getProperty(attribute.getVertexPropertyName(), Map.class); if (MapUtils.isNotEmpty(softRefVal)) { ret = new HashMap<>(); for (Object mapKey : softRefVal.keySet()) { AtlasObjectId objectId = getAtlasObjectIdFromSoftRefFormat(Objects.toString(softRefVal.get(mapKey)), attribute, entityExtInfo, isMinExtInfo); if (objectId != null) { ret.put(Objects.toString(mapKey), objectId); } } } return ret; }
private List<AtlasObjectId> mapVertexToArrayForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) { List<AtlasObjectId> ret = null; List softRefVal = entityVertex.getListProperty(attribute.getVertexPropertyName(), List.class); if (CollectionUtils.isNotEmpty(softRefVal)) { ret = new ArrayList<>(); for (Object o : softRefVal) { AtlasObjectId objectId = getAtlasObjectIdFromSoftRefFormat(Objects.toString(o), attribute, entityExtInfo, isMinExtInfo); if(objectId != null) { ret.add(objectId); } } } return ret; }
public String getQualifiedAttributePropertyKey(String attrName) throws AtlasBaseException { if ( allAttributes.containsKey(attrName)) { return allAttributes.get(attrName).getVertexPropertyName(); } throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_ATTRIBUTE, attrName, structDef.getName()); }
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }
public static AtlasVertex findByUniqueAttributes(AtlasEntityType entityType, Map<String, Object> attrValues) { AtlasVertex vertex = null; final Map<String, AtlasAttribute> uniqueAttributes = entityType.getUniqAttributes(); if (MapUtils.isNotEmpty(uniqueAttributes) && MapUtils.isNotEmpty(attrValues)) { for (AtlasAttribute attribute : uniqueAttributes.values()) { Object attrValue = attrValues.get(attribute.getName()); if (attrValue == null) { continue; } if (canUseIndexQuery(entityType, attribute.getName())) { vertex = AtlasGraphUtilsV2.getAtlasVertexFromIndexQuery(entityType, attribute, attrValue); } else { vertex = AtlasGraphUtilsV2.findByTypeAndPropertyName(entityType.getTypeName(), attribute.getVertexPropertyName(), attrValue); // if no instance of given typeName is found, try to find an instance of type's sub-type if (vertex == null && !entityType.getAllSubTypes().isEmpty()) { vertex = AtlasGraphUtilsV2.findBySuperTypeAndPropertyName(entityType.getTypeName(), attribute.getVertexPropertyName(), attrValue); } } if (vertex != null) { if (LOG.isDebugEnabled()) { LOG.debug("findByUniqueAttributes(type={}, attrName={}, attrValue={}: found vertex {}", entityType.getTypeName(), attribute.getName(), attrValue, vertex); } break; } } } return vertex; }
private Map<String, Object> mapVertexToMap(AtlasVertex entityVertex, AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute, AtlasAttribute attribute, final boolean isMinExtInfo) throws AtlasBaseException { Map<String, Object> ret = null; AtlasMapType mapType = (AtlasMapType) attribute.getAttributeType(); AtlasType mapValueType = mapType.getValueType(); if (LOG.isDebugEnabled()) { LOG.debug("Mapping map attribute {} for vertex {}", mapType.getTypeName(), entityVertex); } if (isReference(mapValueType)) { Map<String, Object> currentMap = getReferenceMap(entityVertex, attribute); if (MapUtils.isNotEmpty(currentMap)) { ret = new HashMap<>(); for (Map.Entry<String, Object> entry : currentMap.entrySet()) { String mapKey = entry.getKey(); Object keyValue = entry.getValue(); Object mapValue = mapVertexToCollectionEntry(entityVertex, mapValueType, keyValue, attribute.getRelationshipEdgeLabel(), entityExtInfo, isOwnedAttribute, attribute.getRelationshipEdgeDirection(), isMinExtInfo); if (mapValue != null) { ret.put(mapKey, mapValue); } } } } else { ret = getPrimitiveMap(entityVertex, attribute.getVertexPropertyName()); } if (MapUtils.isEmpty(ret)) { ret = null; } return ret; }
private AtlasEdge createRelationship(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException { AtlasEdge ret = null; try { ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName()); if (ret != null) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV2.getIdFromVertex(end1Vertex), AtlasGraphUtilsV2.getIdFromVertex(end2Vertex)); } AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); if (!relationType.hasLegacyAttributeEnd()) { // skip authorization for legacy attributes, as these would be covered as entity-update AtlasEntityHeader end1Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end1Vertex); AtlasEntityHeader end2Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end2Vertex); AtlasAuthorizationUtils.verifyAccess(new AtlasRelationshipAccessRequest(typeRegistry, AtlasPrivilege.RELATIONSHIP_ADD, relationship.getTypeName(), end1Entity, end2Entity)); } ret = createRelationshipEdge(end1Vertex, end2Vertex, relationship); if (MapUtils.isNotEmpty(relationType.getAllAttributes())) { for (AtlasAttribute attr : relationType.getAllAttributes().values()) { String attrName = attr.getName(); String attrVertexProperty = attr.getVertexPropertyName(); Object attrValue = relationship.getAttribute(attrName); AtlasGraphUtilsV2.setEncodedProperty(ret, attrVertexProperty, attrValue); } } } catch (RepositoryException e) { throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e); } return ret; }
private static AtlasVertex getAtlasVertexFromIndexQuery(AtlasEntityType entityType, AtlasAttribute attribute, Object attrVal) { String propertyName = attribute.getVertexPropertyName(); AtlasIndexQuery query = getIndexQuery(entityType, propertyName, attrVal.toString()); for (Iterator<AtlasIndexQuery.Result> iter = query.vertices(); iter.hasNext(); ) { AtlasIndexQuery.Result result = iter.next(); AtlasVertex vertex = result.getVertex(); // skip non-entity vertices, if any got returned if (vertex == null || !vertex.getPropertyKeys().contains(Constants.GUID_PROPERTY_KEY)) { continue; } // verify the typeName String typeNameInVertex = getTypeName(vertex); if (!entityType.getTypeAndAllSubTypes().contains(typeNameInVertex)) { LOG.warn("incorrect vertex type from index-query: expected='{}'; found='{}'", entityType.getTypeName(), typeNameInVertex); continue; } if (attrVal.getClass() == String.class) { String s = (String) attrVal; String vertexVal = vertex.getProperty(propertyName, String.class); if (!s.equalsIgnoreCase(vertexVal)) { LOG.warn("incorrect match from index-query for property {}: expected='{}'; found='{}'", propertyName, s, vertexVal); continue; } } return vertex; } return null; }
private static AtlasVertex getAtlasVertexFromIndexQuery(AtlasEntityType entityType, AtlasAttribute attribute, Object attrVal) { String propertyName = attribute.getVertexPropertyName(); AtlasIndexQuery query = getIndexQuery(entityType, propertyName, attrVal.toString()); for (Iterator<AtlasIndexQuery.Result> iter = query.vertices(); iter.hasNext(); ) { AtlasIndexQuery.Result result = iter.next(); AtlasVertex vertex = result.getVertex(); // skip non-entity vertices, if any got returned if (vertex == null || !vertex.getPropertyKeys().contains(Constants.GUID_PROPERTY_KEY)) { continue; } // verify the typeName String typeNameInVertex = getTypeName(vertex); if (!entityType.getTypeAndAllSubTypes().contains(typeNameInVertex)) { LOG.warn("incorrect vertex type from index-query: expected='{}'; found='{}'", entityType.getTypeName(), typeNameInVertex); continue; } if (attrVal.getClass() == String.class) { String s = (String) attrVal; String vertexVal = vertex.getProperty(propertyName, String.class); if (!s.equalsIgnoreCase(vertexVal)) { LOG.warn("incorrect match from index-query for property {}: expected='{}'; found='{}'", propertyName, s, vertexVal); continue; } } return vertex; } return null; }
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 AtlasRelationship updateRelationship(AtlasEdge relationshipEdge, AtlasRelationship relationship) throws AtlasBaseException { AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); AtlasVertex end1Vertex = relationshipEdge.getOutVertex(); AtlasVertex end2Vertex = relationshipEdge.getInVertex(); AtlasEntityHeader end1Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end1Vertex); AtlasEntityHeader end2Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end2Vertex); AtlasAuthorizationUtils.verifyAccess(new AtlasRelationshipAccessRequest(typeRegistry, AtlasPrivilege.RELATIONSHIP_UPDATE, relationship.getTypeName(), end1Entity, end2Entity)); updateTagPropagations(relationshipEdge, relationship); if (MapUtils.isNotEmpty(relationType.getAllAttributes())) { for (AtlasAttribute attr : relationType.getAllAttributes().values()) { String attrName = attr.getName(); String attrVertexProperty = attr.getVertexPropertyName(); if (relationship.hasAttribute(attrName)) { AtlasGraphUtilsV2.setEncodedProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName)); } } } return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge); }
private AtlasRelationship updateRelationship(AtlasEdge relationshipEdge, AtlasRelationship relationship) throws AtlasBaseException { AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); AtlasVertex end1Vertex = relationshipEdge.getOutVertex(); AtlasVertex end2Vertex = relationshipEdge.getInVertex(); AtlasEntityHeader end1Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end1Vertex); AtlasEntityHeader end2Entity = entityRetriever.toAtlasEntityHeaderWithClassifications(end2Vertex); AtlasAuthorizationUtils.verifyAccess(new AtlasRelationshipAccessRequest(typeRegistry, AtlasPrivilege.RELATIONSHIP_UPDATE, relationship.getTypeName(), end1Entity, end2Entity)); updateTagPropagations(relationshipEdge, relationship); if (MapUtils.isNotEmpty(relationType.getAllAttributes())) { for (AtlasAttribute attr : relationType.getAllAttributes().values()) { String attrName = attr.getName(); String attrVertexProperty = attr.getVertexPropertyName(); if (relationship.hasAttribute(attrName)) { AtlasGraphUtilsV2.setEncodedProperty(relationshipEdge, attrVertexProperty, relationship.getAttribute(attrName)); } } } return entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge); }
public AttributeMutationContext(EntityOperation op, AtlasVertex referringVertex, AtlasAttribute attribute, Object value) { this(op, referringVertex, attribute, value, attribute.getVertexPropertyName(), null, null); }
private void mapAttributes(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo) throws AtlasBaseException { AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); AtlasType objType = typeRegistry.getType(relationship.getTypeName()); if (!(objType instanceof AtlasRelationshipType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName()); } AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType; for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) { // mapping only primitive attributes Object attrValue = mapVertexToPrimitive(edge, attribute.getVertexPropertyName(), attribute.getAttributeDef()); relationship.setAttribute(attribute.getName(), attrValue); } } }
public AttributeMutationContext(EntityOperation op, AtlasVertex referringVertex, AtlasAttribute attribute, Object value) { this(op, referringVertex, attribute, value, attribute.getVertexPropertyName(), null, null); }
private void mapAttributes(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo) throws AtlasBaseException { AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); AtlasType objType = typeRegistry.getType(relationship.getTypeName()); if (!(objType instanceof AtlasRelationshipType)) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, relationship.getTypeName()); } AtlasRelationshipType relationshipType = (AtlasRelationshipType) objType; for (AtlasAttribute attribute : relationshipType.getAllAttributes().values()) { // mapping only primitive attributes Object attrValue = mapVertexToPrimitive(edge, attribute.getVertexPropertyName(), attribute.getAttributeDef()); relationship.setAttribute(attribute.getName(), attrValue); } } }
private AtlasObjectId mapVertexToObjectIdForSoftRef(AtlasVertex entityVertex, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) { String softRefVal = AtlasGraphUtilsV2.getEncodedProperty(entityVertex, attribute.getVertexPropertyName(), String.class); return StringUtils.isNotEmpty(softRefVal) ? getAtlasObjectIdFromSoftRefFormat(softRefVal, attribute, entityExtInfo, isMinExtInfo) : null; }
private AtlasVertex getGlossaryTermVertex(String termName) { AtlasVertex ret = null; if (StringUtils.isNotEmpty(termName)) { AtlasEntityType termType = getTermEntityType(); AtlasAttribute attrName = termType.getAttribute(TermSearchProcessor.ATLAS_GLOSSARY_TERM_ATTR_QNAME); AtlasGraphQuery query = graph.query().has(Constants.ENTITY_TYPE_PROPERTY_KEY, termType.getTypeName()) .has(attrName.getVertexPropertyName(), termName) .has(Constants.STATE_PROPERTY_KEY, AtlasEntity.Status.ACTIVE.name()); Iterator<AtlasVertex> results = query.vertices().iterator(); ret = results.hasNext() ? results.next() : null; } return ret; }
public static List<Object> getArrayElementsProperty(AtlasType elementType, AtlasVertex instanceVertex, AtlasAttribute attribute) { String propertyName = attribute.getVertexPropertyName(); if (isReference(elementType)) { return (List) getCollectionElementsUsingRelationship(instanceVertex, attribute); } else { return (List) instanceVertex.getListProperty(propertyName); } }
private String getVertexPropertyName(AtlasEntity entity, String attributeName) throws AtlasBaseException { AtlasEntityType type = (AtlasEntityType) typeRegistry.getType(entity.getTypeName()); AtlasStructType.AtlasAttribute attribute = type.getAttribute(attributeName); return attribute.getVertexPropertyName(); } }