Search in sources :

Example 1 with TypesDef

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

the class TypeConverterUtil method toAtlasTypesDef.

public static AtlasTypesDef toAtlasTypesDef(String typeDefinition, AtlasTypeRegistry registry) throws AtlasBaseException {
    AtlasTypesDef ret = new AtlasTypesDef();
    try {
        if (StringUtils.isEmpty(typeDefinition)) {
            throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
        }
        TypesDef typesDef = AtlasType.fromV1Json(typeDefinition, TypesDef.class);
        if (CollectionUtils.isNotEmpty(typesDef.getEnumTypes())) {
            List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.getEnumTypes());
            ret.setEnumDefs(enumDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getStructTypes())) {
            List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.getStructTypes());
            ret.setStructDefs(structDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getClassTypes())) {
            List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.getClassTypes(), registry);
            ret.setEntityDefs(entityDefs);
        }
        if (CollectionUtils.isNotEmpty(typesDef.getTraitTypes())) {
            List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.getTraitTypes());
            ret.setClassificationDefs(classificationDefs);
        }
    } catch (Exception e) {
        LOG.error("Invalid type definition = {}", typeDefinition, e);
        throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
    }
    return ret;
}
Also used : AtlasStructDef(org.apache.atlas.model.typedef.AtlasStructDef) AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) AtlasEnumDef(org.apache.atlas.model.typedef.AtlasEnumDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Example 2 with TypesDef

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

the class TypeConverterUtil method classificationToTypesDef.

private static TypesDef classificationToTypesDef(AtlasClassificationType classificationType, AtlasTypeRegistry registry) {
    String typeName = classificationType.getClassificationDef().getName();
    String typeDesc = classificationType.getClassificationDef().getDescription();
    String typeVersion = classificationType.getClassificationDef().getTypeVersion();
    Set<String> superTypes = new HashSet<>(classificationType.getClassificationDef().getSuperTypes());
    List<AttributeDefinition> attributes = getAttributes(classificationType, registry);
    TraitTypeDefinition traitTypeDef = new TraitTypeDefinition(typeName, typeDesc, typeVersion, attributes, superTypes);
    TypesDef ret = new TypesDef(null, null, Arrays.asList(traitTypeDef), null);
    return ret;
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) TraitTypeDefinition(org.apache.atlas.v1.model.typedef.TraitTypeDefinition) AttributeDefinition(org.apache.atlas.v1.model.typedef.AttributeDefinition)

Example 3 with TypesDef

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

the class AtlasClient method createTraitType.

/**
 * Creates trait type with specifiedName, superTraits and attributes
 * @param traitName the name of the trait type
 * @param superTraits the list of super traits from which this trait type inherits attributes
 * @param attributeDefinitions the list of attributes of the trait type
 * @return the list of types created
 * @throws AtlasServiceException
 */
public List<String> createTraitType(String traitName, Set<String> superTraits, AttributeDefinition... attributeDefinitions) throws AtlasServiceException {
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, superTraits, Arrays.asList(attributeDefinitions));
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    LOG.debug("Creating trait type {} {}", traitName, AtlasType.toV1Json(piiTrait));
    return createType(AtlasType.toV1Json(typesDef));
}
Also used : TypesDef(org.apache.atlas.v1.model.typedef.TypesDef) TraitTypeDefinition(org.apache.atlas.v1.model.typedef.TraitTypeDefinition)

Example 4 with TypesDef

use of org.apache.atlas.v1.model.typedef.TypesDef 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 5 with TypesDef

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

the class EntityJerseyResourceIT method testAddTrait.

@Test
public void testAddTrait() throws Exception {
    String dbName = "db" + randomString();
    String tableName = "table" + randomString();
    Referenceable hiveDBInstance = createHiveDBInstanceBuiltIn(dbName);
    Id dbId = createInstance(hiveDBInstance);
    Referenceable hiveTableInstance = createHiveTableInstanceBuiltIn(dbName, tableName, dbId);
    Id id = createInstance(hiveTableInstance);
    final String guid = id._getId();
    try {
        Assert.assertNotNull(UUID.fromString(guid));
    } catch (IllegalArgumentException e) {
        Assert.fail("Response is not a guid, " + guid);
    }
    String traitName = "PII_Trait" + randomString();
    TraitTypeDefinition piiTrait = TypesUtil.createTraitTypeDef(traitName, null, Collections.<String>emptySet());
    String traitDefinitionAsJSON = AtlasType.toV1Json(piiTrait);
    LOG.debug("traitDefinitionAsJSON = {}", traitDefinitionAsJSON);
    TypesDef typesDef = new TypesDef(Collections.emptyList(), Collections.emptyList(), Collections.singletonList(piiTrait), Collections.emptyList());
    createType(typesDef);
    Struct traitInstance = new Struct(traitName);
    atlasClientV1.addTrait(guid, traitInstance);
    assertEntityAudit(guid, EntityAuditEvent.EntityAuditAction.TAG_ADD);
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) Id(org.apache.atlas.v1.model.instance.Id) Struct(org.apache.atlas.v1.model.instance.Struct) Test(org.testng.annotations.Test)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)8 Test (org.testng.annotations.Test)8 Id (org.apache.atlas.v1.model.instance.Id)7 TypesDef (org.apache.atlas.v1.model.typedef.TypesDef)7 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)6 Struct (org.apache.atlas.v1.model.instance.Struct)5 AtlasServiceException (org.apache.atlas.AtlasServiceException)3 AttributeDefinition (org.apache.atlas.v1.model.typedef.AttributeDefinition)3 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)2 TraitTypeDefinition (org.apache.atlas.v1.model.typedef.TraitTypeDefinition)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 HashMap (java.util.HashMap)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)1 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)1 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)1