Search in sources :

Example 21 with IStruct

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

the class EntityNotificationImplTest method testGetAllTraitsSuperTraits.

@Test
public void testGetAllTraitsSuperTraits() throws Exception {
    TypeSystem typeSystem = mock(TypeSystem.class);
    String traitName = "MyTrait";
    IStruct myTrait = new Struct(traitName);
    String superTraitName = "MySuperTrait";
    TraitType traitDef = mock(TraitType.class);
    Set<String> superTypeNames = Collections.singleton(superTraitName);
    TraitType superTraitDef = mock(TraitType.class);
    Set<String> superSuperTypeNames = Collections.emptySet();
    Referenceable entity = getEntity("id", myTrait);
    when(typeSystem.getDataType(TraitType.class, traitName)).thenReturn(traitDef);
    when(typeSystem.getDataType(TraitType.class, superTraitName)).thenReturn(superTraitDef);
    when(traitDef.getAllSuperTypeNames()).thenReturn(superTypeNames);
    when(superTraitDef.getAllSuperTypeNames()).thenReturn(superSuperTypeNames);
    EntityNotificationImpl entityNotification = new EntityNotificationImpl(entity, EntityNotification.OperationType.TRAIT_ADD, typeSystem);
    List<IStruct> allTraits = entityNotification.getAllTraits();
    assertEquals(2, allTraits.size());
    for (IStruct trait : allTraits) {
        String typeName = trait.getTypeName();
        assertTrue(typeName.equals(traitName) || typeName.equals(superTraitName));
    }
}
Also used : TypeSystem(org.apache.atlas.typesystem.types.TypeSystem) Referenceable(org.apache.atlas.typesystem.Referenceable) TraitType(org.apache.atlas.typesystem.types.TraitType) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) Test(org.testng.annotations.Test)

Example 22 with IStruct

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

the class EntityNotificationImplTest method getEntity.

public static Referenceable getEntity(String id, IStruct... traits) {
    String typeName = "typeName";
    Map<String, Object> values = new HashMap<>();
    List<String> traitNames = new LinkedList<>();
    Map<String, IStruct> traitMap = new HashMap<>();
    for (IStruct trait : traits) {
        String traitName = trait.getTypeName();
        traitNames.add(traitName);
        traitMap.put(traitName, trait);
    }
    return new Referenceable(id, typeName, values, traitNames, traitMap);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct)

Example 23 with IStruct

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

the class NotificationEntityChangeListener method getSuperTraits.

private static List<IStruct> getSuperTraits(String typeName, Map<String, Object> values, TypeSystem typeSystem) throws AtlasException {
    List<IStruct> superTypes = new LinkedList<>();
    TraitType traitDef = typeSystem.getDataType(TraitType.class, typeName);
    Set<String> superTypeNames = traitDef.getAllSuperTypeNames();
    for (String superTypeName : superTypeNames) {
        TraitType superTraitDef = typeSystem.getDataType(TraitType.class, superTypeName);
        Map<String, Object> superTypeValues = new HashMap<>();
        FieldMapping fieldMapping = superTraitDef.fieldMapping();
        if (fieldMapping != null) {
            Set<String> superTypeAttributeNames = fieldMapping.fields.keySet();
            for (String superTypeAttributeName : superTypeAttributeNames) {
                if (values.containsKey(superTypeAttributeName)) {
                    superTypeValues.put(superTypeAttributeName, values.get(superTypeAttributeName));
                }
            }
        }
        IStruct superTrait = new Struct(superTypeName, superTypeValues);
        superTypes.add(superTrait);
        superTypes.addAll(getSuperTraits(superTypeName, values, typeSystem));
    }
    return superTypes;
}
Also used : HashMap(java.util.HashMap) TraitType(org.apache.atlas.typesystem.types.TraitType) FieldMapping(org.apache.atlas.typesystem.types.FieldMapping) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 24 with IStruct

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

the class KafkaConsumerTest method getEntity.

private Referenceable getEntity(String traitName) {
    Referenceable entity = EntityNotificationImplTest.getEntity("id");
    List<IStruct> traitInfo = new LinkedList<>();
    IStruct trait = new Struct(traitName, Collections.<String, Object>emptyMap());
    traitInfo.add(trait);
    return entity;
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) LinkedList(java.util.LinkedList) IStruct(org.apache.atlas.typesystem.IStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 25 with IStruct

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

the class DefaultMetadataServiceTest method testAddDeleteTrait.

@Test
public void testAddDeleteTrait() throws Exception {
    Referenceable entity = createDBEntity();
    String id = TestUtils.createInstance(metadataService, entity);
    //add trait
    Struct tag = new Struct(TestUtils.PII);
    metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
    List<String> traits = metadataService.getTraitNames(id);
    assertEquals(traits.size(), 1);
    assertEquals(traits.get(0), PII);
    //getTrait
    IStruct traitDefinition = metadataService.getTraitDefinition(id, PII);
    Assert.assertNotNull(traitDefinition);
    assertEquals(traitDefinition.getValuesMap().size(), 0);
    //delete trait
    metadataService.deleteTrait(id, PII);
    traits = metadataService.getTraitNames(id);
    assertEquals(traits.size(), 0);
    //add trait again
    metadataService.addTrait(id, InstanceSerialization.toJson(tag, true));
    traits = metadataService.getTraitNames(id);
    assertEquals(traits.size(), 1);
    assertEquals(traits.get(0), PII);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct) IStruct(org.apache.atlas.typesystem.IStruct) Test(org.testng.annotations.Test) AfterTest(org.testng.annotations.AfterTest) BeforeTest(org.testng.annotations.BeforeTest)

Aggregations

IStruct (org.apache.atlas.typesystem.IStruct)34 Struct (org.apache.atlas.typesystem.Struct)16 Test (org.testng.annotations.Test)12 LinkedList (java.util.LinkedList)11 Referenceable (org.apache.atlas.typesystem.Referenceable)11 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)10 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)8 HashMap (java.util.HashMap)7 TraitType (org.apache.atlas.typesystem.types.TraitType)6 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 Map (java.util.Map)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ArrayList (java.util.ArrayList)3 AtlasException (org.apache.atlas.AtlasException)3 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)3 Id (org.apache.atlas.typesystem.persistence.Id)3 List (java.util.List)2 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)2