Java Code Examples for org.apache.atlas.model.typedef.AtlasTypesDef#setClassificationDefs()

The following examples show how to use org.apache.atlas.model.typedef.AtlasTypesDef#setClassificationDefs() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportTransformsShaper.java    From atlas with Apache License 2.0 5 votes vote down vote up
private String getCreateTag(String classificationName) throws AtlasBaseException {
    AtlasClassificationDef classificationDef = typeRegistry.getClassificationDefByName(classificationName);
    if(classificationDef != null) {
        return classificationName;
    }

    classificationDef = new AtlasClassificationDef(classificationName);
    AtlasTypesDef typesDef = new AtlasTypesDef();
    typesDef.setClassificationDefs(Collections.singletonList(classificationDef));
    typeDefStore.createTypesDef(typesDef);
    LOG.info("created classification: {}", classificationName);
    return classificationName;
}
 
Example 2
Source File: TypeConverterUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: AtlasEntityTestBase.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected AtlasClassificationDef getTagWithName(AtlasTypesDef typesDef, String tagName, String attributeType) {
    AtlasClassificationDef aTag = new AtlasClassificationDef(tagName);
    AtlasAttributeDef attributeDef = new AtlasAttributeDef("testAttribute", attributeType, true,
            AtlasAttributeDef.Cardinality.SINGLE, 0, 1, false, true, false,
            Collections.emptyList());

    aTag.addAttribute(attributeDef);
    typesDef.setClassificationDefs(Arrays.asList(aTag));
    return aTag;
}
 
Example 4
Source File: Action.java    From atlas with Apache License 2.0 5 votes vote down vote up
private void createClassificationDefIfNotExists(String classificationName, TransformerContext context) {
    AtlasTypeRegistry typeRegistry = context != null ? context.getTypeRegistry() : null;

    if (typeRegistry != null) {
        try {
            AtlasClassificationDef classificationDef = typeRegistry.getClassificationDefByName(classificationName);

            if (classificationDef == null) {
                AtlasTypeDefStore typeDefStore = context.getTypeDefStore();

                if (typeDefStore != null) {
                    classificationDef = new AtlasClassificationDef(classificationName);

                    AtlasTypesDef typesDef = new AtlasTypesDef();

                    typesDef.setClassificationDefs(Collections.singletonList(classificationDef));

                    typeDefStore.createTypesDef(typesDef);

                    LOG.info("created classification: {}", classificationName);
                } else {
                    LOG.warn("skipped creation of classification {}. typeDefStore is null", classificationName);
                }
            }
        } catch (AtlasBaseException e) {
            LOG.error("Error creating classification: {}", classificationName, e);
        }
    }
}
 
Example 5
Source File: TypeConverterUtil.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
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 = TypesSerialization.fromJson(typeDefinition);
        if (CollectionUtils.isNotEmpty(typesDef.enumTypesAsJavaList())) {
            List<AtlasEnumDef> enumDefs = toAtlasEnumDefs(typesDef.enumTypesAsJavaList());
            ret.setEnumDefs(enumDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.structTypesAsJavaList())) {
            List<AtlasStructDef> structDefs = toAtlasStructDefs(typesDef.structTypesAsJavaList());
            ret.setStructDefs(structDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.classTypesAsJavaList())) {
            List<AtlasEntityDef> entityDefs = toAtlasEntityDefs(typesDef.classTypesAsJavaList(), registry);
            ret.setEntityDefs(entityDefs);
        }

        if (CollectionUtils.isNotEmpty(typesDef.traitTypesAsJavaList())) {
            List<AtlasClassificationDef> classificationDefs = toAtlasClassificationDefs(typesDef.traitTypesAsJavaList());
            ret.setClassificationDefs(classificationDefs);
        }

    } catch (Exception e) {
        LOG.error("Invalid type definition = {}", typeDefinition, e);
        throw new AtlasBaseException(INVALID_TYPE_DEFINITION, typeDefinition);
    }

    return ret;
}