Search in sources :

Example 11 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.

the class AtlasClassificationFormatConverter method fromV1ToV2.

@Override
public AtlasClassification fromV1ToV2(Object v1Obj, AtlasType type, ConverterContext ctx) throws AtlasBaseException {
    AtlasClassification ret = null;
    if (v1Obj != null) {
        AtlasClassificationType classificationType = (AtlasClassificationType) type;
        if (v1Obj instanceof Map) {
            final Map v1Map = (Map) v1Obj;
            final Map v1Attribs = (Map) v1Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isNotEmpty(v1Attribs)) {
                ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
            } else {
                ret = new AtlasClassification(type.getTypeName());
            }
        } else if (v1Obj instanceof IStruct) {
            IStruct struct = (IStruct) v1Obj;
            Map<String, Object> v1Attribs = null;
            try {
                v1Attribs = struct.getValuesMap();
            } catch (AtlasException excp) {
                LOG.error("IStruct.getValuesMap() failed", excp);
            }
            ret = new AtlasClassification(type.getTypeName(), fromV1ToV2(classificationType, v1Attribs, ctx));
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or IStruct", v1Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasException(org.apache.atlas.AtlasException) Map(java.util.Map) IStruct(org.apache.atlas.typesystem.IStruct)

Example 12 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method validateAndNormalize.

private void validateAndNormalize(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());
    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }
    List<String> messages = new ArrayList<>();
    type.validateValue(classification, classification.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }
    type.getNormalizedValue(classification);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 13 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.

the class AtlasEntityStoreV1 method validateAndNormalizeForUpdate.

private void validateAndNormalizeForUpdate(AtlasClassification classification) throws AtlasBaseException {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classification.getTypeName());
    if (type == null) {
        throw new AtlasBaseException(AtlasErrorCode.CLASSIFICATION_NOT_FOUND, classification.getTypeName());
    }
    List<String> messages = new ArrayList<>();
    type.validateValueForUpdate(classification, classification.getTypeName(), messages);
    if (!messages.isEmpty()) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, messages);
    }
    type.getNormalizedValueForUpdate(classification);
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ArrayList(java.util.ArrayList) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 14 with AtlasClassificationType

use of org.apache.atlas.type.AtlasClassificationType in project incubator-atlas by apache.

the class AtlasTypeDefGraphStore method searchTypesDef.

@Override
public AtlasTypesDef searchTypesDef(SearchFilter searchFilter) throws AtlasBaseException {
    final AtlasTypesDef typesDef = new AtlasTypesDef();
    Predicate searchPredicates = FilterUtil.getPredicateFromSearchFilter(searchFilter);
    for (AtlasEnumType enumType : typeRegistry.getAllEnumTypes()) {
        if (searchPredicates.evaluate(enumType)) {
            typesDef.getEnumDefs().add(enumType.getEnumDef());
        }
    }
    for (AtlasStructType structType : typeRegistry.getAllStructTypes()) {
        if (searchPredicates.evaluate(structType)) {
            typesDef.getStructDefs().add(structType.getStructDef());
        }
    }
    for (AtlasClassificationType classificationType : typeRegistry.getAllClassificationTypes()) {
        if (searchPredicates.evaluate(classificationType)) {
            typesDef.getClassificationDefs().add(classificationType.getClassificationDef());
        }
    }
    for (AtlasEntityType entityType : typeRegistry.getAllEntityTypes()) {
        if (searchPredicates.evaluate(entityType)) {
            typesDef.getEntityDefs().add(entityType.getEntityDef());
        }
    }
    return typesDef;
}
Also used : AtlasEnumType(org.apache.atlas.type.AtlasEnumType) AtlasStructType(org.apache.atlas.type.AtlasStructType) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) AtlasTypesDef(org.apache.atlas.model.typedef.AtlasTypesDef) Predicate(org.apache.commons.collections.Predicate)

Aggregations

AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)14 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)5 ArrayList (java.util.ArrayList)3 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)3 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)3 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)3 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)3 Test (org.testng.annotations.Test)3 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)2 AtlasEnumType (org.apache.atlas.type.AtlasEnumType)2 AtlasStructType (org.apache.atlas.type.AtlasStructType)2 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 ScriptEngine (javax.script.ScriptEngine)1 ScriptException (javax.script.ScriptException)1 AtlasException (org.apache.atlas.AtlasException)1 AtlasSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult)1 AtlasFullTextResult (org.apache.atlas.model.discovery.AtlasSearchResult.AtlasFullTextResult)1 AttributeSearchResult (org.apache.atlas.model.discovery.AtlasSearchResult.AttributeSearchResult)1