Search in sources :

Example 21 with AtlasClassificationType

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

the class EntityGraphMapper method validateAndNormalizeForUpdate.

public 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) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 22 with AtlasClassificationType

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

the class EntityGraphMapper method createClassificationVertex.

private AtlasVertex createClassificationVertex(AtlasClassification classification) {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> createVertex({})", classification.getTypeName());
    }
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classification.getTypeName());
    AtlasVertex ret = createStructVertex(classification);
    AtlasGraphUtilsV1.addProperty(ret, Constants.SUPER_TYPES_PROPERTY_KEY, classificationType.getAllSuperTypes());
    AtlasGraphUtilsV1.setProperty(ret, Constants.CLASSIFICATION_ENTITY_GUID, classification.getEntityGuid());
    return ret;
}
Also used : AtlasVertex(org.apache.atlas.repository.graphdb.AtlasVertex) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Example 23 with AtlasClassificationType

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

the class AtlasEntityFormatConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext context) throws AtlasBaseException {
    Object ret = null;
    if (v2Obj != null) {
        AtlasEntityType entityType = (AtlasEntityType) type;
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = type.getTypeName();
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            final Map v2Attribs = (Map) v2Map.get(ATTRIBUTES_PROPERTY_KEY);
            if (MapUtils.isEmpty(v2Attribs)) {
                ret = new Id(idStr, 0, typeName);
            } else {
                ret = new Referenceable(idStr, typeName, super.fromV2ToV1(entityType, v2Attribs, context));
            }
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            Status status = entity.getStatus();
            if (status == null) {
                status = Status.ACTIVE;
            }
            Referenceable referenceable = new Referenceable(entity.getGuid(), entity.getTypeName(), status.name(), fromV2ToV1(entityType, entity.getAttributes(), context), new AtlasSystemAttributes(entity.getCreatedBy(), entity.getUpdatedBy(), entity.getCreateTime(), entity.getUpdateTime()));
            if (CollectionUtils.isNotEmpty(entity.getClassifications())) {
                for (AtlasClassification classification : entity.getClassifications()) {
                    String traitName = classification.getTypeName();
                    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(traitName);
                    AtlasFormatConverter formatConverter = classificationType != null ? converterRegistry.getConverter(classificationType.getTypeCategory()) : null;
                    Struct trait = formatConverter != null ? (Struct) formatConverter.fromV2ToV1(classification, classificationType, context) : null;
                    if (trait != null) {
                        referenceable.getTraitNames().add(trait.getTypeName());
                        referenceable.getTraits().put(trait.getTypeName(), trait);
                    }
                }
            }
            ret = referenceable;
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            AtlasEntity entity = context.getById(((AtlasObjectId) v2Obj).getGuid());
            if (entity == null) {
                throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "Could not find entity ", v2Obj.toString());
            }
            ret = this.fromV2ToV1(entity, typeRegistry.getType(((AtlasObjectId) v2Obj).getTypeName()), context);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.UNEXPECTED_TYPE, "Map or AtlasEntity or String", v2Obj.getClass().getCanonicalName());
        }
    }
    return ret;
}
Also used : Status(org.apache.atlas.model.instance.AtlasEntity.Status) AtlasSystemAttributes(org.apache.atlas.v1.model.instance.AtlasSystemAttributes) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Struct(org.apache.atlas.v1.model.instance.Struct) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification) AtlasEntityType(org.apache.atlas.type.AtlasEntityType) Map(java.util.Map)

Example 24 with AtlasClassificationType

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

the class AtlasInstanceConverter method toAtlasClassification.

public AtlasClassification toAtlasClassification(Struct classification) throws AtlasBaseException {
    AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
    AtlasClassificationType classificationType = typeRegistry.getClassificationTypeByName(classification.getTypeName());
    if (classificationType == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.CLASSIFICATION.name(), classification.getTypeName());
    }
    AtlasClassification ret = (AtlasClassification) converter.fromV1ToV2(classification, classificationType, new AtlasFormatConverter.ConverterContext());
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType) AtlasClassification(org.apache.atlas.model.instance.AtlasClassification)

Example 25 with AtlasClassificationType

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

the class EntityDiscoveryService method getClassificationFilter.

private static String getClassificationFilter(AtlasTypeRegistry typeRegistry, String classificationName, int maxTypesLengthInIdxQuery) {
    AtlasClassificationType type = typeRegistry.getClassificationTypeByName(classificationName);
    String typeAndSubTypesQryStr = type != null ? type.getTypeAndAllSubTypesQryStr() : null;
    if (StringUtils.isNotEmpty(typeAndSubTypesQryStr) && typeAndSubTypesQryStr.length() <= maxTypesLengthInIdxQuery) {
        return typeAndSubTypesQryStr;
    }
    return "";
}
Also used : AtlasClassificationType(org.apache.atlas.type.AtlasClassificationType)

Aggregations

AtlasClassificationType (org.apache.atlas.type.AtlasClassificationType)35 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)12 AtlasClassification (org.apache.atlas.model.instance.AtlasClassification)8 AtlasTypeRegistry (org.apache.atlas.type.AtlasTypeRegistry)8 Test (org.testng.annotations.Test)8 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)7 AtlasClassificationDef (org.apache.atlas.model.typedef.AtlasClassificationDef)6 Struct (org.apache.atlas.v1.model.instance.Struct)6 Map (java.util.Map)5 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)5 AtlasStructType (org.apache.atlas.type.AtlasStructType)3 Referenceable (org.apache.atlas.v1.model.instance.Referenceable)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedList (java.util.LinkedList)2 ConverterContext (org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext)2 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)2 AtlasArrayType (org.apache.atlas.type.AtlasArrayType)2 AtlasEnumType (org.apache.atlas.type.AtlasEnumType)2 AtlasMapType (org.apache.atlas.type.AtlasMapType)2