use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class AtlasInstanceConverter method toAtlasEntities.
public AtlasEntity.AtlasEntitiesWithExtInfo toAtlasEntities(List<Referenceable> referenceables) throws AtlasBaseException {
if (LOG.isDebugEnabled()) {
LOG.debug("==> toAtlasEntities({})", referenceables);
}
AtlasFormatConverter.ConverterContext context = new AtlasFormatConverter.ConverterContext();
for (Referenceable referenceable : referenceables) {
AtlasEntity entity = fromV1toV2Entity(referenceable, context);
context.addEntity(entity);
}
AtlasEntity.AtlasEntitiesWithExtInfo ret = context.getEntities();
if (LOG.isDebugEnabled()) {
LOG.debug("<== toAtlasEntities({}): ret=", referenceables, ret);
}
return ret;
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class AtlasInstanceConverter method getReferenceable.
public Referenceable getReferenceable(AtlasEntity entity, final ConverterContext ctx) throws AtlasBaseException {
AtlasFormatConverter converter = instanceFormatters.getConverter(TypeCategory.ENTITY);
AtlasType entityType = typeRegistry.getType(entity.getTypeName());
Referenceable ref = (Referenceable) converter.fromV2ToV1(entity, entityType, ctx);
return ref;
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class AtlasInstanceConverter method getReferenceables.
public Referenceable[] getReferenceables(Collection<AtlasEntity> entities) throws AtlasBaseException {
Referenceable[] ret = new Referenceable[entities.size()];
AtlasFormatConverter.ConverterContext ctx = new AtlasFormatConverter.ConverterContext();
for (Iterator<AtlasEntity> i = entities.iterator(); i.hasNext(); ) {
ctx.addEntity(i.next());
}
Iterator<AtlasEntity> entityIterator = entities.iterator();
for (int i = 0; i < entities.size(); i++) {
ret[i] = getReferenceable(entityIterator.next(), ctx);
}
return ret;
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class AtlasInstanceConverter method toAtlasEntities.
public AtlasEntitiesWithExtInfo toAtlasEntities(String[] jsonEntities) throws AtlasBaseException, AtlasException {
Referenceable[] referenceables = new Referenceable[jsonEntities.length];
for (int i = 0; i < jsonEntities.length; i++) {
referenceables[i] = AtlasType.fromV1Json(jsonEntities[i], Referenceable.class);
}
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) instanceFormatters.getConverter(TypeCategory.ENTITY);
ConverterContext context = new ConverterContext();
for (Referenceable 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);
}
AtlasEntitiesWithExtInfo ret = context.getEntities();
return ret;
}
use of org.apache.atlas.v1.model.instance.Referenceable in project atlas by apache.
the class AtlasObjectIdConverter method fromV1ToV2.
@Override
public Object fromV1ToV2(Object v1Obj, AtlasType type, AtlasFormatConverter.ConverterContext converterContext) throws AtlasBaseException {
Object ret = null;
if (v1Obj != null) {
if (v1Obj instanceof Id) {
Id id = (Id) v1Obj;
ret = new AtlasObjectId(id.getId(), id.getTypeName());
} else if (v1Obj instanceof Referenceable) {
Referenceable refInst = (Referenceable) v1Obj;
String guid = refInst.getId().getId();
ret = new AtlasObjectId(guid, refInst.getTypeName());
if (!converterContext.entityExists(guid) && hasAnyAssignedAttribute(refInst)) {
AtlasEntityType entityType = typeRegistry.getEntityTypeByName(refInst.getTypeName());
AtlasEntityFormatConverter converter = (AtlasEntityFormatConverter) converterRegistry.getConverter(TypeCategory.ENTITY);
AtlasEntity entity = converter.fromV1ToV2(v1Obj, entityType, converterContext);
converterContext.addReferredEntity(entity);
}
}
}
return ret;
}
Aggregations