Search in sources :

Example 1 with EnumTypeDefinition

use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition in project atlas by apache.

the class EntityJerseyResourceIT method testUTF8.

@Test
public void testUTF8() throws Exception {
    // Type names cannot be arbitrary UTF8 characters. See org.apache.atlas.type.AtlasTypeUtil#validateType()
    String classType = randomString();
    String attrName = random();
    String attrValue = random();
    ClassTypeDefinition classTypeDefinition = TypesUtil.createClassTypeDef(classType, null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef(attrName, AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Collections.singletonList(classTypeDefinition));
    createType(typesDef);
    Referenceable instance = new Referenceable(classType);
    instance.set(attrName, attrValue);
    Id guid = createInstance(instance);
    ObjectNode response = atlasClientV1.callAPIWithBodyAndParams(AtlasClient.API_V1.GET_ENTITY, null, guid._getId());
    Referenceable getReferenceable = AtlasType.fromV1Json(AtlasType.toJson(response.get(AtlasClient.DEFINITION)), Referenceable.class);
    Assert.assertEquals(getReferenceable.get(attrName), attrValue);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Id(org.apache.atlas.v1.model.instance.Id) Test(org.testng.annotations.Test)

Example 2 with EnumTypeDefinition

use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition in project atlas by apache.

the class BaseResourceIT method createTypeDefinitionsV1.

protected void createTypeDefinitionsV1() throws Exception {
    ClassTypeDefinition dbClsDef = TypesUtil.createClassTypeDef(DATABASE_TYPE, null, null, TypesUtil.createUniqueRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef(DESCRIPTION, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("locationUri", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), new AttributeDefinition("tables", AtlasBaseTypeDef.getArrayTypeName(HIVE_TABLE_TYPE), Multiplicity.OPTIONAL, false, "db"));
    ClassTypeDefinition columnClsDef = TypesUtil.createClassTypeDef(COLUMN_TYPE, null, null, attrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("dataType", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("comment", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    StructTypeDefinition structTypeDefinition = new StructTypeDefinition("serdeType", null, Arrays.asList(new AttributeDefinition[] { TypesUtil.createRequiredAttrDef(NAME, AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createRequiredAttrDef("serde", AtlasBaseTypeDef.ATLAS_TYPE_STRING) }));
    EnumValue[] values = { new EnumValue("MANAGED", 1), new EnumValue("EXTERNAL", 2) };
    EnumTypeDefinition enumTypeDefinition = new EnumTypeDefinition("tableType", null, null, Arrays.asList(values));
    ClassTypeDefinition tblClsDef = TypesUtil.createClassTypeDef(HIVE_TABLE_TYPE, null, Collections.singleton("DataSet"), attrDef("owner", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("createTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("lastAccessTime", AtlasBaseTypeDef.ATLAS_TYPE_DATE), attrDef("temporary", AtlasBaseTypeDef.ATLAS_TYPE_BOOLEAN), new AttributeDefinition("db", DATABASE_TYPE, Multiplicity.OPTIONAL, true, "tables"), new AttributeDefinition("columns", AtlasBaseTypeDef.getArrayTypeName(COLUMN_TYPE), Multiplicity.OPTIONAL, true, null), new AttributeDefinition("tableType", "tableType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde1", "serdeType", Multiplicity.OPTIONAL, false, null), new AttributeDefinition("serde2", "serdeType", Multiplicity.OPTIONAL, false, null));
    ClassTypeDefinition loadProcessClsDef = TypesUtil.createClassTypeDef(HIVE_PROCESS_TYPE, null, Collections.singleton("Process"), attrDef("userName", AtlasBaseTypeDef.ATLAS_TYPE_STRING), attrDef("startTime", AtlasBaseTypeDef.ATLAS_TYPE_INT), attrDef("endTime", AtlasBaseTypeDef.ATLAS_TYPE_LONG), attrDef("queryText", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryPlan", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryId", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED), attrDef("queryGraph", AtlasBaseTypeDef.ATLAS_TYPE_STRING, Multiplicity.REQUIRED));
    TraitTypeDefinition classificationTrait = TypesUtil.createTraitTypeDef("classification", null, Collections.<String>emptySet(), TypesUtil.createRequiredAttrDef("tag", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(PII_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition phiTrait = TypesUtil.createTraitTypeDef(PHI_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition pciTrait = TypesUtil.createTraitTypeDef(PCI_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition soxTrait = TypesUtil.createTraitTypeDef(SOX_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition secTrait = TypesUtil.createTraitTypeDef(SEC_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition financeTrait = TypesUtil.createTraitTypeDef(FINANCE_TAG, null, Collections.<String>emptySet());
    TraitTypeDefinition factTrait = TypesUtil.createTraitTypeDef("Fact" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition etlTrait = TypesUtil.createTraitTypeDef("ETL" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition dimensionTrait = TypesUtil.createTraitTypeDef("Dimension" + randomString(), null, Collections.<String>emptySet());
    TraitTypeDefinition metricTrait = TypesUtil.createTraitTypeDef("Metric" + randomString(), null, Collections.<String>emptySet());
    createType(getTypesDef(Collections.singletonList(enumTypeDefinition), Collections.singletonList(structTypeDefinition), Arrays.asList(classificationTrait, piiTrait, phiTrait, pciTrait, soxTrait, secTrait, financeTrait, factTrait, etlTrait, dimensionTrait, metricTrait), Arrays.asList(dbClsDef, columnClsDef, tblClsDef, loadProcessClsDef)));
}
Also used : EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue)

Example 3 with EnumTypeDefinition

use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition in project atlas by apache.

the class EntityJerseyResourceIT method testEntityDefinitionAcrossTypeUpdate.

@Test
public void testEntityDefinitionAcrossTypeUpdate() throws Exception {
    // create type
    ClassTypeDefinition typeDefinition = TypesUtil.createClassTypeDef(randomString(), null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.emptyList(), Collections.singletonList(typeDefinition));
    atlasClientV1.createType(AtlasType.toV1Json(typesDef));
    // create entity for the type
    Referenceable instance = new Referenceable(typeDefinition.getTypeName());
    instance.set("name", randomString());
    String guid = atlasClientV1.createEntity(instance).get(0);
    // update type - add attribute
    typeDefinition = TypesUtil.createClassTypeDef(typeDefinition.getTypeName(), null, Collections.<String>emptySet(), TypesUtil.createUniqueRequiredAttrDef("name", AtlasBaseTypeDef.ATLAS_TYPE_STRING), TypesUtil.createOptionalAttrDef("description", AtlasBaseTypeDef.ATLAS_TYPE_STRING));
    TypesDef typeDef = new TypesDef(Collections.<EnumTypeDefinition>emptyList(), Collections.<StructTypeDefinition>emptyList(), Collections.<TraitTypeDefinition>emptyList(), Arrays.asList(typeDefinition));
    atlasClientV1.updateType(typeDef);
    // Get definition after type update - new attributes should be null
    Referenceable entity = atlasClientV1.getEntity(guid);
    Assert.assertNull(entity.get("description"));
    Assert.assertEquals(entity.get("name"), instance.get("name"));
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Test(org.testng.annotations.Test)

Example 4 with EnumTypeDefinition

use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition in project atlas by apache.

the class TypeConverterUtil method toAtlasEnumDefs.

private static List<AtlasEnumDef> toAtlasEnumDefs(List<EnumTypeDefinition> enumTypeDefinitions) {
    List<AtlasEnumDef> ret = new ArrayList<AtlasEnumDef>();
    for (EnumTypeDefinition enumType : enumTypeDefinitions) {
        AtlasEnumDef enumDef = new AtlasEnumDef();
        enumDef.setName(enumType.getName());
        enumDef.setDescription(enumType.getDescription());
        enumDef.setTypeVersion(enumType.getVersion());
        enumDef.setElementDefs(getAtlasEnumElementDefs(enumType.getEnumValues()));
        ret.add(enumDef);
    }
    return ret;
}
Also used : EnumTypeDefinition(org.apache.atlas.v1.model.typedef.EnumTypeDefinition) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Example 5 with EnumTypeDefinition

use of org.apache.atlas.v1.model.typedef.EnumTypeDefinition in project atlas by apache.

the class TypeConverterUtil method enumToTypesDef.

private static TypesDef enumToTypesDef(AtlasEnumType enumType) {
    AtlasEnumDef enumDef = enumType.getEnumDef();
    String enumName = enumDef.getName();
    String enumDesc = enumDef.getDescription();
    String enumVersion = enumDef.getTypeVersion();
    List<EnumValue> enumValues = getEnumValues(enumDef.getElementDefs());
    EnumTypeDefinition enumTypeDef = new EnumTypeDefinition(enumName, enumDesc, enumVersion, enumValues);
    TypesDef ret = new TypesDef(Arrays.asList(enumTypeDef), null, null, null);
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) EnumValue(org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue) EnumTypeDefinition(org.apache.atlas.v1.model.typedef.EnumTypeDefinition) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef)

Aggregations

AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)2 EnumTypeDefinition (org.apache.atlas.v1.model.typedef.EnumTypeDefinition)2 EnumValue (org.apache.atlas.v1.model.typedef.EnumTypeDefinition.EnumValue)2 Test (org.testng.annotations.Test)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)1 Id (org.apache.atlas.v1.model.instance.Id)1 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)1