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