use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class DefaultGraphPersistenceStrategy method constructClassInstanceId.
@Override
public ITypedReferenceableInstance constructClassInstanceId(ClassType classType, Object value) {
try {
AtlasVertex classVertex = (AtlasVertex) value;
ITypedReferenceableInstance classInstance = classType.createInstance(GraphHelper.getIdFromVertex(classVertex), new String[0]);
return classType.convert(classInstance, Multiplicity.OPTIONAL);
} catch (AtlasException e) {
LOG.error("error while constructing an instance", e);
}
return null;
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteMixOfNullAndNonNullGuids.
@Test
public void testDeleteMixOfNullAndNonNullGuids() throws Exception {
ITypedReferenceableInstance entity1 = compositeMapValueType.createInstance();
ITypedReferenceableInstance entity2 = compositeMapValueType.createInstance();
List<String> createEntitiesResult = repositoryService.createEntities(entity1, entity2).getCreatedEntities();
Assert.assertEquals(createEntitiesResult.size(), 2);
List<String> guids = Arrays.asList(createEntitiesResult.get(0), null, null, createEntitiesResult.get(1));
EntityResult deleteEntitiesResult = repositoryService.deleteEntities(guids);
Assert.assertEquals(deleteEntitiesResult.getDeletedEntities().size(), 2);
Assert.assertTrue(deleteEntitiesResult.getDeletedEntities().containsAll(createEntitiesResult));
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryDeleteTestBase method testDeleteEntityWithTraits.
@Test
public void testDeleteEntityWithTraits() throws Exception {
Referenceable entity = createDBEntity();
String id = createInstance(entity);
TraitType dataType = typeSystem.getDataType(TraitType.class, PII);
ITypedStruct trait = dataType.convert(new Struct(TestUtils.PII), Multiplicity.REQUIRED);
repositoryService.addTrait(id, trait);
ITypedReferenceableInstance instance = repositoryService.getEntityDefinition(id);
assertTrue(instance.getTraits().contains(PII));
deleteEntities(id);
assertEntityDeleted(id);
assertTestDeleteEntityWithTraits(id);
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryDeleteTestBase method testDisconnectUnidirectionalArrayReferenceFromClassType.
/**
* Verify deleting entity that is the target of a unidirectional class array reference
* from a class instance.
*/
@Test
public void testDisconnectUnidirectionalArrayReferenceFromClassType() throws Exception {
createDbTableGraph(TestUtils.DATABASE_NAME, TestUtils.TABLE_NAME);
// Get the guid for one of the table's columns.
ITypedReferenceableInstance table = repositoryService.getEntityDefinition(TestUtils.TABLE_TYPE, "name", TestUtils.TABLE_NAME);
String tableGuid = table.getId()._getId();
List<ITypedReferenceableInstance> columns = (List<ITypedReferenceableInstance>) table.get("columns");
Assert.assertEquals(columns.size(), 5);
String columnGuid = columns.get(0).getId()._getId();
// Delete the column.
EntityResult entityResult = deleteEntities(columnGuid);
assertEquals(entityResult.getDeletedEntities().size(), 1);
Assert.assertTrue(entityResult.getDeletedEntities().contains(columnGuid));
assertEquals(entityResult.getUpdateEntities().size(), 1);
Assert.assertTrue(entityResult.getUpdateEntities().contains(tableGuid));
assertEntityDeleted(columnGuid);
// Verify table.columns reference to the deleted column has been disconnected.
table = repositoryService.getEntityDefinition(tableGuid);
assertTestDisconnectUnidirectionalArrayReferenceFromClassType((List<ITypedReferenceableInstance>) table.get("columns"), columnGuid);
}
use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.
the class GraphBackedMetadataRepositoryDeleteTestBase method getEmployeeNameGuidMap.
private Map<String, String> getEmployeeNameGuidMap(final ITypedReferenceableInstance hrDept) throws AtlasException {
Object refValue = hrDept.get("employees");
Assert.assertTrue(refValue instanceof List);
List<Object> employees = (List<Object>) refValue;
Assert.assertEquals(employees.size(), 4);
Map<String, String> nameGuidMap = new HashMap<String, String>() {
{
put("hr", hrDept.getId()._getId());
}
};
for (Object listValue : employees) {
Assert.assertTrue(listValue instanceof ITypedReferenceableInstance);
ITypedReferenceableInstance employee = (ITypedReferenceableInstance) listValue;
nameGuidMap.put((String) employee.get("name"), employee.getId()._getId());
}
return nameGuidMap;
}
Aggregations