@Override public boolean areEqualValues(Object val1, Object val2) { final boolean ret; if (val1 == null) { ret = val2 == null; } else if (val2 == null) { ret = false; } else { AtlasRelationship rel1 = getRelationshipFromValue(val1); if (rel1 == null) { ret = false; } else { AtlasRelationship rel2 = getRelationshipFromValue(val2); if (rel2 == null) { ret = false; } else if (!super.areEqualValues(rel1, rel2)) { ret = false; } else { ret = Objects.equals(rel1.getGuid(), rel2.getGuid()) && Objects.equals(rel1.getEnd1(), rel2.getEnd1()) && Objects.equals(rel1.getEnd2(), rel2.getEnd2()) && Objects.equals(rel1.getLabel(), rel2.getLabel()) && Objects.equals(rel1.getPropagateTags(), rel2.getPropagateTags()) && Objects.equals(rel1.getStatus(), rel2.getStatus()); } } } return ret; }
@Override @GraphTransaction public AtlasRelationship create(AtlasRelationship relationship) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> create({})", relationship); } AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1()); AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2()); validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes()); AtlasEdge edge = createRelationship(end1Vertex, end2Vertex, relationship); AtlasRelationship ret = edge != null ? entityRetriever.mapEdgeToAtlasRelationship(edge) : null; if (LOG.isDebugEnabled()) { LOG.debug("<== create({}): {}", relationship, ret); } // notify entities for added/removed classification propagation entityChangeNotifier.notifyPropagatedEntities(); return ret; }
private void init(String guid, String homeId, AtlasObjectId end1, AtlasObjectId end2, String label, PropagateTags propagateTags, Status status, String createdBy, String updatedBy, Date createTime, Date updateTime, Long version, Set<AtlasClassification> propagatedClassifications, Set<AtlasClassification> blockedPropagatedClassifications) { setGuid(guid); setHomeId(homeId); setEnd1(end1); setEnd2(end2); setLabel(label); setPropagateTags(propagateTags); setStatus(status); setCreatedBy(createdBy); setUpdatedBy(updatedBy); setCreateTime(createTime); setUpdateTime(updateTime); setVersion(version); setPropagatedClassifications(propagatedClassifications); setBlockedPropagatedClassifications(blockedPropagatedClassifications); }
public AtlasRelationshipHeader(AtlasRelationship relationship) { this(relationship.getTypeName(), relationship.getGuid(), relationship.getEnd1(), relationship.getEnd2()); setLabel(relationship.getLabel()); switch (relationship.getStatus()) { case ACTIVE: setStatus(AtlasEntity.Status.ACTIVE); break; case DELETED: setStatus(AtlasEntity.Status.DELETED); break; } }
@Override public AtlasRelationship getOrCreate(AtlasRelationship relationship) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> getOrCreate({})", relationship); } validateRelationship(relationship); AtlasVertex end1Vertex = getVertexFromEndPoint(relationship.getEnd1()); AtlasVertex end2Vertex = getVertexFromEndPoint(relationship.getEnd2()); AtlasRelationship ret = null; // check if relationship exists AtlasEdge relationshipEdge = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName()); if (relationshipEdge == null) { validateRelationship(relationship); relationshipEdge = createRelationship(end1Vertex, end2Vertex, relationship); } if (relationshipEdge != null){ ret = entityRetriever.mapEdgeToAtlasRelationship(relationshipEdge); } if (LOG.isDebugEnabled()) { LOG.debug("<== getOrCreate({}): {}", relationship, ret); } return ret; }
validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes()); String relationshipLabel = getRelationshipEdgeLabel(end1Vertex, end2Vertex, relationship.getTypeName()); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_ALREADY_EXISTS, relationship.getTypeName(), AtlasGraphUtilsV2.getIdFromVertex(end1Vertex), AtlasGraphUtilsV2.getIdFromVertex(end2Vertex)); AtlasRelationshipType relationType = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); relationship.getTypeName(), end1Entity, end2Entity)); String relationshipGuid = relationship.getGuid(); PropagateTags tagPropagation = getRelationshipTagPropagation(end1Vertex, end2Vertex, relationship); final String guid = AtlasTypeUtil.isAssignedGuid(relationshipGuid) ? relationshipGuid : UUID.randomUUID().toString(); AtlasGraphUtilsV2.setEncodedProperty(ret, ENTITY_TYPE_PROPERTY_KEY, relationship.getTypeName()); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIP_GUID_PROPERTY_KEY, guid); AtlasGraphUtilsV2.setEncodedProperty(ret, HOME_ID_KEY, relationship.getHomeId()); AtlasGraphUtilsV2.setEncodedProperty(ret, VERSION_PROPERTY_KEY, getRelationshipVersion(relationship)); AtlasGraphUtilsV2.setEncodedProperty(ret, PROVENANCE_TYPE_KEY, relationship.getProvenanceType()); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, tagPropagation.name()); handleBlockedClassifications(ret, relationship.getBlockedPropagatedClassifications()); String attrName = attr.getName(); String attrVertexProperty = attr.getVertexPropertyName(); Object attrValue = relationship.getAttribute(attrName);
process3_employee_union_relationship.setBlockedPropagatedClassifications(new HashSet<>(Arrays.asList(PII_tag3))); relationshipStore.update(process3_employee_union_relationship); Set<AtlasClassification> propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications(); Set<AtlasClassification> blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications(); process3_employee_union_relationship.setBlockedPropagatedClassifications(Collections.emptySet()); relationshipStore.update(process3_employee_union_relationship); propagatedClassifications = process3_employee_union_relationship.getPropagatedClassifications(); blockedClassifications = process3_employee_union_relationship.getBlockedPropagatedClassifications();
private AtlasRelatedObjectId mapVertexToRelatedObjectId(AtlasVertex entityVertex, AtlasEdge edge) throws AtlasBaseException { AtlasRelatedObjectId ret = null; if (GraphHelper.elementExists(edge)) { AtlasVertex referenceVertex = edge.getInVertex(); if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) { referenceVertex = edge.getOutVertex(); } if (referenceVertex != null) { String entityTypeName = getTypeName(referenceVertex); String entityGuid = getGuid(referenceVertex); AtlasEntity.Status entityStatus = GraphHelper.getStatus(referenceVertex); AtlasRelationship relationship = mapEdgeToAtlasRelationship(edge); ret = new AtlasRelatedObjectId(entityGuid, entityTypeName, entityStatus, relationship.getGuid(), relationship.getStatus(), new AtlasStruct(relationship.getTypeName(), relationship.getAttributes())); Object displayText = getDisplayText(referenceVertex, entityTypeName); if (displayText != null) { ret.setDisplayText(displayText.toString()); } } } return ret; }
private AtlasRelationship getRelationshipFromValue(Object val) { final AtlasRelationship ret; if (val instanceof AtlasRelationship) { ret = (AtlasRelationship) val; } else if (val instanceof Map) { ret = new AtlasRelationship((Map) val); } else { ret = null; } return ret; } }
assertEquals(employees2_process_relationship.getPropagateTags(), TWO_TO_ONE); employees2_process_relationship.setPropagateTags(NONE); relationshipStore.update(employees2_process_relationship); assertEquals(employees2_process_relationship.getPropagateTags(), NONE); employees2_process_relationship.setPropagateTags(TWO_TO_ONE); relationshipStore.update(employees2_process_relationship); assertEquals(process3_employee_union_relationship.getPropagateTags(), ONE_TO_TWO); process3_employee_union_relationship.setPropagateTags(BOTH); relationshipStore.update(process3_employee_union_relationship); process3_employee_union_relationship.setPropagateTags(ONE_TO_TWO); relationshipStore.update(process3_employee_union_relationship); assertClassificationNotExistInEntity(EMPLOYEES_UNION_PROCESS, tag4);
private AtlasEdge createRelationshipEdge(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) throws RepositoryException, AtlasBaseException { String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationship.getTypeName()); PropagateTags tagPropagation = getRelationshipTagPropagation(fromVertex, toVertex, relationship); AtlasEdge ret = graphHelper.getOrCreateEdge(fromVertex, toVertex, relationshipLabel); if (LOG.isDebugEnabled()) { LOG.debug("Created relationship edge from [{}] --> [{}] using edge label: [{}]", getTypeName(fromVertex), getTypeName(toVertex), relationshipLabel); } // map additional properties to relationship edge if (ret != null) { // Accept a valid (assigned) guid from the supplied relationship, or generate one. String relationshipGuid = relationship.getGuid(); final String guid = AtlasTypeUtil.isAssignedGuid(relationshipGuid) ? relationshipGuid : UUID.randomUUID().toString(); AtlasGraphUtilsV2.setEncodedProperty(ret, ENTITY_TYPE_PROPERTY_KEY, relationship.getTypeName()); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIP_GUID_PROPERTY_KEY, guid); AtlasGraphUtilsV2.setEncodedProperty(ret, VERSION_PROPERTY_KEY, getRelationshipVersion(relationship)); AtlasGraphUtilsV2.setEncodedProperty(ret, RELATIONSHIPTYPE_TAG_PROPAGATION_KEY, tagPropagation.name()); // blocked propagated classifications handleBlockedClassifications(ret, relationship.getBlockedPropagatedClassifications()); // propagate tags deleteHandler.addTagPropagation(ret, tagPropagation); } return ret; }
private void validateAndNormalize(AtlasRelationship relationship) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (! AtlasTypeUtil.isValidGuid(relationship.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_GUID_NOT_FOUND, relationship.getGuid()); } AtlasRelationshipType type = typeRegistry.getRelationshipTypeByName(relationship.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.RELATIONSHIP.name(), relationship.getTypeName()); } type.validateValue(relationship, relationship.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValue(relationship); }
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 void readClassificationsFromEdge(AtlasEdge edge, AtlasRelationshipWithExtInfo relationshipWithExtInfo, boolean extendedInfo) throws AtlasBaseException { List<AtlasVertex> classificationVertices = getClassificationVertices(edge); List<String> blockedClassificationIds = getBlockedClassificationIds(edge); AtlasRelationship relationship = relationshipWithExtInfo.getRelationship(); Set<AtlasClassification> propagatedClassifications = new HashSet<>(); Set<AtlasClassification> blockedClassifications = new HashSet<>(); for (AtlasVertex classificationVertex : classificationVertices) { String classificationId = classificationVertex.getIdForDisplay(); AtlasClassification classification = toAtlasClassification(classificationVertex); String entityGuid = classification.getEntityGuid(); if (blockedClassificationIds.contains(classificationId)) { blockedClassifications.add(classification); } else { propagatedClassifications.add(classification); } // add entity headers to referred entities if (extendedInfo) { addToReferredEntities(relationshipWithExtInfo, entityGuid); } } relationship.setPropagatedClassifications(propagatedClassifications); relationship.setBlockedPropagatedClassifications(blockedClassifications); }
private void updateTagPropagations(AtlasEdge edge, AtlasRelationship relationship) throws AtlasBaseException { PropagateTags oldTagPropagation = getPropagateTags(edge); PropagateTags newTagPropagation = relationship.getPropagateTags(); handleBlockedClassifications(edge, relationship.getBlockedPropagatedClassifications());
/** * Validate the fields in the the RelationshipType are consistent with respect to themselves. * @param relationship * @throws AtlasBaseException */ private boolean validateRelationship(AtlasRelationship relationship) { String end1TypeName = relationship.getEnd1() != null ? relationship.getEnd1().getTypeName() : null; String end2TypeName = relationship.getEnd2() != null ? relationship.getEnd2().getTypeName() : null; if (StringUtils.isNotEmpty(end1TypeName) && StringUtils.isNotEmpty(end2TypeName)) { return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); } return false; }
@Override public AtlasEdge getRelationship(AtlasVertex fromVertex, AtlasVertex toVertex, AtlasRelationship relationship) { String relationshipLabel = getRelationshipEdgeLabel(fromVertex, toVertex, relationship.getTypeName()); return getRelationshipEdge(fromVertex, toVertex, relationshipLabel); }
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); } } }
@Override public AtlasEdge getOrCreate(AtlasVertex end1Vertex, AtlasVertex end2Vertex, AtlasRelationship relationship) throws AtlasBaseException { AtlasEdge ret = getRelationshipEdge(end1Vertex, end2Vertex, relationship.getTypeName()); if (ret == null) { validateRelationship(end1Vertex, end2Vertex, relationship.getTypeName(), relationship.getAttributes()); ret = createRelationship(end1Vertex, end2Vertex, relationship); } 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; }