Search in sources :

Example 56 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasEntityGraphDiscoveryV1 method visitRelationships.

private void visitRelationships(AtlasEntityType entityType, AtlasEntity entity, List<String> visitedAttributes) throws AtlasBaseException {
    for (AtlasAttribute attribute : entityType.getRelationshipAttributes().values()) {
        AtlasType attrType = attribute.getAttributeType();
        String attrName = attribute.getName();
        Object attrVal = entity.getRelationshipAttribute(attrName);
        if (entity.hasRelationshipAttribute(attrName)) {
            visitAttribute(attrType, attrVal);
            visitedAttributes.add(attrName);
        }
    }
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasType(org.apache.atlas.type.AtlasType)

Example 57 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasEntityGraphDiscoveryV1 method visitStruct.

void visitStruct(AtlasStructType structType, AtlasStruct struct) throws AtlasBaseException {
    for (AtlasAttribute attribute : structType.getAllAttributes().values()) {
        AtlasType attrType = attribute.getAttributeType();
        Object attrVal = struct.getAttribute(attribute.getName());
        visitAttribute(attrType, attrVal);
    }
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasType(org.apache.atlas.type.AtlasType)

Example 58 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasEntityGraphDiscoveryV1 method visitEntity.

void visitEntity(AtlasEntityType entityType, AtlasEntity entity) throws AtlasBaseException {
    List<String> visitedAttributes = new ArrayList<>();
    // visit relationship attributes
    if (!(this.discoveryContext.getEntityStream() instanceof EntityImportStream)) {
        visitRelationships(entityType, entity, visitedAttributes);
    }
    // visit struct attributes
    for (AtlasAttribute attribute : entityType.getAllAttributes().values()) {
        AtlasType attrType = attribute.getAttributeType();
        String attrName = attribute.getName();
        Object attrVal = entity.getAttribute(attrName);
        if (entity.hasAttribute(attrName) && !visitedAttributes.contains(attrName)) {
            visitAttribute(attrType, attrVal);
        }
    }
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) ArrayList(java.util.ArrayList) AtlasType(org.apache.atlas.type.AtlasType)

Example 59 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasRelationshipDefStoreV1 method updateByGuid.

@Override
public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid);
    }
    AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : guid));
    validateType(relationshipDef);
    AtlasType type = typeRegistry.getTypeByGuid(guid);
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid);
    }
    preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex);
    // updates should not effect the edges between the types as we do not allow updates that change the endpoints.
    AtlasRelationshipDef ret = toRelationshipDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret);
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasRelationshipDef(org.apache.atlas.model.typedef.AtlasRelationshipDef) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Example 60 with AtlasType

use of org.apache.atlas.type.AtlasType in project atlas by apache.

the class AtlasEntityDefStoreV1 method updateByName.

@Override
public AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasEntityDefStoreV1.updateByName({}, {})", name, entityDef);
    }
    AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name);
    AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update entity-def ", name);
    validateType(entityDef);
    AtlasType type = typeRegistry.getType(entityDef.getName());
    if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name());
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    updateVertexPreUpdate(entityDef, (AtlasEntityType) type, vertex);
    updateVertexAddReferences(entityDef, vertex);
    AtlasEntityDef ret = toEntityDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasEntityDefStoreV1.updateByName({}, {}): {}", name, entityDef, ret);
    }
    return ret;
}
Also used : AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasTypeAccessRequest(org.apache.atlas.authorize.AtlasTypeAccessRequest) AtlasType(org.apache.atlas.type.AtlasType)

Aggregations

AtlasType (org.apache.atlas.type.AtlasType)95 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)51 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)33 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)23 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)17 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)17 AtlasStructType (org.apache.atlas.type.AtlasStructType)16 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)15 AtlasMapType (org.apache.atlas.type.AtlasMapType)13 ArrayList (java.util.ArrayList)11 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 HashMap (java.util.HashMap)8 AtlasTypeAccessRequest (org.apache.atlas.authorize.AtlasTypeAccessRequest)8 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)8 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)8 Map (java.util.Map)7 List (java.util.List)6 Collection (java.util.Collection)5 LinkedHashSet (java.util.LinkedHashSet)5 Set (java.util.Set)4