use of org.apache.atlas.model.legacy.EntityResult 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.legacy.EntityResult in project incubator-atlas by apache.
the class AtlasClientTest method testCreateEntity.
@Test
public void testCreateEntity() throws Exception {
setupRetryParams();
AtlasClient atlasClient = new AtlasClient(service, configuration);
WebResource.Builder builder = setupBuilder(AtlasClient.API.CREATE_ENTITY, service);
ClientResponse response = mock(ClientResponse.class);
when(response.getStatus()).thenReturn(Response.Status.CREATED.getStatusCode());
JSONObject jsonResponse = new JSONObject(new EntityResult(Arrays.asList("id"), null, null).toString());
when(response.getEntity(String.class)).thenReturn(jsonResponse.toString());
when(response.getLength()).thenReturn(jsonResponse.length());
String entityJson = InstanceSerialization.toJson(new Referenceable("type"), true);
when(builder.method(anyString(), Matchers.<Class>any(), anyString())).thenReturn(response);
List<String> ids = atlasClient.createEntity(entityJson);
assertEquals(ids.size(), 1);
assertEquals(ids.get(0), "id");
}
use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.
the class AtlasClient method deleteEntity.
/**
* Supports Deletion of an entity identified by its unique attribute value
* @param entityType Type of the entity being deleted
* @param uniqueAttributeName Attribute Name that uniquely identifies the entity
* @param uniqueAttributeValue Attribute Value that uniquely identifies the entity
* @return List of entity ids updated/deleted(including composite references from that entity)
*/
public EntityResult deleteEntity(String entityType, String uniqueAttributeName, String uniqueAttributeValue) throws AtlasServiceException {
LOG.debug("Deleting entity type: {}, attributeName: {}, attributeValue: {}", entityType, uniqueAttributeName, uniqueAttributeValue);
API api = API.DELETE_ENTITY;
WebResource resource = getResource(api);
resource = resource.queryParam(TYPE, entityType);
resource = resource.queryParam(ATTRIBUTE_NAME, uniqueAttributeName);
resource = resource.queryParam(ATTRIBUTE_VALUE, uniqueAttributeValue);
JSONObject jsonResponse = callAPIWithResource(API.DELETE_ENTITIES, resource);
EntityResult results = extractEntityResult(jsonResponse);
LOG.debug("Delete entities returned results: {}", results);
return results;
}
use of org.apache.atlas.model.legacy.EntityResult 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;
}
use of org.apache.atlas.model.legacy.EntityResult in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteEntityWithDuplicateReferenceListElements.
@Test
public void testDeleteEntityWithDuplicateReferenceListElements() throws Exception {
// Create a table entity, with 2 composite column entities
Referenceable dbEntity = createDBEntity();
String dbGuid = createInstance(dbEntity);
Referenceable table1Entity = createTableEntity(dbGuid);
String tableName = TestUtils.randomString();
table1Entity.set(NAME, tableName);
Referenceable col1 = createColumnEntity();
col1.set(NAME, TestUtils.randomString());
Referenceable col2 = createColumnEntity();
col2.set(NAME, TestUtils.randomString());
// Populate columns reference list with duplicates.
table1Entity.set(COLUMNS_ATTR_NAME, ImmutableList.of(col1, col2, col1, col2));
ClassType dataType = typeSystem.getDataType(ClassType.class, table1Entity.getTypeName());
ITypedReferenceableInstance instance = dataType.convert(table1Entity, Multiplicity.REQUIRED);
TestUtils.resetRequestContext();
List<String> result = repositoryService.createEntities(instance).getCreatedEntities();
Assert.assertEquals(result.size(), 3);
ITypedReferenceableInstance entityDefinition = repositoryService.getEntityDefinition(TABLE_TYPE, NAME, tableName);
String tableGuid = entityDefinition.getId()._getId();
Object attrValue = entityDefinition.get(COLUMNS_ATTR_NAME);
assertTrue(attrValue instanceof List);
List<ITypedReferenceableInstance> columns = (List<ITypedReferenceableInstance>) attrValue;
Assert.assertEquals(columns.size(), 4);
TestUtils.resetRequestContext();
String columnGuid = columns.get(0).getId()._getId();
// Delete one of the columns.
EntityResult deleteResult = repositoryService.deleteEntities(Collections.singletonList(columnGuid));
Assert.assertEquals(deleteResult.getDeletedEntities().size(), 1);
Assert.assertTrue(deleteResult.getDeletedEntities().contains(columnGuid));
Assert.assertEquals(deleteResult.getUpdateEntities().size(), 1);
Assert.assertTrue(deleteResult.getUpdateEntities().contains(tableGuid));
// Verify the duplicate edge IDs were all removed from reference property list.
AtlasVertex tableVertex = GraphHelper.getInstance().getVertexForGUID(tableGuid);
String columnsPropertyName = GraphHelper.getQualifiedFieldName(dataType, COLUMNS_ATTR_NAME);
List columnsPropertyValue = tableVertex.getProperty(columnsPropertyName, List.class);
verifyTestDeleteEntityWithDuplicateReferenceListElements(columnsPropertyValue);
}
Aggregations