Search in sources :

Example 6 with Referenceable

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;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)

Example 7 with Referenceable

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;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasType(org.apache.atlas.type.AtlasType)

Example 8 with Referenceable

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;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity)

Example 9 with Referenceable

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;
}
Also used : ConverterContext(org.apache.atlas.repository.converters.AtlasFormatConverter.ConverterContext) AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Example 10 with Referenceable

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;
}
Also used : Referenceable(org.apache.atlas.v1.model.instance.Referenceable) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Id(org.apache.atlas.v1.model.instance.Id) AtlasEntityType(org.apache.atlas.type.AtlasEntityType)

Aggregations

Referenceable (org.apache.atlas.v1.model.instance.Referenceable)143 Test (org.testng.annotations.Test)64 Id (org.apache.atlas.v1.model.instance.Id)37 Struct (org.apache.atlas.v1.model.instance.Struct)23 ArrayList (java.util.ArrayList)20 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)15 HashMap (java.util.HashMap)12 List (java.util.List)10 AtlasException (org.apache.atlas.AtlasException)10 HookNotification (org.apache.atlas.model.notification.HookNotification)10 Map (java.util.Map)9 EntityUpdateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityUpdateRequest)9 AtlasServiceException (org.apache.atlas.AtlasServiceException)8 EntityAuditEvent (org.apache.atlas.EntityAuditEvent)8 EntityNotificationV1 (org.apache.atlas.v1.model.notification.EntityNotificationV1)7 EntityCreateRequest (org.apache.atlas.v1.model.notification.HookNotificationV1.EntityCreateRequest)7 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)6 EntityResult (org.apache.atlas.model.legacy.EntityResult)6 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)6 EntityNotificationTest (org.apache.atlas.notification.entity.EntityNotificationTest)5