Java Code Examples for org.apache.atlas.model.instance.AtlasObjectId#getTypeName()
The following examples show how to use
org.apache.atlas.model.instance.AtlasObjectId#getTypeName() .
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: EntityGraphMapper.java From atlas with Apache License 2.0 | 6 votes |
private String mapSoftRefValue(AttributeMutationContext ctx, EntityMutationContext context) { String ret = null; if (ctx.getValue() instanceof AtlasObjectId) { AtlasObjectId objectId = (AtlasObjectId) ctx.getValue(); String typeName = objectId.getTypeName(); String guid = AtlasTypeUtil.isUnAssignedGuid(objectId.getGuid()) ? context.getGuidAssignments().get(objectId.getGuid()) : objectId.getGuid(); ret = AtlasEntityUtil.formatSoftRefValue(typeName, guid); } else { if (ctx.getValue() != null) { LOG.warn("mapSoftRefValue: Was expecting AtlasObjectId, but found: {}", ctx.getValue().getClass()); } } setAssignedGuid(ctx.getValue(), context); return ret; }
Example 2
Source File: AtlasRelationshipStoreV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
private void validateEnd(AtlasObjectId end) throws AtlasBaseException { String guid = end.getGuid(); String typeName = end.getTypeName(); Map<String, Object> uniqueAttributes = end.getUniqueAttributes(); AtlasVertex endVertex = AtlasGraphUtilsV1.findByGuid(guid); if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid); } else if (MapUtils.isNotEmpty(uniqueAttributes)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (AtlasGraphUtilsV1.findByUniqueAttributes(entityType, uniqueAttributes) == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString()); } } }
Example 3
Source File: StartEntityFetchByExportRequest.java From atlas with Apache License 2.0 | 5 votes |
private List<String> getEntitiesForMatchTypeUsingUniqueAttributes(AtlasObjectId item, String matchType) throws AtlasBaseException { final String queryTemplate = getQueryTemplateForMatchType(matchType); final String typeName = item.getTypeName(); final AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); Set<String> ret = new HashSet<>(); if (entityType == null) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, typeName); } for (Map.Entry<String, Object> e : item.getUniqueAttributes().entrySet()) { String attrName = e.getKey(); Object attrValue = e.getValue(); AtlasStructType.AtlasAttribute attribute = entityType.getAttribute(attrName); if (attribute == null || attrValue == null) { continue; } List<String> guids = executeGremlinQuery(queryTemplate, getBindingsForObjectId(typeName, attribute.getQualifiedName(), e.getValue())); if (!CollectionUtils.isNotEmpty(guids)) { continue; } ret.addAll(guids); } return new ArrayList<>(ret); }
Example 4
Source File: UniqAttrBasedEntityResolver.java From atlas with Apache License 2.0 | 5 votes |
@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 = AtlasGraphUtilsV2.findByUniqueAttributes(this.graph, entityType, objId.getUniqueAttributes()); if (vertex == null && RequestContext.get().isCreateShellEntityForNonExistingReference()) { vertex = entityGraphMapper.createShellEntityVertex(objId, context); } if (vertex != null) { context.addResolvedIdByUniqAttribs(objId, vertex); resolvedReferences.add(objId); } else { throw new AtlasBaseException(AtlasErrorCode.REFERENCED_ENTITY_NOT_FOUND, objId.toString()); } } return context; }
Example 5
Source File: AtlasRelationshipStoreV2.java From atlas with Apache License 2.0 | 5 votes |
private String getTypeNameFromObjectId(AtlasObjectId objectId) { String typeName = objectId.getTypeName(); if (StringUtils.isBlank(typeName)) { typeName = AtlasGraphUtilsV2.getTypeNameFromGuid(this.graph, objectId.getGuid()); } return typeName; }
Example 6
Source File: AtlasEntityStoreV2.java From atlas with Apache License 2.0 | 5 votes |
@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 7
Source File: UniqAttrBasedEntityResolver.java From incubator-atlas with Apache License 2.0 | 5 votes |
@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 8
Source File: AtlasRelationshipStoreV1.java From incubator-atlas with Apache License 2.0 | 5 votes |
private String getTypeNameFromObjectId(AtlasObjectId objectId) { String typeName = objectId.getTypeName(); if (StringUtils.isBlank(typeName)) { typeName = AtlasGraphUtilsV1.getTypeNameFromGuid(objectId.getGuid()); } return typeName; }
Example 9
Source File: AtlasRelationshipStoreV2.java From atlas with Apache License 2.0 | 4 votes |
/** * Validate the ends of the passed relationship * @param relationship * @throws AtlasBaseException */ private void validateEnds(AtlasRelationship relationship) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("validateEnds entry relationship:" + relationship); } List<AtlasObjectId> ends = new ArrayList<>(); List<AtlasRelationshipEndDef> endDefs = new ArrayList<>(); String relationshipTypeName = relationship.getTypeName(); AtlasRelationshipDef relationshipDef = typeRegistry.getRelationshipDefByName(relationshipTypeName); ends.add(relationship.getEnd1()); ends.add(relationship.getEnd2()); endDefs.add(relationshipDef.getEndDef1()); endDefs.add(relationshipDef.getEndDef2()); for (int i = 0; i < ends.size(); i++) { AtlasObjectId end = ends.get(i); String guid = end.getGuid(); String typeName = end.getTypeName(); Map<String, Object> uniqueAttributes = end.getUniqueAttributes(); AtlasVertex endVertex = AtlasGraphUtilsV2.findByGuid(this.graph, guid); if (!AtlasTypeUtil.isValidGuid(guid) || endVertex == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, guid); } else if (MapUtils.isNotEmpty(uniqueAttributes)) { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (AtlasGraphUtilsV2.findByUniqueAttributes(this.graph, entityType, uniqueAttributes) == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_BY_UNIQUE_ATTRIBUTE_NOT_FOUND, typeName, uniqueAttributes.toString()); } } else { // check whether the guid is the correct type String vertexTypeName = endVertex.getProperty(Constants.TYPE_NAME_PROPERTY_KEY, String.class); if (!Objects.equals(vertexTypeName, typeName)) { String attrName = endDefs.get(i).getName(); throw new AtlasBaseException(AtlasErrorCode.RELATIONSHIP_INVALID_ENDTYPE, attrName, guid, vertexTypeName, typeName); } } } if (LOG.isDebugEnabled()) { LOG.debug("validateEnds exit successfully validated relationship:" + relationship); } }
Example 10
Source File: EntityGraphMapper.java From atlas with Apache License 2.0 | 4 votes |
private AtlasEntityType getInstanceType(Object val, EntityMutationContext context) throws AtlasBaseException { AtlasEntityType ret = null; if (val != null) { String typeName = null; String guid = null; if (val instanceof AtlasObjectId) { AtlasObjectId objId = (AtlasObjectId) val; typeName = objId.getTypeName(); guid = objId.getGuid(); } else if (val instanceof Map) { Map map = (Map) val; Object typeNameVal = map.get(AtlasObjectId.KEY_TYPENAME); Object guidVal = map.get(AtlasObjectId.KEY_GUID); if (typeNameVal != null) { typeName = typeNameVal.toString(); } if (guidVal != null) { guid = guidVal.toString(); } } if (typeName == null) { if (guid != null) { ret = context.getType(guid); if (ret == null) { AtlasVertex vertex = context.getDiscoveryContext().getResolvedEntityVertex(guid); if (vertex != null) { typeName = AtlasGraphUtilsV2.getTypeName(vertex); } } } } if (ret == null && typeName != null) { ret = typeRegistry.getEntityTypeByName(typeName); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, val.toString()); } } return ret; }
Example 11
Source File: AtlasRelationshipType.java From atlas with Apache License 2.0 | 4 votes |
/** * Validate the fields in the the RelationshipType are consistent with respect to themselves. * @param relationship * @throws AtlasBaseException */ private boolean validateRelationship(AtlasRelationship relationship) { AtlasObjectId end1 = relationship.getEnd1(); AtlasObjectId end2 = relationship.getEnd2(); if (end1 != null && end2 != null) { String end1TypeName = end1.getTypeName(); String end2TypeName = end2.getTypeName(); if (StringUtils.isNotEmpty(end1TypeName) && StringUtils.isNotEmpty(end2TypeName)) { return end1Type.isTypeOrSuperTypeOf(end1TypeName) && end2Type.isTypeOrSuperTypeOf(end2TypeName) && super.isValidValue(relationship); } else { return StringUtils.isNotEmpty(end1.getGuid()) && StringUtils.isNotEmpty(end2.getGuid()); } } return false; }
Example 12
Source File: ExportService.java From incubator-atlas with Apache License 2.0 | 4 votes |
private List<AtlasEntityWithExtInfo> getStartingEntity(AtlasObjectId item, ExportContext context) throws AtlasBaseException { List<AtlasEntityWithExtInfo> ret = new ArrayList<>(); if (StringUtils.isNotEmpty(item.getGuid())) { AtlasEntityWithExtInfo entity = entityGraphRetriever.toAtlasEntityWithExtInfo(item); if (entity != null) { ret = Collections.singletonList(entity); } } else if (StringUtils.isNotEmpty(item.getTypeName()) && MapUtils.isNotEmpty(item.getUniqueAttributes())) { String typeName = item.getTypeName(); AtlasEntityType entityType = typeRegistry.getEntityTypeByName(typeName); if (entityType == null) { throw new AtlasBaseException(AtlasErrorCode.UNKNOWN_TYPENAME, typeName); } final String queryTemplate; if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_STARTS_WITH)) { queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_STARTS_WITH); } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_ENDS_WITH)) { queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_ENDS_WITH); } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_CONTAINS)) { queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_CONTAINS); } else if (StringUtils.equalsIgnoreCase(context.matchType, MATCH_TYPE_MATCHES)) { queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_MATCHES); } else { // default queryTemplate = gremlinQueryProvider.getQuery(AtlasGremlinQuery.EXPORT_TYPE_DEFAULT); } for (Map.Entry<String, Object> e : item.getUniqueAttributes().entrySet()) { String attrName = e.getKey(); Object attrValue = e.getValue(); AtlasAttribute attribute = entityType.getAttribute(attrName); if (attribute == null || attrValue == null) { continue; } context.bindings.clear(); context.bindings.put("typeName", typeName); context.bindings.put("attrName", attribute.getQualifiedName()); context.bindings.put("attrValue", attrValue); List<String> guids = executeGremlinQueryForGuids(queryTemplate, context); if (CollectionUtils.isNotEmpty(guids)) { for (String guid : guids) { AtlasEntityWithExtInfo entityWithExtInfo = entityGraphRetriever.toAtlasEntityWithExtInfo(guid); if (entityWithExtInfo == null) { continue; } ret.add(entityWithExtInfo); } } break; } LOG.info("export(item={}; matchType={}, fetchType={}): found {} entities", item, context.matchType, context.fetchType, ret.size()); } return ret; }
Example 13
Source File: EntityGraphMapper.java From incubator-atlas with Apache License 2.0 | 4 votes |
public static AtlasEntityHeader constructHeader(AtlasObjectId id) { return new AtlasEntityHeader(id.getTypeName(), id.getGuid(), id.getUniqueAttributes()); }
Example 14
Source File: AbstractLineageStrategy.java From nifi with Apache License 2.0 | 4 votes |
private Referenceable toReferenceable(AtlasObjectId id) { return StringUtils.isEmpty(id.getGuid()) ? new Referenceable(id.getTypeName(), id.getUniqueAttributes()) : new Referenceable(id.getGuid(), id.getTypeName(), id.getUniqueAttributes()); }