Search in sources :

Example 1 with AtlasClassificationDef

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

the class AtlasClassificationDefStoreV1 method getByName.

@Override
public AtlasClassificationDef getByName(String name) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.getByName({})", name);
    }
    AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT);
    if (vertex == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name);
    }
    vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, TypeCategory.class);
    AtlasClassificationDef ret = toClassificationDef(vertex);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.getByName({}): {}", name, ret);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex)

Example 2 with AtlasClassificationDef

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

the class AtlasClassificationDefStoreV1 method update.

@Override
public AtlasClassificationDef update(AtlasClassificationDef classifiDef) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasClassificationDefStoreV1.update({})", classifiDef);
    }
    validateType(classifiDef);
    AtlasClassificationDef ret = StringUtils.isNotBlank(classifiDef.getGuid()) ? updateByGuid(classifiDef.getGuid(), classifiDef) : updateByName(classifiDef.getName(), classifiDef);
    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasClassificationDefStoreV1.update({}): {}", classifiDef, ret);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef)

Example 3 with AtlasClassificationDef

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

the class TypeConverterUtil method toAtlasClassificationDefs.

private static List<AtlasClassificationDef> toAtlasClassificationDefs(List<HierarchicalTypeDefinition<TraitType>> traitTypeDefinitions) throws AtlasBaseException {
    List<AtlasClassificationDef> ret = new ArrayList<AtlasClassificationDef>();
    for (HierarchicalTypeDefinition<TraitType> traitType : traitTypeDefinitions) {
        AtlasClassificationDef classifDef = new AtlasClassificationDef();
        List<AtlasAttributeDef> attrDefs = new ArrayList<AtlasAttributeDef>();
        classifDef.setName(traitType.typeName);
        classifDef.setDescription(traitType.typeDescription);
        classifDef.setTypeVersion(traitType.typeVersion);
        classifDef.setSuperTypes(traitType.superTypes);
        AttributeDefinition[] attrDefinitions = traitType.attributeDefinitions;
        for (AttributeDefinition attrDefinition : attrDefinitions) {
            attrDefs.add(toAtlasAttributeDef(attrDefinition));
        }
        classifDef.setAttributeDefs(attrDefs);
        ret.add(classifDef);
    }
    return ret;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) TraitType(org.apache.atlas.typesystem.types.TraitType) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) ArrayList(java.util.ArrayList) AttributeDefinition(org.apache.atlas.typesystem.types.AttributeDefinition)

Example 4 with AtlasClassificationDef

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

the class TypeDefSorter method addToResult.

private static <T extends AtlasStructDef> void addToResult(T type, List<T> result, Set<T> processed, Map<String, T> typesByName) {
    if (processed.contains(type)) {
        return;
    }
    processed.add(type);
    Set<String> superTypeNames = new HashSet<>();
    if (type.getClass().equals(AtlasClassificationDef.class)) {
        try {
            AtlasClassificationDef classificationDef = AtlasClassificationDef.class.cast(type);
            superTypeNames.addAll(classificationDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to ClassificationDef failed");
        }
    }
    if (type.getClass().equals(AtlasEntityDef.class)) {
        try {
            AtlasEntityDef entityDef = AtlasEntityDef.class.cast(type);
            superTypeNames.addAll(entityDef.getSuperTypes());
        } catch (ClassCastException ex) {
            LOG.warn("Casting to AtlasEntityDef failed");
        }
    }
    for (String superTypeName : superTypeNames) {
        // Recursively add any supertypes first to the result.
        T superType = typesByName.get(superTypeName);
        if (superType != null) {
            addToResult(superType, result, processed, typesByName);
        }
    }
    result.add(type);
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) HashSet(java.util.HashSet)

Example 5 with AtlasClassificationDef

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

the class TypedefsJerseyResourceIT method createHiveTypesV2.

private AtlasTypesDef createHiveTypesV2() throws Exception {
    AtlasTypesDef atlasTypesDef = new AtlasTypesDef();
    AtlasEntityDef databaseTypeDefinition = createClassTypeDef("database", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"));
    atlasTypesDef.getEntityDefs().add(databaseTypeDefinition);
    AtlasEntityDef tableTypeDefinition = createClassTypeDef("table", ImmutableSet.<String>of(), AtlasTypeUtil.createUniqueRequiredAttrDef("name", "string"), AtlasTypeUtil.createRequiredAttrDef("description", "string"), AtlasTypeUtil.createOptionalAttrDef("columnNames", DataTypes.arrayTypeName("string")), AtlasTypeUtil.createOptionalAttrDef("created", "date"), AtlasTypeUtil.createOptionalAttrDef("parameters", DataTypes.mapTypeName("string", "string")), AtlasTypeUtil.createRequiredAttrDef("type", "string"), new AtlasAttributeDef("database", "database", false, Cardinality.SINGLE, 1, 1, true, true, Collections.<AtlasConstraintDef>emptyList()));
    atlasTypesDef.getEntityDefs().add(tableTypeDefinition);
    AtlasClassificationDef fetlTypeDefinition = AtlasTypeUtil.createTraitTypeDef("fetl", ImmutableSet.<String>of(), AtlasTypeUtil.createRequiredAttrDef("level", "int"));
    atlasTypesDef.getClassificationDefs().add(fetlTypeDefinition);
    return atlasTypesDef;
}
Also used : AtlasClassificationDef(org.apache.atlas.model.typedef.AtlasClassificationDef) AtlasEntityDef(org.apache.atlas.model.typedef.AtlasEntityDef) AtlasAttributeDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef) AtlasConstraintDef(org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef)

Aggregations

AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)45 AtlasEntityDef (org.apache.atlas.model.typedef.AtlasEntityDef)24 AtlasTypesDef (org.apache.atlas.model.typedef.AtlasTypesDef)22 AtlasStructDef (org.apache.atlas.model.typedef.AtlasStructDef)21 AtlasEnumDef (org.apache.atlas.model.typedef.AtlasEnumDef)18 Test (org.testng.annotations.Test)16 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)13 ArrayList (java.util.ArrayList)8 AtlasAttributeDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasAttributeDef)8 AtlasEnumElementDef (org.apache.atlas.model.typedef.AtlasEnumDef.AtlasEnumElementDef)5 AtlasConstraintDef (org.apache.atlas.model.typedef.AtlasStructDef.AtlasConstraintDef)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 HashMap (java.util.HashMap)4 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)4 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)4 AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 AtlasTransientTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry.AtlasTransientTypeRegistry)3 AtlasServiceException (org.apache.atlas.AtlasServiceException)2 GraphTransaction (org.apache.atlas.annotation.GraphTransaction)2