org.apache.atlas.model.instance.AtlasObjectId Java Examples

The following examples show how to use org.apache.atlas.model.instance.AtlasObjectId. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NiFiFlow.java    From nifi with Apache License 2.0 6 votes vote down vote up
private EntityChangeType getFlowPathIOChangeType(AtlasObjectId id) {
    final String guid = id.getGuid();
    if (!isGuidAssigned(guid)) {
        return EntityChangeType.CREATED;
    } else {
        if (TYPE_NIFI_QUEUE.equals(id.getTypeName()) && queues.containsKey(id)) {
            // If an input/output is a queue, and it is owned by this NiFiFlow, then check if it's still needed. NiFiFlow knows active queues.
            if (stillExistingEntityGuids.contains(guid)) {
                return EntityChangeType.AS_IS;
            } else {
                return EntityChangeType.DELETED;
            }
        } else {
            // Otherwise, do not need to delete.
            return EntityChangeType.AS_IS;
        }
    }
}
 
Example #2
Source File: AtlasRelationshipStoreV2Test.java    From atlas with Apache License 2.0 6 votes vote down vote up
protected static List<AtlasObjectId> toAtlasObjectIds(Object object) {
    List<AtlasObjectId> ret = new ArrayList<>();

    if (object instanceof List) {
        List<?> objectIds = (List) object;

        if (CollectionUtils.isNotEmpty(objectIds)) {
            for (Object obj : objectIds) {
                if (obj instanceof AtlasRelatedObjectId) {
                    AtlasRelatedObjectId relatedObjectId = (AtlasRelatedObjectId) obj;
                    ret.add(new AtlasObjectId(relatedObjectId.getGuid(), relatedObjectId.getTypeName(), relatedObjectId.getUniqueAttributes()));
                }
            }
        }
    }

    return ret;
}
 
Example #3
Source File: AtlasGlossaryCategoryDTO.java    From atlas with Apache License 2.0 6 votes vote down vote up
@Override
public AtlasEntity toEntity(final AtlasGlossaryCategory obj) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> AtlasGlossaryCategoryDTO.toEntity()", obj);
    }
    Objects.requireNonNull(obj, "atlasGlossaryCategory");
    Objects.requireNonNull(obj.getQualifiedName(), "atlasGlossaryCategory qualifiedName must be specified");
    Objects.requireNonNull(obj.getAnchor(), "atlasGlossaryCategory anchor must be specified");

    AtlasEntity ret = getDefaultAtlasEntity(obj);

    ret.setAttribute("qualifiedName", obj.getQualifiedName());
    ret.setAttribute("name", obj.getName());
    ret.setAttribute("shortDescription", obj.getShortDescription());
    ret.setAttribute("longDescription", obj.getLongDescription());
    ret.setAttribute("anchor", new AtlasObjectId(obj.getAnchor().getGlossaryGuid()));
    ret.setAttribute("additionalAttributes", obj.getAdditionalAttributes());

    if (LOG.isDebugEnabled()) {
        LOG.debug("<== AtlasGlossaryCategoryDTO.toEntity() : {}", ret);
    }
    return ret;
}
 
Example #4
Source File: AtlasStructFormatConverter.java    From atlas with Apache License 2.0 6 votes vote down vote up
private String getGuid(Object obj) {
    final String ret;

    if (obj instanceof AtlasObjectId) {
        AtlasObjectId objId = (AtlasObjectId) obj;

        ret = objId.getGuid();
    } else if (obj instanceof Map) {
        Map v2Map = (Map) obj;

        ret = (String)v2Map.get(AtlasObjectId.KEY_GUID);
    } else {
        ret = null;
    }

    return ret;
}
 
Example #5
Source File: GraphHelper.java    From atlas with Apache License 2.0 6 votes vote down vote up
public static AtlasObjectId getReferenceObjectId(AtlasEdge edge, AtlasRelationshipEdgeDirection relationshipDirection,
                                                 AtlasVertex parentVertex) {
    AtlasObjectId ret = null;

    if (relationshipDirection == OUT) {
        ret = getAtlasObjectIdForInVertex(edge);
    } else if (relationshipDirection == IN) {
        ret = getAtlasObjectIdForOutVertex(edge);
    } else if (relationshipDirection == BOTH){
        // since relationship direction is BOTH, edge direction can be inward or outward
        // compare with parent entity vertex and pick the right reference vertex
        if (verticesEquals(parentVertex, edge.getOutVertex())) {
            ret = getAtlasObjectIdForInVertex(edge);
        } else {
            ret = getAtlasObjectIdForOutVertex(edge);
        }
    }

    return ret;
}
 
Example #6
Source File: AtlasTypeUtil.java    From atlas with Apache License 2.0 6 votes vote down vote up
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);
}
 
Example #7
Source File: AtlasRelationshipStoreSoftDeleteV2Test.java    From atlas with Apache License 2.0 6 votes vote down vote up
protected void verifyRelationshipAttributeUpdate_OneToOne_Sibling(AtlasEntity julius, AtlasEntity jane, AtlasEntity mike) throws Exception {
    AtlasObjectId juliusId = employeeNameIdMap.get("Julius");
    AtlasObjectId mikeId   = employeeNameIdMap.get("Mike");

    // Julius sibling updated to Mike
    AtlasObjectId juliusSiblingId = toAtlasObjectId(julius.getRelationshipAttribute("sibling"));
    assertNotNull(juliusSiblingId);
    assertObjectIdEquals(juliusSiblingId, mikeId);

    // Mike's sibling is Julius
    AtlasObjectId mikeSiblingId = toAtlasObjectId(mike.getRelationshipAttribute("sibling"));
    assertNotNull(mikeSiblingId);
    assertObjectIdEquals(mikeSiblingId, juliusId);

    // Jane's sibling is still Julius (soft delete)
    AtlasObjectId janeSiblingId = toAtlasObjectId(jane.getRelationshipAttribute("sibling"));
    assertNotNull(janeSiblingId);
    assertObjectIdEquals(janeSiblingId, juliusId);
}
 
Example #8
Source File: EntityGraphMapper.java    From incubator-atlas with Apache License 2.0 6 votes vote down vote up
private boolean objectIdsContain(Collection<AtlasObjectId> objectIds, AtlasObjectId objectId) {
    boolean ret = false;

    if (CollectionUtils.isEmpty(objectIds)) {
        ret = false;

    } else {
        for (AtlasObjectId id : objectIds) {
            if (StringUtils.equals(id.getGuid(), objectId.getGuid())) {
                ret = true;
                break;
            }
        }
    }

    return ret;
}
 
Example #9
Source File: DropDatabase.java    From atlas with Apache License 2.0 6 votes vote down vote up
private List<AtlasObjectId> getHiveEntities() {
    List<AtlasObjectId> ret = new ArrayList<>();

    for (Entity entity : getOutputs()) {
        if (entity.getType() == DATABASE) {
            String        dbQName = getQualifiedName(entity.getDatabase());
            AtlasObjectId dbId    = new AtlasObjectId(HIVE_TYPE_DB, ATTRIBUTE_QUALIFIED_NAME, dbQName);

            context.removeFromKnownDatabase(dbQName);

            ret.add(dbId);
        } else if (entity.getType() == TABLE) {
            String        tblQName = getQualifiedName(entity.getTable());
            AtlasObjectId tblId    = new AtlasObjectId(HIVE_TYPE_TABLE, ATTRIBUTE_QUALIFIED_NAME, tblQName);

            context.removeFromKnownTable(tblQName);

            ret.add(tblId);
        }
    }

    return ret;
}
 
Example #10
Source File: RequestContext.java    From atlas with Apache License 2.0 5 votes vote down vote up
public void resetEntityGuid() {
    if (entity instanceof AtlasEntity) {
        ((AtlasEntity) entity).setGuid(guid);
    } else if (entity instanceof AtlasObjectId) {
        ((AtlasObjectId) entity).setGuid(guid);
    } else if (entity instanceof Map) {
        ((Map) entity).put(KEY_GUID, guid);
    }
}
 
Example #11
Source File: AtlasEntityGraphDiscoveryV1.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private void recordObjectReference(AtlasObjectId objId) {
    if (AtlasTypeUtil.isValidGuid(objId)) {
        discoveryContext.addReferencedGuid(objId.getGuid());
    } else {
        discoveryContext.addReferencedByUniqAttribs(objId);
    }
}
 
Example #12
Source File: DropTable.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public List<HookNotification> getNotificationMessages() {
    List<HookNotification> ret      = null;
    List<AtlasObjectId>    entities = context.isMetastoreHook() ? getHiveMetastoreEntities() : getHiveEntities();

    if (CollectionUtils.isNotEmpty(entities)) {
        ret = new ArrayList<>(entities.size());

        for (AtlasObjectId entity : entities) {
            ret.add(new EntityDeleteRequestV2(getUserName(), Collections.singletonList(entity)));
        }
    }

    return ret;
}
 
Example #13
Source File: ImportServiceTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private List<AtlasObjectId> getItemsToExport(String... typeNames){
    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    for (String typeName : typeNames) {
        itemsToExport.add(new AtlasObjectId(typeName, "qualifiedName", "db.table@cluster"));
    }
    return itemsToExport;
}
 
Example #14
Source File: FullTextMapperV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #15
Source File: UniqAttrBasedEntityResolver.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Override
public EntityGraphDiscoveryContext resolveEntityReferences(EntityGraphDiscoveryContext context) throws AtlasBaseException {
    if (context == null) {
        throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, "UniqAttrBasedEntityResolver.resolveEntityReferences(): context is null");
    }

    //Resolve attribute references
    List<AtlasObjectId> resolvedReferences = new ArrayList<>();

    for (AtlasObjectId objId : context.getReferencedByUniqAttribs()) {
        //query in graph repo that given unique attribute - check for deleted also?
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objId.getTypeName());

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), objId.getTypeName());
        }

        AtlasVertex vertex = AtlasGraphUtilsV1.findByUniqueAttributes(entityType, objId.getUniqueAttributes());

        if (vertex != null) {
            context.addResolvedIdByUniqAttribs(objId, vertex);
            resolvedReferences.add(objId);
        } else {
            throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, objId.toString());
        }
    }

    return context;
}
 
Example #16
Source File: BulkImporterImpl.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static void updateVertexGuid(AtlasGraph atlasGraph, AtlasTypeRegistry typeRegistry, EntityGraphRetriever entityGraphRetriever, AtlasEntity entity) {
    String entityGuid = entity.getGuid();
    AtlasObjectId objectId = entityGraphRetriever.toAtlasObjectIdWithoutGuid(entity);

    AtlasEntityType entityType = typeRegistry.getEntityTypeByName(entity.getTypeName());
    String vertexGuid = null;
    try {
        vertexGuid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(atlasGraph, entityType, objectId.getUniqueAttributes());
    } catch (AtlasBaseException e) {
        LOG.warn("Entity: {}: Does not exist!", objectId);
        return;
    }

    if (StringUtils.isEmpty(vertexGuid) || vertexGuid.equals(entityGuid)) {
        return;
    }

    AtlasVertex v = AtlasGraphUtilsV2.findByGuid(atlasGraph, vertexGuid);
    if (v == null) {
        return;
    }

    addHistoricalGuid(v, vertexGuid);
    AtlasGraphUtilsV2.setProperty(v, Constants.GUID_PROPERTY_KEY, entityGuid);

    LOG.warn("GUID Updated: Entity: {}: from: {}: to: {}", objectId, vertexGuid, entity.getGuid());
}
 
Example #17
Source File: AtlasEntityStoreV2.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
@GraphTransaction
public EntityMutationResponse updateEntity(AtlasObjectId objectId, AtlasEntityWithExtInfo updatedEntityInfo, boolean isPartialUpdate) throws AtlasBaseException {
    if (LOG.isDebugEnabled()) {
        LOG.debug("==> updateEntity({}, {}, {})", objectId, updatedEntityInfo, isPartialUpdate);
    }

    if (objectId == null || updatedEntityInfo == null || updatedEntityInfo.getEntity() == null) {
        throw new AtlasBaseException(AtlasErrorCode.INVALID_PARAMETERS, "null entity-id/entity");
    }

    final String guid;

    if (AtlasTypeUtil.isAssignedGuid(objectId.getGuid())) {
        guid = objectId.getGuid();
    } else {
        AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objectId.getTypeName());

        if (entityType == null) {
            throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, objectId.getTypeName());
        }

        guid = AtlasGraphUtilsV2.getGuidByUniqueAttributes(graph, typeRegistry.getEntityTypeByName(objectId.getTypeName()), objectId.getUniqueAttributes());
    }

    AtlasEntity entity = updatedEntityInfo.getEntity();

    entity.setGuid(guid);

    return createOrUpdate(new AtlasEntityStream(updatedEntityInfo), isPartialUpdate, false, false);
}
 
Example #18
Source File: AtlasDeleteHandlerV1Test.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testDeleteEntitiesWithCompositeMapReference() throws Exception {
    // Create instances of MapOwner and MapValue.
    // Set MapOwner.map with one entry that references MapValue instance.
    AtlasEntity.AtlasEntityWithExtInfo entityDefinition = createMapOwnerAndValueEntities();
    String mapOwnerGuid = entityDefinition.getEntity().getGuid();

    // Verify MapOwner.map attribute has expected value.
    AtlasEntity.AtlasEntityWithExtInfo mapOwnerInstance = entityStore.getById(mapOwnerGuid);
    Object object = mapOwnerInstance.getEntity().getAttribute("map");
    Assert.assertNotNull(object);
    Assert.assertTrue(object instanceof Map);
    Map<String, AtlasObjectId> map = (Map<String, AtlasObjectId>)object;
    Assert.assertEquals(map.size(), 1);
    AtlasObjectId mapValueInstance = map.get("value1");
    Assert.assertNotNull(mapValueInstance);
    String mapValueGuid = mapValueInstance.getGuid();
    String edgeLabel = AtlasGraphUtilsV1.getAttributeEdgeLabel(compositeMapOwnerType, "map");
    String mapEntryLabel = edgeLabel + "." + "value1";
    AtlasEdgeLabel atlasEdgeLabel = new AtlasEdgeLabel(mapEntryLabel);
    AtlasVertex mapOwnerVertex = GraphHelper.getInstance().getVertexForGUID(mapOwnerGuid);
    object = mapOwnerVertex.getProperty(atlasEdgeLabel.getQualifiedMapKey(), Object.class);
    Assert.assertNotNull(object);

    RequestContextV1.clear();
    List<AtlasEntityHeader> deletedEntities = entityStore.deleteById(mapOwnerGuid).getDeletedEntities();
    Assert.assertEquals(deletedEntities.size(), 2);
    Assert.assertTrue(extractGuids(deletedEntities).contains(mapOwnerGuid));
    Assert.assertTrue(extractGuids(deletedEntities).contains(mapValueGuid));

    assertEntityDeleted(mapOwnerGuid);
    assertEntityDeleted(mapValueGuid);
}
 
Example #19
Source File: AtlasBuiltInTypes.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isValidValue(Object obj) {
    if (obj == null || obj instanceof AtlasObjectId) {
        return true;
    } else if (obj instanceof Map) {
        return isValidMap((Map)obj);
    }

    return getNormalizedValue(obj) != null;
}
 
Example #20
Source File: ExportServiceTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasExportRequest getRequestForFullFetch() {
    AtlasExportRequest request = new AtlasExportRequest();

    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    itemsToExport.add(new AtlasObjectId("hive_db", "qualifiedName", "default@cl1"));
    request.setItemsToExport(itemsToExport);

    return request;
}
 
Example #21
Source File: AtlasRelationshipStoreV2Test.java    From atlas with Apache License 2.0 5 votes vote down vote up
protected static void verifyRelationshipAttributeList(AtlasEntity entity, String relationshipAttrName, List<AtlasObjectId> expectedValues) {
    Object refValue = entity.getRelationshipAttribute(relationshipAttrName);
    assertTrue(refValue instanceof List);

    List<AtlasObjectId> refList = toAtlasObjectIds(refValue);
    assertEquals(refList.size(), expectedValues.size());

    if (expectedValues.size() > 0) {
        assertTrue(refList.containsAll(expectedValues));
    }
}
 
Example #22
Source File: NiFiAtlasClient.java    From nifi with Apache License 2.0 5 votes vote down vote up
public AtlasEntity.AtlasEntityWithExtInfo searchEntityDef(AtlasObjectId id) throws AtlasServiceException {
    final String guid = id.getGuid();
    if (!StringUtils.isEmpty(guid)) {
        return atlasClient.getEntityByGuid(guid, true, false);
    }
    final Map<String, String> attributes = new HashMap<>();
    id.getUniqueAttributes().entrySet().stream().filter(entry -> entry.getValue() != null)
            .forEach(entry -> attributes.put(entry.getKey(), entry.getValue().toString()));
    return atlasClient.getEntityByAttribute(id.getTypeName(), attributes, true, false);
}
 
Example #23
Source File: ZipSinkTest.java    From incubator-atlas with Apache License 2.0 5 votes vote down vote up
private AtlasExportResult getDefaultExportResult() {
    AtlasExportRequest request = new AtlasExportRequest();

    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    itemsToExport.add(new AtlasObjectId("hive_db", "qualifiedName", "default"));
    request.setItemsToExport(itemsToExport);

    defaultExportResult = new AtlasExportResult(request, "admin", "1.0.0.0", "root", 100);
    return defaultExportResult;
}
 
Example #24
Source File: AtlasEntityUtil.java    From atlas with Apache License 2.0 5 votes vote down vote up
public static Map<String, String> formatSoftRefValue(Map<String, AtlasObjectId> objIdMap) {
    Map<String, String> ret = new HashMap<>();

    for (Map.Entry<String, AtlasObjectId> entry : objIdMap.entrySet()) {
        ret.put(entry.getKey(), formatSoftRefValue(entry.getValue()));
    }

    return ret;
}
 
Example #25
Source File: TestAtlasObjectIdType.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void testObjectIdTypeGetNormalizedValue() {
    assertNull(objectIdType.getNormalizedValue(null), "value=" + null);

    for (Object value : validValues) {
        if (value == null) {
            continue;
        }

        AtlasObjectId normalizedValue = objectIdType.getNormalizedValue(value);

        assertNotNull(normalizedValue, "value=" + value);

        if (value instanceof AtlasObjectId) {
            assertEquals(normalizedValue, value, "value=" + value);
        } else if (value instanceof Map) {
            assertEquals(normalizedValue.getTypeName(), ((Map)value).get(AtlasObjectId.KEY_TYPENAME),
                         "value=" + value);
            if (((Map)value).get(AtlasObjectId.KEY_GUID) == null) {
                assertEquals(normalizedValue.getGuid(), ((Map)value).get(AtlasObjectId.KEY_GUID),  "value=" + value);
            } else {
                assertEquals(normalizedValue.getGuid(), ((Map) value).get(AtlasObjectId.KEY_GUID), "value=" + value);
            }

            assertEquals(normalizedValue.getUniqueAttributes(), ((Map)value).get(AtlasObjectId.KEY_UNIQUE_ATTRIBUTES),
                    "value=" + value);
        }
    }
}
 
Example #26
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasObjectId getAtlasObjectIdFromSoftRefFormat(String softRefVal, AtlasAttribute attribute, AtlasEntityExtInfo entityExtInfo, final boolean isMinExtInfo) {
    AtlasObjectId ret = AtlasEntityUtil.parseSoftRefValue(softRefVal);

    if(ret != null) {
        if (entityExtInfo != null && attribute.isOwnedRef()) {
            try {
                AtlasVertex referenceVertex = getEntityVertex(ret.getGuid());

                if (referenceVertex != null) {
                    final AtlasEntity entity;

                    if (isMinExtInfo) {
                        entity = mapVertexToAtlasEntityMin(referenceVertex, entityExtInfo);
                    } else {
                        entity = mapVertexToAtlasEntity(referenceVertex, entityExtInfo);
                    }

                    if (entity != null) {
                        ret = toAtlasObjectId(entity);
                    }
                }
            } catch (AtlasBaseException excp) {
                LOG.info("failed to retrieve soft-referenced entity(typeName={}, guid={}); errorCode={}. Ignoring", ret.getTypeName(), ret.getGuid(), excp.getAtlasErrorCode());
            }
        }
    }

    return ret;
}
 
Example #27
Source File: EntityGraphRetriever.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasObjectId mapVertexToObjectId(AtlasVertex entityVertex, String edgeLabel, AtlasEdge edge,
                                          AtlasEntityExtInfo entityExtInfo, boolean isOwnedAttribute,
                                          AtlasRelationshipEdgeDirection edgeDirection, final boolean isMinExtInfo) throws AtlasBaseException {
    AtlasObjectId ret = null;

    if (edge == null) {
        edge = graphHelper.getEdgeForLabel(entityVertex, edgeLabel, edgeDirection);
    }

    if (GraphHelper.elementExists(edge)) {
        AtlasVertex referenceVertex = edge.getInVertex();

        if (StringUtils.equals(getIdFromVertex(referenceVertex), getIdFromVertex(entityVertex))) {
            referenceVertex = edge.getOutVertex();
        }

        if (referenceVertex != null) {
            if (entityExtInfo != null && isOwnedAttribute) {
                final AtlasEntity entity;

                if (isMinExtInfo) {
                    entity = mapVertexToAtlasEntityMin(referenceVertex, entityExtInfo);
                } else {
                    entity = mapVertexToAtlasEntity(referenceVertex, entityExtInfo);
                }

                if (entity != null) {
                    ret = AtlasTypeUtil.getAtlasObjectId(entity);
                }
            } else {
                ret = toAtlasObjectId(referenceVertex);
            }
        }
    }

    return ret;
}
 
Example #28
Source File: StartEntityFetchByExportRequestTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
@Test
public void fetchTypeGuid() {
    String exportRequestJson = "{ \"itemsToExport\": [ { \"typeName\": \"hive_db\", \"guid\": \"111-222-333\" } ]}";
    AtlasExportRequest exportRequest = AtlasType.fromJson(exportRequestJson, AtlasExportRequest.class);

    List<AtlasObjectId> objectGuidMap = startEntityFetchByExportRequestSpy.get(exportRequest);

    assertEquals(objectGuidMap.get(0).getGuid(), "111-222-333");
}
 
Example #29
Source File: EntityGraphMapper.java    From atlas with Apache License 2.0 5 votes vote down vote up
private static String getGuid(Object val) throws AtlasBaseException {
    if (val != null) {
        if ( val instanceof  AtlasObjectId) {
            return ((AtlasObjectId) val).getGuid();
        } else if (val instanceof Map) {
            Object guidVal = ((Map)val).get(AtlasObjectId.KEY_GUID);

            return guidVal != null ? guidVal.toString() : null;
        }
    }

    return null;
}
 
Example #30
Source File: ExportServiceTest.java    From atlas with Apache License 2.0 5 votes vote down vote up
private AtlasExportRequest getRequestForEmployee() {
    AtlasExportRequest request = new AtlasExportRequest();

    List<AtlasObjectId> itemsToExport = new ArrayList<>();
    itemsToExport.add(new AtlasObjectId("Employee", "name", "Max"));
    request.setItemsToExport(itemsToExport);

    setOptionsMap(request, true, "CONNECTED", false, "");
    return request;
}