Search in sources :

Example 1 with IStruct

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

the class SoftDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(final String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were not disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNotNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNotNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 2 with IStruct

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

the class HardDeleteHandlerV1Test method assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes.

@Override
protected void assertTestDisconnectUnidirectionalArrayReferenceFromStructAndTraitTypes(String structContainerGuid) throws Exception {
    // Verify that the unidirectional references from the struct and trait instances
    // to the deleted entities were disconnected.
    ITypedReferenceableInstance structContainerConvertedEntity = metadataService.getEntityDefinition(structContainerGuid);
    ITypedStruct struct = (ITypedStruct) structContainerConvertedEntity.get("struct");
    assertNull(struct.get("target"));
    IStruct trait = structContainerConvertedEntity.getTrait("TestTrait");
    assertNotNull(trait);
    assertNull(trait.get("target"));
}
Also used : ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct)

Example 3 with IStruct

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

the class DefaultMetadataServiceTest method assertReferenceableEquals.

//equals excluding the id
private void assertReferenceableEquals(Referenceable actual, Referenceable expected) {
    List<String> traits = actual.getTraits();
    Map<String, IStruct> traitsMap = new HashMap<>();
    for (String trait : traits) {
        traitsMap.put(trait, actual.getTrait(trait));
    }
    Referenceable newActual = new Referenceable(expected.getId(), actual.getTypeName(), actual.getValuesMap(), traits, traitsMap);
    assertEquals(newActual, expected);
}
Also used : Referenceable(org.apache.atlas.typesystem.Referenceable) HashMap(java.util.HashMap) IStruct(org.apache.atlas.typesystem.IStruct)

Example 4 with IStruct

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

the class AtlasStructFormatConverter method fromV1ToV2.

@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    AtlasStruct ret = null;
    if (v1Obj != null) {
        AtlasStructType structType = (AtlasStructType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
            } else {
                ret = new AtlasStruct(type.getTypeName());
            }
        } else if (v1Obj instanceof IStruct) {
            IStruct struct = (IStruct) v1Obj;
            Map<String, Object> v1Attribs = null;
            try {
                v1Attribs = struct.getValuesMap();
            } catch (AtlasException excp) {
                LOG.error("IStruct.getValuesMap() failed", excp);
            }
            ret = new AtlasStruct(type.getTypeName(), fromV1ToV2(structType, v1Attribs, converterContext));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasException(org.apache.atlas.AtlasException) HashMap(java.util.HashMap) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 5 with IStruct

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

the class GraphBackedMetadataRepositoryTest method testAddTraitWithAttribute.

@Test(dependsOnMethods = "testAddTrait")
public void testAddTraitWithAttribute() throws Exception {
    final String aGUID = getGUID();
    final String traitName = "P_I_I";
    HierarchicalTypeDefinition<TraitType> piiTrait = TypesUtil.createTraitTypeDef(traitName, ImmutableSet.<String>of(), TypesUtil.createRequiredAttrDef("type", DataTypes.STRING_TYPE));
    TraitType traitType = typeSystem.defineTraitType(piiTrait);
    ITypedStruct traitInstance = traitType.createInstance();
    traitInstance.set("type", "SSN");
    repositoryService.addTrait(aGUID, traitInstance);
    TestUtils.dumpGraph(TestUtils.getGraph());
    // refresh trait names
    List<String> traitNames = repositoryService.getTraitNames(aGUID);
    Assert.assertEquals(traitNames.size(), 3);
    Assert.assertTrue(traitNames.contains(traitName));
    ITypedReferenceableInstance instance = repositoryService.getEntityDefinition(aGUID);
    IStruct traitInstanceRef = instance.getTrait(traitName);
    String type = (String) traitInstanceRef.get("type");
    Assert.assertEquals(type, "SSN");
}
Also used : TraitType(org.apache.atlas.typesystem.types.TraitType) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Test(org.testng.annotations.Test)

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