Search in sources :

Example 1 with AtlasEnumElementDef

use of org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef in project incubator-atlas by apache.

the class AtlasEnumDefStoreV1 method toEnumDef.

private static AtlasEnumDef toEnumDef(AtlasVertex vertex, AtlasEnumDef enumDef, AtlasTypeDefGraphStoreV1 typeDefStore) {
    AtlasEnumDef ret = enumDef != null ? enumDef : new AtlasEnumDef();
    typeDefStore.vertexToTypeDef(vertex, ret);
    List<AtlasEnumElementDef> elements = new ArrayList<>();
    List<String> elemValues = vertex.getProperty(AtlasGraphUtilsV1.getTypeDefPropertyKey(ret), List.class);
    for (String elemValue : elemValues) {
        String elemKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(ret, elemValue);
        String descKey = AtlasGraphUtilsV1.getTypeDefPropertyKey(elemKey, "description");
        Integer ordinal = AtlasGraphUtilsV1.getProperty(vertex, elemKey, Integer.class);
        String desc = AtlasGraphUtilsV1.getProperty(vertex, descKey, String.class);
        elements.add(new AtlasEnumElementDef(elemValue, desc, ordinal));
    }
    ret.setElementDefs(elements);
    return ret;
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) ArrayList(java.util.ArrayList) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 2 with AtlasEnumElementDef

use of org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef in project incubator-atlas by apache.

the class TestAtlasEnumDef method testEnumDefAddElement.

@Test
public void testEnumDefAddElement() {
    AtlasEnumDef enumDef = ModelTestUtil.newEnumDef();
    String newElement = "newElement-abcd-1234";
    enumDef.addElement(new AtlasEnumElementDef(newElement, "A new element", enumDef.getElementDefs().size()));
    assertTrue(enumDef.hasElement(newElement));
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) Test(org.testng.annotations.Test)

Example 3 with AtlasEnumElementDef

use of org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef in project incubator-atlas by apache.

the class TestUtilsV2 method simpleTypeUpdated.

public static AtlasTypesDef simpleTypeUpdated() {
    AtlasEntityDef superTypeDefinition = AtlasTypeUtil.createClassTypeDef("h_type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
    AtlasEntityDef newSuperTypeDefinition = AtlasTypeUtil.createClassTypeDef("new_h_type", ImmutableSet.<String>of(), AtlasTypeUtil.createOptionalAttrDef("attr", "string"));
    AtlasStructDef structTypeDefinition = new AtlasStructDef("s_type", "structType", "1.0", Arrays.asList(AtlasTypeUtil.createRequiredAttrDef("name", "string")));
    AtlasClassificationDef traitTypeDefinition = AtlasTypeUtil.createTraitTypeDef("t_type", "traitType", ImmutableSet.<String>of());
    AtlasEnumDef enumTypeDefinition = new AtlasEnumDef("e_type", "enumType", Arrays.asList(new AtlasEnumElementDef("ONE", "Element Description", 1)));
    return AtlasTypeUtil.getTypesDef(ImmutableList.of(enumTypeDefinition), ImmutableList.of(structTypeDefinition), ImmutableList.of(traitTypeDefinition), ImmutableList.of(superTypeDefinition, newSuperTypeDefinition));
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 4 with AtlasEnumElementDef

use of org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef in project incubator-atlas by apache.

the class TestAtlasEnumDef method testEnumDefSetElementDefs.

@Test
public void testEnumDefSetElementDefs() {
    AtlasEnumDef enumDef = ModelTestUtil.newEnumDef();
    List<AtlasEnumElementDef> oldElements = enumDef.getElementDefs();
    List<AtlasEnumElementDef> newElements = new ArrayList<>();
    newElements.add(new AtlasEnumElementDef("newElement", "new Element", 100));
    enumDef.setElementDefs(newElements);
    for (AtlasEnumElementDef elementDef : oldElements) {
        assertFalse(enumDef.hasElement(elementDef.getValue()));
    }
    for (AtlasEnumElementDef elementDef : newElements) {
        assertTrue(enumDef.hasElement(elementDef.getValue()));
    }
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) ArrayList(java.util.ArrayList) Test(org.testng.annotations.Test)

Example 5 with AtlasEnumElementDef

use of org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef in project incubator-atlas by apache.

the class TestAtlasEnumDef method testEnumDefHasElement.

@Test
public void testEnumDefHasElement() {
    AtlasEnumDef enumDef = ModelTestUtil.getEnumDef();
    for (AtlasEnumElementDef elementDef : enumDef.getElementDefs()) {
        assertTrue(enumDef.hasElement(elementDef.getValue()));
    }
    assertFalse(enumDef.hasElement("01234-xyzabc-;''-)("));
}
Also used : AtlasEnumElementDef(org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef) Test(org.testng.annotations.Test)

Aggregations

AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)14 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)8 ArrayList (java.util.ArrayList)7 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)6 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)6 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)5 HashMap (java.util.HashMap)4 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)4 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)4 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)3 Test (org.testng.annotations.Test)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEnumType (org.apache.atlas.type.AtlasEnumType)2 EnumValue (org.apache.atlas.typesystem.types.EnumValue)2 Map (java.util.Map)1 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)1