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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations