Search in sources :

Example 1 with EntityGraphDiscovery

use of org.apache.atlas.repository.store.graph.EntityGraphDiscovery in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method preCreateOrUpdate.

private EntityMutationContext preCreateOrUpdate(EntityStream entityStream, EntityGraphMapper entityGraphMapper, boolean isPartialUpdate) throws AtlasBaseException {
    EntityGraphDiscovery graphDiscoverer = new AtlasEntityGraphDiscoveryV1(typeRegistry, entityStream);
    EntityGraphDiscoveryContext discoveryContext = graphDiscoverer.discoverEntities();
    EntityMutationContext context = new EntityMutationContext(discoveryContext);
    for (String guid : discoveryContext.getReferencedGuids()) {
        AtlasVertex vertex = discoveryContext.getResolvedEntityVertex(guid);
        AtlasEntity entity = entityStream.getByGuid(guid);
        if (entity != null) {
            if (vertex != null) {
                // entity would be null if guid is not in the stream but referenced by an entity in the stream
                if (!isPartialUpdate) {
                    graphDiscoverer.validateAndNormalize(entity);
                } else {
                    graphDiscoverer.validateAndNormalizeForUpdate(entity);
                }
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                String guidVertex = AtlasGraphUtilsV1.getIdFromVertex(vertex);
                if (!StringUtils.equals(guidVertex, guid)) {
                    // if entity was found by unique attribute
                    entity.setGuid(guidVertex);
                }
                context.addUpdated(guid, entity, entityType, vertex);
            } else {
                graphDiscoverer.validateAndNormalize(entity);
                AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
                //Create vertices which do not exist in the repository
                if ((entityStream instanceof EntityImportStream) && AtlasTypeUtil.isAssignedGuid(entity.getGuid())) {
                    vertex = entityGraphMapper.createVertexWithGuid(entity, entity.getGuid());
                } else {
                    vertex = entityGraphMapper.createVertex(entity);
                }
                discoveryContext.addResolvedGuid(guid, vertex);
                String generatedGuid = AtlasGraphUtilsV1.getIdFromVertex(vertex);
                entity.setGuid(generatedGuid);
                context.addCreated(guid, entity, entityType, vertex);
            }
            // during import, update the system attributes
            if (entityStream instanceof EntityImportStream) {
                entityGraphMapper.updateSystemAttributes(vertex, entity);
            }
        }
    }
    return context;
}
Also used : EntityGraphDiscovery(org.apache.atlas.repository.store.graph.EntityGraphDiscovery) EntityGraphDiscoveryContext(org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 EntityGraphDiscovery (org.apache.atlas.repository.store.graph.EntityGraphDiscovery)1 EntityGraphDiscoveryContext (org.apache.atlas.repository.store.graph.EntityGraphDiscoveryContext)1 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)1