Search in sources :

Example 81 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId 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)

Example 82 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasObjectIdConverter method fromV2ToV1.

@Override
public Object fromV2ToV1(Object v2Obj, AtlasType type, ConverterContext converterContext) throws AtlasBaseException {
    Id ret = null;
    if (v2Obj != null) {
        if (v2Obj instanceof Map) {
            Map v2Map = (Map) v2Obj;
            String idStr = (String) v2Map.get(AtlasObjectId.KEY_GUID);
            String typeName = (String) v2Map.get(AtlasObjectId.KEY_TYPENAME);
            if (StringUtils.isEmpty(idStr)) {
                throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND);
            }
            ret = new Id(idStr, 0, typeName);
        } else if (v2Obj instanceof AtlasObjectId) {
            // transient-id
            AtlasObjectId objId = (AtlasObjectId) v2Obj;
            ret = new Id(objId.getGuid(), 0, objId.getTypeName());
        } else if (v2Obj instanceof AtlasEntity) {
            AtlasEntity entity = (AtlasEntity) v2Obj;
            ret = new Id(entity.getGuid(), entity.getVersion() == null ? 0 : entity.getVersion().intValue(), entity.getTypeName());
        } else {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_CATEGORY_INVALID, type.getTypeCategory().name());
        }
    }
    return ret;
}
Also used : AtlasBaseException(org.apache.atlas.exception.AtlasBaseException) 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) Map(java.util.Map)

Example 83 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class FullTextMapperV2 method mapAttribute.

private void mapAttribute(Object value, AtlasEntityExtInfo entityExtInfo, StringBuilder sb, Set<String> processedGuids, boolean isClassificationOnly) throws AtlasBaseException {
    if (value instanceof AtlasObjectId) {
        if (followReferences && entityExtInfo != null) {
            AtlasObjectId objectId = (AtlasObjectId) value;
            AtlasEntity entity = entityExtInfo.getEntity(objectId.getGuid());
            if (entity != null) {
                map(entity, entityExtInfo, sb, processedGuids, isClassificationOnly);
            }
        }
    } else if (value instanceof List) {
        List valueList = (List) value;
        for (Object listElement : valueList) {
            mapAttribute(listElement, entityExtInfo, sb, processedGuids, isClassificationOnly);
        }
    } else if (value instanceof Map) {
        Map valueMap = (Map) value;
        for (Object key : valueMap.keySet()) {
            mapAttribute(key, entityExtInfo, sb, processedGuids, isClassificationOnly);
            mapAttribute(valueMap.get(key), entityExtInfo, sb, processedGuids, isClassificationOnly);
        }
    } else if (value instanceof Enum) {
        Enum enumValue = (Enum) value;
        sb.append(enumValue.name()).append(FULL_TEXT_DELIMITER);
    } else if (value instanceof AtlasStruct) {
        AtlasStruct atlasStruct = (AtlasStruct) value;
        for (Map.Entry<String, Object> entry : atlasStruct.getAttributes().entrySet()) {
            sb.append(entry.getKey()).append(FULL_TEXT_DELIMITER);
            mapAttribute(entry.getValue(), entityExtInfo, sb, processedGuids, isClassificationOnly);
        }
    } else {
        sb.append(String.valueOf(value)).append(FULL_TEXT_DELIMITER);
    }
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Example 84 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class TestUtilsV2 method createDeptEg2.

public static AtlasEntitiesWithExtInfo createDeptEg2() {
    AtlasEntitiesWithExtInfo entitiesWithExtInfo = new AtlasEntitiesWithExtInfo();
    /**
     ***** Department - HR ******
     */
    AtlasEntity hrDept = new AtlasEntity(DEPARTMENT_TYPE, "name", "hr");
    AtlasObjectId hrDeptId = getAtlasObjectId(hrDept);
    /**
     ***** Address Entities ******
     */
    AtlasStruct janeAddr = new AtlasStruct(ADDRESS_TYPE);
    janeAddr.setAttribute("street", "Great America Parkway");
    janeAddr.setAttribute("city", "Santa Clara");
    AtlasStruct juliusAddr = new AtlasStruct(ADDRESS_TYPE);
    juliusAddr.setAttribute("street", "Madison Ave");
    juliusAddr.setAttribute("city", "Newtonville");
    AtlasStruct maxAddr = new AtlasStruct(ADDRESS_TYPE);
    maxAddr.setAttribute("street", "Ripley St");
    maxAddr.setAttribute("city", "Newton");
    AtlasStruct johnAddr = new AtlasStruct(ADDRESS_TYPE);
    johnAddr.setAttribute("street", "Stewart Drive");
    johnAddr.setAttribute("city", "Sunnyvale");
    /**
     ***** Manager - Jane (John and Max subordinates) ******
     */
    AtlasEntity jane = new AtlasEntity(MANAGER_TYPE);
    AtlasObjectId janeId = getAtlasObjectId(jane);
    jane.setAttribute("name", "Jane");
    jane.setAttribute("department", hrDeptId);
    jane.setAttribute("address", janeAddr);
    /**
     ***** Manager - Julius (no subordinates) ******
     */
    AtlasEntity julius = new AtlasEntity(MANAGER_TYPE);
    AtlasObjectId juliusId = getAtlasObjectId(julius);
    julius.setAttribute("name", "Julius");
    julius.setAttribute("department", hrDeptId);
    julius.setAttribute("address", juliusAddr);
    julius.setAttribute("subordinates", Collections.emptyList());
    /**
     ***** Employee - Max (Manager: Jane, Mentor: Julius) ******
     */
    AtlasEntity max = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasObjectId maxId = getAtlasObjectId(max);
    max.setAttribute("name", "Max");
    max.setAttribute("department", hrDeptId);
    max.setAttribute("address", maxAddr);
    max.setAttribute("manager", janeId);
    max.setAttribute("mentor", juliusId);
    max.setAttribute("birthday", new Date(1979, 3, 15));
    max.setAttribute("hasPets", true);
    max.setAttribute("age", 36);
    max.setAttribute("numberOfCars", 2);
    max.setAttribute("houseNumber", 17);
    max.setAttribute("carMileage", 13);
    max.setAttribute("shares", Long.MAX_VALUE);
    max.setAttribute("salary", Double.MAX_VALUE);
    max.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000000000000"));
    max.setAttribute("approximationOfPi", new BigDecimal("3.1415926535897932"));
    /**
     ***** Employee - John (Manager: Jane, Mentor: Max) ******
     */
    AtlasEntity john = new AtlasEntity(EMPLOYEE_TYPE);
    AtlasObjectId johnId = getAtlasObjectId(john);
    john.setAttribute("name", "John");
    john.setAttribute("department", hrDeptId);
    john.setAttribute("address", johnAddr);
    john.setAttribute("manager", janeId);
    john.setAttribute("mentor", maxId);
    john.setAttribute("birthday", new Date(1950, 5, 15));
    john.setAttribute("hasPets", true);
    john.setAttribute("numberOfCars", 1);
    john.setAttribute("houseNumber", 153);
    john.setAttribute("carMileage", 13364);
    john.setAttribute("shares", 15000);
    john.setAttribute("salary", 123345.678);
    john.setAttribute("age", 50);
    john.setAttribute("numberOfStarsEstimate", new BigInteger("1000000000000000000000"));
    john.setAttribute("approximationOfPi", new BigDecimal("3.141592653589793238462643383279502884197169399375105820974944592307816406286"));
    jane.setAttribute("subordinates", Arrays.asList(johnId, maxId));
    hrDept.setAttribute("employees", Arrays.asList(janeId, juliusId, maxId, johnId));
    entitiesWithExtInfo.addEntity(hrDept);
    entitiesWithExtInfo.addEntity(jane);
    entitiesWithExtInfo.addEntity(julius);
    entitiesWithExtInfo.addEntity(max);
    entitiesWithExtInfo.addEntity(john);
    return entitiesWithExtInfo;
}
Also used : AtlasStruct(org.apache.atlas.model.instance.AtlasStruct) AtlasEntity(org.apache.atlas.model.instance.AtlasEntity) AtlasEntitiesWithExtInfo(org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo) BigInteger(java.math.BigInteger) AtlasTypeUtil.getAtlasObjectId(org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId) Date(java.util.Date) BigDecimal(java.math.BigDecimal)

Example 85 with AtlasObjectId

use of org.apache.atlas.model.instance.AtlasObjectId in project atlas by apache.

the class AtlasTypeUtil method getAtlasObjectId.

public static AtlasObjectId getAtlasObjectId(AtlasEntity entity, AtlasTypeRegistry typeRegistry) {
    String typeName = entity.getTypeName();
    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName);
    Map<String, Object> uniqAttributes = null;
    if (entityType != null && MapUtils.isNotEmpty(entityType.getUniqAttributes())) {
        for (AtlasAttribute attribute : entityType.getUniqAttributes().values()) {
            Object attrValue = entity.getAttribute(attribute.getName());
            if (attrValue != null) {
                if (uniqAttributes == null) {
                    uniqAttributes = new HashMap<>();
                }
                uniqAttributes.put(attribute.getName(), attrValue);
            }
        }
    }
    return new AtlasObjectId(entity.getGuid(), typeName, uniqAttributes);
}
Also used : AtlasAttribute(org.apache.atlas.type.AtlasStructType.AtlasAttribute) AtlasObjectId(org.apache.atlas.model.instance.AtlasObjectId)

Aggregations

AtlasObjectId (org.apache.atlas.model.instance.AtlasObjectId)255 AtlasEntity (org.apache.atlas.model.instance.AtlasEntity)124 Test (org.testng.annotations.Test)70 ArrayList (java.util.ArrayList)69 Map (java.util.Map)47 EntityMutationResponse (org.apache.atlas.model.instance.EntityMutationResponse)44 AtlasEntityHeader (org.apache.atlas.model.instance.AtlasEntityHeader)41 AtlasEntityType (org.apache.atlas.type.AtlasEntityType)41 HashMap (java.util.HashMap)40 AtlasVertex (org.apache.atlas.repository.graphdb.AtlasVertex)38 List (java.util.List)36 AtlasEntityWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntityWithExtInfo)33 AtlasBaseException (org.apache.atlas.exception.AtlasBaseException)32 BeforeTest (org.testng.annotations.BeforeTest)32 AtlasEntitiesWithExtInfo (org.apache.atlas.model.instance.AtlasEntity.AtlasEntitiesWithExtInfo)29 AtlasTypeUtil.getAtlasObjectId (org.apache.atlas.type.AtlasTypeUtil.getAtlasObjectId)24 AtlasStruct (org.apache.atlas.model.instance.AtlasStruct)22 AtlasExportRequest (org.apache.atlas.model.impexp.AtlasExportRequest)14 AtlasEdge (org.apache.atlas.repository.graphdb.AtlasEdge)13 AtlasType (org.apache.atlas.type.AtlasType)11