GraphBackedMetadataRepository implements MetadataRepository { @Override @GraphTransaction public ITypedReferenceableInstance getEntityDefinition(String guid) throws RepositoryException, EntityNotFoundException { return getEntityDefinitions(guid).get(0); } @Inject  GraphBackedMetadataRepository(DeleteHandler deleteHandler, AtlasGraph atlasGraph); GraphToTypedInstanceMapper getGraphToInstanceMapper(); @Override String getTypeAttributeName(); @Override String getStateAttributeName(); @Override String getSuperTypeAttributeName(); String getIdAttributeName(); @Override String getVersionAttributeName(); @Override String getTraitLabel(IDataType<?> dataType, String traitName); @Override String getFieldNameInVertex(IDataType<?> dataType, AttributeInfo aInfo); String getFieldNameInVertex(IDataType<?> dataType, String attrName); @Override String getEdgeLabel(IDataType<?> dataType, AttributeInfo aInfo); @Override @GraphTransaction CreateUpdateEntitiesResult createEntities(ITypedReferenceableInstance... entities); @Override @GraphTransaction ITypedReferenceableInstance getEntityDefinition(String guid); @Override @GraphTransaction List<ITypedReferenceableInstance> getEntityDefinitions(String... guids); @Override @GraphTransaction ITypedReferenceableInstance getEntityDefinition(String entityType, String attribute, Object value); @Override @GraphTransaction List<String> getEntityList(String entityType); @Override @GraphTransaction List<String> getTraitNames(String guid); @Override @GraphTransaction void addTrait(List<String> entityGuids, ITypedStruct traitInstance); @Override @GraphTransaction void addTrait(String guid, ITypedStruct traitInstance); @Override @GraphTransaction void deleteTrait(String guid, String traitNameToBeDeleted); @Override @GraphTransaction CreateUpdateEntitiesResult updateEntities(ITypedReferenceableInstance... entitiesUpdated); @Override @GraphTransaction CreateUpdateEntitiesResult updatePartial(ITypedReferenceableInstance entity); @Override @GraphTransaction EntityResult deleteEntities(List<String> guids); AtlasGraph getGraph();  }
@Test(dependsOnMethods = "testSubmitEntity") public void testGetEntityDefinitionForDepartment() throws Exception { ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(guid); Assert.assertNotNull(entity); Assert.assertEquals(entity.getId().getState(), Id.EntityState.ACTIVE); AtlasSystemAttributes systemAttributes = entity.getSystemAttributes(); Assert.assertNotNull(systemAttributes.createdTime); Assert.assertNotNull(systemAttributes.modifiedTime); }
@Test(expectedExceptions = EntityNotFoundException.class) public void testGetEntityDefinitionNonExistent() throws Exception { repositoryService.getEntityDefinition("blah"); Assert.fail(); }
@Test(dependsOnMethods = "testCreateEntity") public void testGetEntityDefinition() throws Exception { String guid = getGUID(); ITypedReferenceableInstance table = repositoryService.getEntityDefinition(guid); Assert.assertEquals(table.getDate("created"), new Date(TestUtils.TEST_DATE_IN_LONG)); System.out.println("*** table = " + table); }
@Test public void testMultipleTypesWithSameUniqueAttribute() throws Exception { HierarchicalTypeDefinition<ClassType> supertype = createClassTypeDef(randomString(), ImmutableSet.<String>of(), createUniqueRequiredAttrDef("name", DataTypes.STRING_TYPE)); HierarchicalTypeDefinition<ClassType> t1 = createClassTypeDef(randomString(), ImmutableSet.of(supertype.typeName)); HierarchicalTypeDefinition<ClassType> t2 = createClassTypeDef(randomString(), ImmutableSet.of(supertype.typeName)); typeSystem.defineClassTypes(supertype, t1, t2); final String name = randomString(); String id1 = createEntity(new Referenceable(t1.typeName) {{ set("name", name); }}).get(0); String id2 = createEntity(new Referenceable(t2.typeName) {{ set("name", name); }}).get(0); assertNotEquals(id1, id2); ITypedReferenceableInstance entity = repositoryService.getEntityDefinition(t1.typeName, "name", name); assertEquals(entity.getTypeName(), t1.typeName); assertEquals(entity.getId()._getId(), id1); entity = repositoryService.getEntityDefinition(t2.typeName, "name", name); assertEquals(entity.getTypeName(), t2.typeName); assertEquals(entity.getId()._getId(), id2); }