Search in sources :

Example 1 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class ReplaceIdWithInstance method getInstance.

ITypedReferenceableInstance getInstance(Id id) throws AtlasException {
    ITypedReferenceableInstance r = idToInstanceMap.get(id);
    if (r == null) {
        r = repository.get(id);
        idToInstanceMap.put(id, r);
        walker.addRoot(r);
    }
    return r;
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance)

Example 2 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class ReplaceIdWithInstance method convertToInstances.

ImmutableMap<?, ?> convertToInstances(ImmutableMap val, Multiplicity m, DataTypes.MapType mapType) throws AtlasException {
    if (val == null || (mapType.getKeyType().getTypeCategory() != DataTypes.TypeCategory.CLASS && mapType.getValueType().getTypeCategory() != DataTypes.TypeCategory.CLASS)) {
        return val;
    }
    ImmutableMap.Builder b = ImmutableMap.builder();
    for (Map.Entry elem : (Iterable<Map.Entry>) val.entrySet()) {
        Object oldKey = elem.getKey();
        Object oldValue = elem.getValue();
        Object newKey = oldKey;
        Object newValue = oldValue;
        if (oldKey instanceof Id) {
            Id id = (Id) elem;
            ITypedReferenceableInstance r = getInstance(id);
        }
        if (oldValue instanceof Id) {
            Id id = (Id) elem;
            ITypedReferenceableInstance r = getInstance(id);
        }
        b.put(newKey, newValue);
    }
    return b.build();
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) Id(org.apache.atlas.typesystem.persistence.Id) ImmutableMap(com.google.common.collect.ImmutableMap) HashMap(java.util.HashMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 3 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class SoftDeleteHandlerV1Test method assertProcessForTestDeleteReference.

@Override
protected void assertProcessForTestDeleteReference(final AtlasEntityHeader processInstance) throws Exception {
    // 
    ITypedReferenceableInstance process = metadataService.getEntityDefinition(processInstance.getGuid());
    List<ITypedReferenceableInstance> outputs = (List<ITypedReferenceableInstance>) process.get(AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS);
    List<ITypedReferenceableInstance> expectedOutputs = (List<ITypedReferenceableInstance>) process.get(AtlasClient.PROCESS_ATTRIBUTE_OUTPUTS);
    assertEquals(outputs.size(), expectedOutputs.size());
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) List(java.util.List)

Example 4 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class SoftDeleteHandlerV1Test method assertTestUpdateEntity_MultiplicityOneNonCompositeReference.

@Override
protected void assertTestUpdateEntity_MultiplicityOneNonCompositeReference(final String janeGuid) throws Exception {
    // Verify Jane's subordinates reference cardinality is still 2.
    ITypedReferenceableInstance jane = metadataService.getEntityDefinition(janeGuid);
    List<ITypedReferenceableInstance> subordinates = (List<ITypedReferenceableInstance>) jane.get("subordinates");
    Assert.assertEquals(subordinates.size(), 2);
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) List(java.util.List)

Example 5 with ITypedReferenceableInstance

use of org.apache.atlas.typesystem.ITypedReferenceableInstance in project incubator-atlas by apache.

the class HardDeleteHandlerV1Test method assertMaxForTestDisconnectBidirectionalReferences.

@Override
protected void assertMaxForTestDisconnectBidirectionalReferences(Map<String, String> nameGuidMap) throws Exception {
    // Verify that the Department.employees reference to the deleted employee
    // was disconnected.
    ITypedReferenceableInstance hrDept = metadataService.getEntityDefinition(nameGuidMap.get("hr"));
    List<ITypedReferenceableInstance> employees = (List<ITypedReferenceableInstance>) hrDept.get("employees");
    Assert.assertEquals(employees.size(), 3);
    String maxGuid = nameGuidMap.get("Max");
    for (ITypedReferenceableInstance employee : employees) {
        Assert.assertNotEquals(employee.getId()._getId(), maxGuid);
    }
    // Verify that the Manager.subordinates reference to the deleted employee
    // Max was disconnected.
    ITypedReferenceableInstance jane = metadataService.getEntityDefinition(nameGuidMap.get("Jane"));
    List<ITypedReferenceableInstance> subordinates = (List<ITypedReferenceableInstance>) jane.get("subordinates");
    assertEquals(subordinates.size(), 1);
    // Verify that max's Person.mentor unidirectional reference to john was disconnected.
    ITypedReferenceableInstance john = metadataService.getEntityDefinition(nameGuidMap.get("John"));
    assertNull(john.get("mentor"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) 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