Search in sources :

Example 1 with ConverterContext

use of org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext in project incubator-atlas by apache.

the class AtlasInstanceConverter method toAtlasEntities.

public AtlasEntitiesWithExtInfo toAtlasEntities(String entitiesJson) throws AtlasBaseException, AtlasException {
    ITypedReferenceableInstance[] referenceables = metadataService.deserializeClassInstances(entitiesJson);
    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    ConverterContext context = new ConverterContext();
    AtlasEntitiesWithExtInfo ret = null;
    if (referenceables != null) {
        for (IReferenceableInstance referenceable : referenceables) {
            AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
            if (entityType == null) {
                throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
            }
            AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, context);
            context.addEntity(entity);
        }
        ret = context.getEntities();
    }
    return ret;
}
Also used : IReferenceableInstance(org.apache.atlas.typesystem.IReferenceableInstance) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ITypedReferenceableInstance(org.apache.atlas.typesystem.ITypedReferenceableInstance) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 2 with ConverterContext

use of org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext in project incubator-atlas by apache.

the class AtlasInstanceConverter method getTrait.

public ITypedStruct getTrait(AtlasClassification classification) throws AtlasBaseException {
    AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.CLASSIFICATION);
    AtlasType classificationType = typeRegistry.getType(classification.getTypeName());
    Struct trait = (Struct) converter.fromV2ToV1(classification, classificationType, new ConverterContext());
    try {
        return metadataService.createTraitInstance(trait);
    } catch (AtlasException e) {
        LOG.error("Exception while getting a typed reference for the entity ", e);
        throw toAtlasBaseException(e);
    }
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasType(org.apache.atlas.type.AtlasType) AtlasException(org.apache.atlas.AtlasException) ITypedStruct(org.apache.atlas.typesystem.ITypedStruct) IStruct(org.apache.atlas.typesystem.IStruct) Struct(org.apache.atlas.typesystem.Struct)

Example 3 with ConverterContext

use of org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext in project incubator-atlas by apache.

the class AtlasInstanceConverter method toAtlasEntity.

public AtlasEntitiesWithExtInfo toAtlasEntity(IReferenceableInstance referenceable) throws AtlasBaseException {
    AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(referenceable.getTypeName());
    if (entityType == null) {
        throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), referenceable.getTypeName());
    }
    // validate
    try {
        metadataService.validateAndConvertToTypedInstance(referenceable, entityType.getTypeName());
    } catch (AtlasException excp) {
        throw toAtlasBaseException(excp);
    }
    ConverterContext ctx = new ConverterContext();
    AtlasEntity entity = converter.fromV1ToV2(referenceable, entityType, ctx);
    ctx.addEntity(entity);
    return ctx.getEntities();
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasException(org.apache.atlas.AtlasException) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

ConverterContext (org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext)3 AtlasException (org.apache.atlas.AtlasException)2 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)2 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)2 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)2 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)1 AtlasType (org.apache.atlas.type.AtlasType)1 IReferenceableInstance (org.apache.atlas.typesystem.IReferenceableInstance)1 IStruct (org.apache.atlas.typesystem.IStruct)1 ITypedReferenceableInstance (org.apache.atlas.typesystem.ITypedReferenceableInstance)1 ITypedStruct (org.apache.atlas.typesystem.ITypedStruct)1 Struct (org.apache.atlas.typesystem.Struct)1