Search in sources :

Example 16 with ITypedReferenceableInstance

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;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasException(org.apache.atlas.AtlasException)

Example 17 with ITypedReferenceableInstance

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));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 18 with ITypedReferenceableInstance

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);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 19 with ITypedReferenceableInstance

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);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) EntityResult(org.apache.atlas.model.legacy.EntityResult) Test(org.testng.annotations.Test)

Example 20 with ITypedReferenceableInstance

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;
}
Also used : HashMap(java.util.HashMap) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ArrayList(java.util.ArrayList) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List)

Aggregations

ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)142 Test (org.testng.annotations.Test)54 List (java.util.List)34 ArrayList (java.util.ArrayList)30 Id (org.apache.atlas.typesystem.persistence.Id)28 Referenceable (org.apache.atlas.typesystem.Referenceable)22 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)21 ImmutableList (com.google.common.collect.ImmutableList)20 ClassType (org.apache.atlas.typesystem.types.ClassType)19 HashMap (java.util.HashMap)16 AtlasException (org.apache.atlas.AtlasException)16 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)16 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)14 EntityResult (org.apache.atlas.model.legacy.EntityResult)12 IStruct (org.apache.atlas.typesystem.IStruct)10 Map (java.util.Map)9 CreateUpdateEntitiesResult (org.apache.atlas.CreateUpdateEntitiesResult)9 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)9 RepositoryException (org.apache.atlas.repository.RepositoryException)9 BeforeTest (org.testng.annotations.BeforeTest)9