Search in sources :

Example 6 with GuidMapping

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

the class TypedInstanceToGraphMapper method createGuidMapping.

public GuidMapping createGuidMapping() {
    Map<String, String> mapping = new HashMap<>(idToVertexMap.size());
    for (Map.Entry<Id, AtlasVertex> entry : idToVertexMap.entrySet()) {
        Id id = entry.getKey();
        if (id.isUnassigned()) {
            AtlasVertex classVertex = entry.getValue();
            mapping.put(id._getId(), GraphHelper.getGuid(classVertex));
        }
    }
    return new GuidMapping(mapping);
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) HashMap(java.util.HashMap) Id(org.apache.atlas.typesystem.persistence.Id) HashMap(java.util.HashMap) Map(java.util.Map) GuidMapping(org.apache.atlas.model.instance.GuidMapping)

Example 7 with GuidMapping

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

the class GraphBackedMetadataRepository method createEntities.

@Override
@GraphTransaction
public CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities) throws RepositoryException, EntityExistsException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("adding entities={}", entities);
    }
    try {
        TypedInstanceToGraphMapper instanceToGraphMapper = new TypedInstanceToGraphMapper(graphToInstanceMapper, deleteHandler);
        instanceToGraphMapper.mapTypedInstanceToGraph(TypedInstanceToGraphMapper.Operation.CREATE, entities);
        List<String> createdGuids = RequestContext.get().getCreatedEntityIds();
        CreateUpdateEntitiesResult result = new CreateUpdateEntitiesResult();
        EntityResult entityResult = new EntityResult(createdGuids, null, null);
        GuidMapping mapping = instanceToGraphMapper.createGuidMapping();
        result.setEntityResult(entityResult);
        result.setGuidMapping(mapping);
        return result;
    } catch (EntityExistsException e) {
        throw e;
    } catch (AtlasException e) {
        throw new RepositoryException(e);
    }
}
Also used : CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) RepositoryException(org.apache.atlas.repository.RepositoryException) EntityResult(org.apache.atlas.model.legacy.EntityResult) AtlasException(org.apache.atlas.AtlasException) EntityExistsException(org.apache.atlas.typesystem.exception.EntityExistsException) GuidMapping(org.apache.atlas.model.instance.GuidMapping) GraphTransaction(org.apache.atlas.annotation.GraphTransaction)

Example 8 with GuidMapping

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

the class EntityResource method getResponse.

private JSONObject getResponse(CreateUpdateEntitiesResult result) throws AtlasException, JSONException {
    JSONObject response = new JSONObject();
    EntityResult entityResult = result.getEntityResult();
    GuidMapping mapping = result.getGuidMapping();
    response.put(AtlasClient.REQUEST_ID, Servlets.getRequestId());
    if (entityResult != null) {
        response.put(AtlasClient.ENTITIES, new JSONObject(entityResult.toString()).get(AtlasClient.ENTITIES));
        String sampleEntityId = getSample(result.getEntityResult());
        if (sampleEntityId != null) {
            String entityDefinition = metadataService.getEntityDefinitionJson(sampleEntityId);
            response.put(AtlasClient.DEFINITION, new JSONObject(entityDefinition));
        }
    }
    if (mapping != null) {
        response.put(AtlasClient.GUID_ASSIGNMENTS, new JSONObject(AtlasType.toJson(mapping)).get(AtlasClient.GUID_ASSIGNMENTS));
    }
    return response;
}
Also used : JSONObject(org.codehaus.jettison.json.JSONObject) EntityResult(org.apache.atlas.model.legacy.EntityResult) 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