Search in sources :

Example 26 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method createVertexWithGuid.

public AtlasVertex createVertexWithGuid(AtlasEntity entity, String guid) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createVertex({})", entity.getTypeName());
    }
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
    AtlasVertex ret = createStructVertex(entity);
    for (String superTypeName : entityType.getAllSuperTypes()) {
        AtlasGraphUtilsV1.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, superTypeName);
    }
    AtlasGraphUtilsV1.setProperty(ret, Constants.GUID_PROPERTY_KEY, guid);
    AtlasGraphUtilsV1.setProperty(ret, Constants.VERSION_PROPERTY_KEY, getEntityVersion(entity));
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 27 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method addClassifications.

public void addClassifications(final EntityMutationContext context, String guid, List<AtlasClassification> classifications) throws AtlasBaseException {
    if (CollectionUtils.isNotEmpty(classifications)) {
        AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
        if (instanceVertex == null) {
            throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
        }
        String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
        final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
        for (AtlasClassification classification : classifications) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("mapping classification {}", classification);
            }
            GraphHelper.addProperty(instanceVertex, Constants.TRAIT_NAMES_PROPERTY_KEY, classification.getTypeName());
            // add a new AtlasVertex for the struct or trait instance
            AtlasVertex classificationVertex = createClassificationVertex(classification);
            if (LOG.isDebugEnabled()) {
                LOG.debug("created vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
            }
            // add the attributes for the trait instance
            mapClassification(EntityOperation.CREATE, context, classification, entityType, instanceVertex, classificationVertex);
        }
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 28 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method mapAttributesAndClassifications.

public EntityMutationResponse mapAttributesAndClassifications(EntityMutationContext context, final boolean isPartialUpdate, final boolean replaceClassifications) throws AtlasBaseException {
    EntityMutationResponse resp = new EntityMutationResponse();
    Collection<AtlasEntity> createdEntities = context.getCreatedEntities();
    Collection<AtlasEntity> updatedEntities = context.getUpdatedEntities();
    if (CollectionUtils.isNotEmpty(createdEntities)) {
        for (AtlasEntity createdEntity : createdEntities) {
            String guid = createdEntity.getGuid();
            AtlasVertex vertex = context.getVertex(guid);
            AtlasEntityType entityType = context.getType(guid);
            mapAttributes(createdEntity, vertex, CREATE, context);
            resp.addEntity(CREATE, constructHeader(createdEntity, entityType, vertex));
            addClassifications(context, guid, createdEntity.getClassifications());
        }
    }
    if (CollectionUtils.isNotEmpty(updatedEntities)) {
        for (AtlasEntity updatedEntity : updatedEntities) {
            String guid = updatedEntity.getGuid();
            AtlasVertex vertex = context.getVertex(guid);
            AtlasEntityType entityType = context.getType(guid);
            mapAttributes(updatedEntity, vertex, UPDATE, context);
            if (isPartialUpdate) {
                resp.addEntity(PARTIAL_UPDATE, constructHeader(updatedEntity, entityType, vertex));
            } else {
                resp.addEntity(UPDATE, constructHeader(updatedEntity, entityType, vertex));
            }
            if (replaceClassifications) {
                deleteClassifications(guid);
                addClassifications(context, guid, updatedEntity.getClassifications());
            }
        }
    }
    RequestContextV1 req = RequestContextV1.get();
    for (AtlasObjectId id : req.getDeletedEntityIds()) {
        resp.addEntity(DELETE, constructHeader(id));
    }
    for (AtlasObjectId id : req.getUpdatedEntityIds()) {
        if (isPartialUpdate) {
            resp.addEntity(PARTIAL_UPDATE, constructHeader(id));
        } else {
            resp.addEntity(UPDATE, constructHeader(id));
        }
    }
    return resp;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) RequestContextV1(org.apache.atlas.RequestContextV1) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 29 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method mapCollectionElementsToVertex.

private Object mapCollectionElementsToVertex(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException {
    switch(ctx.getAttrType().getTypeCategory()) {
        case PRIMITIVE:
        case ENUM:
            return ctx.getValue();
        case STRUCT:
            return mapStructValue(ctx, context);
        case OBJECT_ID_TYPE:
            AtlasEntityType instanceType = getInstanceType(ctx.getValue());
            ctx.setElementType(instanceType);
            return mapObjectIdValue(ctx, context);
        case MAP:
        case ARRAY:
        default:
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, ctx.getAttrType().getTypeCategory().name());
    }
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 30 with AtlasEntityType

use of org.apache.atlas.type.AtlasEntityType in project incubator-atlas by apache.

the class EntityGraphMapper method updateClassification.

public void updateClassification(final EntityMutationContext context, String guid, AtlasClassification classification) throws AtlasBaseException {
    AtlasVertex instanceVertex = AtlasGraphUtilsV1.findByGuid(guid);
    if (instanceVertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid);
    }
    String entityTypeName = AtlasGraphUtilsV1.getTypeName(instanceVertex);
    final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entityTypeName);
    if (LOG.isDebugEnabled()) {
        LOG.debug("Updating classification {} for entity {}", classification, guid);
    }
    // get the classification vertex from entity
    String relationshipLabel = GraphHelper.getTraitLabel(entityTypeName, classification.getTypeName());
    AtlasEdge classificationEdge = graphHelper.getEdgeForLabel(instanceVertex, relationshipLabel);
    AtlasVertex classificationVertex = classificationEdge.getInVertex();
    if (LOG.isDebugEnabled()) {
        LOG.debug("updating vertex {} for trait {}", string(classificationVertex), classification.getTypeName());
    }
    mapClassification(EntityOperation.UPDATE, context, classification, entityType, instanceVertex, classificationVertex);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasEdge(org.apache.atlas.repository.graphdb.AtlasEdge)

Aggregations

AtlasEntityType (org.apache.atlas.type.AtlasEntityType)45 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)18 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)16 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)12 AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)8 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)8 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)7 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)6 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)6 AtlasAttribute (org.apache.atlas.type.AtlasStructType.AtlasAttribute)6 AtlasType (org.apache.atlas.type.AtlasType)6 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)5 HashMap (java.util.HashMap)4 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)4 List (java.util.List)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3