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);
}
}
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);
}
}
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;
}
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;
}
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;
}
Aggregations