Search in sources :

Example 21 with CreateUpdateEntitiesResult

use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryTest method testCreateEntityWithOneNestingLevel.

@Test
public void testCreateEntityWithOneNestingLevel() throws AtlasException {
    List<Referenceable> toValidate = new ArrayList<>();
    Referenceable dept = new Referenceable(TestUtils.DEPARTMENT_TYPE);
    toValidate.add(dept);
    dept.set(TestUtils.NAME, "test1");
    Referenceable mike = new Referenceable(TestUtils.PERSON_TYPE);
    toValidate.add(mike);
    mike.set(TestUtils.NAME, "Mike");
    mike.set(TestUtils.DEPARTMENT_ATTR, dept);
    Referenceable mark = new Referenceable(TestUtils.PERSON_TYPE);
    toValidate.add(mark);
    mark.set(TestUtils.NAME, "Mark");
    mark.set(TestUtils.DEPARTMENT_ATTR, dept);
    dept.set(TestUtils.EMPLOYEES_ATTR, ImmutableList.of(mike, mark));
    Map<String, Referenceable> positions = new HashMap<>();
    final String JANITOR = "janitor";
    final String RECEPTIONIST = "receptionist";
    positions.put(JANITOR, mike);
    positions.put(RECEPTIONIST, mark);
    dept.set(TestUtils.POSITIONS_ATTR, positions);
    ClassType deptType = TypeSystem.getInstance().getDataType(ClassType.class, TestUtils.DEPARTMENT_TYPE);
    ITypedReferenceableInstance deptInstance = deptType.convert(dept, Multiplicity.REQUIRED);
    CreateUpdateEntitiesResult result = repositoryService.createEntities(deptInstance);
    validateGuidMapping(toValidate, result);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult) ArrayList(java.util.ArrayList) ClassType(org.apache.atlas.typesystem.types.ClassType) Test(org.testng.annotations.Test)

Example 22 with CreateUpdateEntitiesResult

use of org.apache.atlas.CreateUpdateEntitiesResult in project incubator-atlas by apache.

the class GraphBackedMetadataRepositoryDeleteTestBase method createInstance.

private String createInstance(Referenceable entity) throws Exception {
    ClassType dataType = typeSystem.getDataType(ClassType.class, entity.getTypeName());
    ITypedReferenceableInstance instance = dataType.convert(entity, Multiplicity.REQUIRED);
    CreateUpdateEntitiesResult result = repositoryService.createEntities(instance);
    List<String> results = result.getCreatedEntities();
    return results.get(results.size() - 1);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) CreateUpdateEntitiesResult(org.apache.atlas.CreateUpdateEntitiesResult)

Aggregations

CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)22 AtlasException (org.apache.atlas.AtlasException)9 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)9 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)5 Referenceable (org.apache.atlas.typesystem.Referenceable)5 JSONObject (org.codehaus.jettison.json.JSONObject)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)4 GuidMapping (org.apache.atlas.model.instance.GuidMapping)4 EntityExistsException (org.apache.atlas.typesystem.exception.EntityExistsException)4 Id (org.apache.atlas.typesystem.persistence.Id)4 Test (org.testng.annotations.Test)4 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)3 RepositoryException (org.apache.atlas.repository.RepositoryException)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 EntityNotFoundException (org.apache.atlas.typesystem.exception.EntityNotFoundException)3 ReferenceableInstance (org.apache.atlas.typesystem.persistence.ReferenceableInstance)3 ClassType (org.apache.atlas.typesystem.types.ClassType)3