Search in sources :

Example 1 with GuidMapping

use of org.apache.atlas.model.instance.GuidMapping in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method updatePartial.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult updatePartial(ITypedReferenceableInstance entity) throws RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("updating entity {}", entity);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_PARTIAL, entity);
        RequestContext requestContext = RequestContext.get();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(createEntityResultFromContext(requestContext));
        result.setGuidMapping(mapping);
        return result;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) AtlasException(org.apache.atlas.AtlasException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 2 with GuidMapping

use of org.apache.atlas.model.instance.GuidMapping in project incubator-atlas by apache.

the class GraphBackedMetadataRepository method updateEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance... entitiesUpdated) throws RepositoryException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("updating entity {}", entitiesUpdated);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.UPDATE_FULL, entitiesUpdated);
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        RequestContext requestContext = RequestContext.get();
        result.setEntityResult(createEntityResultFromContext(requestContext));
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setGuidMapping(mapping);
        return result;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) RequestContext(org.apache.atlas.RequestContext) AtlasException(org.apache.atlas.AtlasException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 3 with GuidMapping

use of org.apache.atlas.model.instance.GuidMapping in project incubator-atlas by apache.

the class CreateUpdateEntitiesResult method fromJson.

/**
     * Deserializes the given json into an instance of
     * CreateUpdateEntitiesResult.
     *
     * @param json
     *            the (unmodified) json that comes back from Atlas.
     * @return
     * @throws AtlasServiceException
     */
public static CreateUpdateEntitiesResult fromJson(String json) throws AtlasServiceException {
    GuidMapping guidMapping = AtlasType.fromJson(json, GuidMapping.class);
    EntityResult entityResult = EntityResult.fromString(json);
    CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
    result.setEntityResult(entityResult);
    result.setGuidMapping(guidMapping);
    return result;
}
Also used : EntityResult(org.apache.atlas.model.legacy.EntityResult) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Example 4 with GuidMapping

use of org.apache.atlas.model.instance.GuidMapping in project incubator-atlas by apache.

the class AtlasInstanceConverter method toEntityMutationResponse.

public static EntityMutationResponse toEntityMutationResponse(CreateUpdateEntitiesResult result) {
    EntityMutationResponse response = new EntityMutationResponse();
    for (String guid : result.getCreatedEntities()) {
        AtlasEntityHeader header = new AtlasEntityHeader();
        header.setGuid(guid);
        response.addEntity(EntityMutations.EntityOperation.CREATE, header);
    }
    for (String guid : result.getUpdatedEntities()) {
        AtlasEntityHeader header = new AtlasEntityHeader();
        header.setGuid(guid);
        response.addEntity(EntityMutations.EntityOperation.UPDATE, header);
    }
    for (String guid : result.getDeletedEntities()) {
        AtlasEntityHeader header = new AtlasEntityHeader();
        header.setGuid(guid);
        response.addEntity(EntityMutations.EntityOperation.DELETE, header);
    }
    GuidMapping guidMapping = result.getGuidMapping();
    if (guidMapping != null) {
        response.setGuidAssignments(guidMapping.getGuidAssignments());
    }
    return response;
}
Also used : EntityMutationResponse(org.apache.atlas.model.instance.EntityMutationResponse) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Example 5 with GuidMapping

use of org.apache.atlas.model.instance.GuidMapping in project incubator-atlas by apache.

the class AtlasInstanceConverter method toCreateUpdateEntitiesResult.

public CreateUpdateEntitiesResult toCreateUpdateEntitiesResult(EntityMutationResponse reponse) {
    CreateUpdateEntitiesResult ret = null;
    if (reponse != null) {
        Map<EntityOperation, List<AtlasEntityHeader>> mutatedEntities = reponse.getMutatedEntities();
        Map<String, String> guidAssignments = reponse.getGuidAssignments();
        ret = new CreateUpdateEntitiesResult();
        if (MapUtils.isNotEmpty(guidAssignments)) {
            ret.setGuidMapping(new GuidMapping(guidAssignments));
        }
        if (MapUtils.isNotEmpty(mutatedEntities)) {
            EntityResult entityResult = new EntityResult();
            for (Map.Entry<EntityOperation, List<AtlasEntityHeader>> e : mutatedEntities.entrySet()) {
                switch(e.getKey()) {
                    case CREATE:
                        List<AtlasEntityHeader> createdEntities = mutatedEntities.get(EntityOperation.CREATE);
                        if (CollectionUtils.isNotEmpty(createdEntities)) {
                            Collections.reverse(createdEntities);
                            entityResult.set(EntityResult.OP_CREATED, getGuids(createdEntities));
                        }
                        break;
                    case UPDATE:
                        List<AtlasEntityHeader> updatedEntities = mutatedEntities.get(EntityOperation.UPDATE);
                        if (CollectionUtils.isNotEmpty(updatedEntities)) {
                            Collections.reverse(updatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(updatedEntities));
                        }
                        break;
                    case PARTIAL_UPDATE:
                        List<AtlasEntityHeader> partialUpdatedEntities = mutatedEntities.get(EntityOperation.PARTIAL_UPDATE);
                        if (CollectionUtils.isNotEmpty(partialUpdatedEntities)) {
                            Collections.reverse(partialUpdatedEntities);
                            entityResult.set(EntityResult.OP_UPDATED, getGuids(partialUpdatedEntities));
                        }
                        break;
                    case DELETE:
                        List<AtlasEntityHeader> deletedEntities = mutatedEntities.get(EntityOperation.DELETE);
                        if (CollectionUtils.isNotEmpty(deletedEntities)) {
                            Collections.reverse(deletedEntities);
                            entityResult.set(EntityResult.OP_DELETED, getGuids(deletedEntities));
                        }
                        break;
                }
            }
            ret.setEntityResult(entityResult);
        }
    }
    return ret;
}
Also used : EntityOperation(org.apache.atlas.model.instance.EntityMutations.EntityOperation) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) AtlasEntityHeader(org.apache.atlas.model.instance.AtlasEntityHeader) ArrayList(java.util.ArrayList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Map(java.util.Map) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Aggregations

GuidMapping (org.apache.atlas.model.instance.GuidMapping)8 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)4 EntityResult (org.apache.atlas.model.legacy.EntityResult)4 AtlasException (org.apache.atlas.AtlasException)3 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)3 RepositoryException (org.apache.atlas.repository.RepositoryException)3 Map (java.util.Map)2 RequestContext (org.apache.atlas.RequestContext)2 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)1 EntityOperation (org.apache.atlas.model.instance.EntityMutations.EntityOperation)1 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)1 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)1 Id (org.apache.atlas.typesystem.persistence.Id)1 JSONObject (org.codehaus.jettison.json.JSONObject)1