Java Code Examples for org.apache.atlas.AtlasErrorCode#INVALID_OBJECT_ID
The following examples show how to use
org.apache.atlas.AtlasErrorCode#INVALID_OBJECT_ID .
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: EntityGraphRetriever.java From atlas with Apache License 2.0 | 6 votes |
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException { AtlasVertex ret = null; if (! AtlasTypeUtil.isValid(objId)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString()); } if (AtlasTypeUtil.isAssignedGuid(objId)) { ret = AtlasGraphUtilsV2.findByGuid(this.graph, objId.getGuid()); } else { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objId.getTypeName()); Map<String, Object> uniqAttributes = objId.getUniqueAttributes(); ret = AtlasGraphUtilsV2.getVertexByUniqueAttributes(this.graph, entityType, uniqAttributes); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, objId.toString()); } return ret; }
Example 2
Source File: AtlasEntityGraphDiscoveryV2.java From atlas with Apache License 2.0 | 6 votes |
@Override public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } validateCustomAttributes(entity); validateLabels(entity.getLabels()); type.validateValue(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValue(entity); }
Example 3
Source File: AtlasEntityGraphDiscoveryV2.java From atlas with Apache License 2.0 | 6 votes |
@Override public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (!AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } validateCustomAttributes(entity); validateLabels(entity.getLabels()); type.validateValueForUpdate(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValueForUpdate(entity); }
Example 4
Source File: EntityGraphRetriever.java From incubator-atlas with Apache License 2.0 | 6 votes |
private AtlasVertex getEntityVertex(AtlasObjectId objId) throws AtlasBaseException { AtlasVertex ret = null; if (! AtlasTypeUtil.isValid(objId)) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, objId.toString()); } if (AtlasTypeUtil.isAssignedGuid(objId)) { ret = AtlasGraphUtilsV1.findByGuid(objId.getGuid()); } else { AtlasEntityType entityType = typeRegistry.getEntityTypeByName(objId.getTypeName()); Map<String, Object> uniqAttributes = objId.getUniqueAttributes(); ret = AtlasGraphUtilsV1.getVertexByUniqueAttributes(entityType, uniqAttributes); } if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_GUID_NOT_FOUND, objId.toString()); } return ret; }
Example 5
Source File: EntityGraphMapper.java From incubator-atlas with Apache License 2.0 | 6 votes |
private static AtlasObjectId getObjectId(Object val) throws AtlasBaseException { if (val != null) { if ( val instanceof AtlasObjectId) { return ((AtlasObjectId) val); } else if (val instanceof Map) { AtlasObjectId ret = new AtlasObjectId((Map)val); if (AtlasTypeUtil.isValid(ret)) { return ret; } } throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, val.toString()); } return null; }
Example 6
Source File: EntityGraphMapper.java From incubator-atlas with Apache License 2.0 | 6 votes |
private AtlasEntityType getInstanceType(Object val) throws AtlasBaseException { AtlasEntityType ret = null; if (val != null) { String typeName = null; if (val instanceof AtlasObjectId) { typeName = ((AtlasObjectId)val).getTypeName(); } else if (val instanceof Map) { Object typeNameVal = ((Map)val).get(AtlasObjectId.KEY_TYPENAME); if (typeNameVal != null) { typeName = typeNameVal.toString(); } } ret = typeName != null ? typeRegistry.getEntityTypeByName(typeName) : null; if (ret == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, val.toString()); } } return ret; }
Example 7
Source File: AtlasEntityGraphDiscoveryV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public void validateAndNormalize(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } type.validateValue(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValue(entity); }
Example 8
Source File: AtlasEntityGraphDiscoveryV1.java From incubator-atlas with Apache License 2.0 | 6 votes |
@Override public void validateAndNormalizeForUpdate(AtlasEntity entity) throws AtlasBaseException { List<String> messages = new ArrayList<>(); if (! AtlasTypeUtil.isValidGuid(entity.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, "invalid guid " + entity.getGuid()); } AtlasEntityType type = typeRegistry.getEntityTypeByName(entity.getTypeName()); if (type == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_INVALID, TypeCategory.ENTITY.name(), entity.getTypeName()); } type.validateValueForUpdate(entity, entity.getTypeName(), messages); if (!messages.isEmpty()) { throw new AtlasBaseException(AtlasErrorCode.INSTANCE_CRUD_INVALID_PARAMS, messages); } type.getNormalizedValueForUpdate(entity); }
Example 9
Source File: UserProfileService.java From atlas with Apache License 2.0 | 5 votes |
public AtlasUserSavedSearch updateSavedSearch(AtlasUserSavedSearch savedSearch) throws AtlasBaseException { if (StringUtils.isBlank(savedSearch.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, savedSearch.getGuid()); } AtlasUserSavedSearch existingSearch = getSavedSearch(savedSearch.getGuid()); // ownerName change is not allowed if (!StringUtils.equals(existingSearch.getOwnerName(), savedSearch.getOwnerName())) { throw new AtlasBaseException(AtlasErrorCode.SAVED_SEARCH_CHANGE_USER, existingSearch.getName(), existingSearch.getOwnerName(), savedSearch.getOwnerName()); } // if renamed, ensure that there no other search with the new name exists if (!StringUtils.equals(existingSearch.getName(), savedSearch.getName())) { AtlasUserProfile userProfile = getUserProfile(existingSearch.getOwnerName()); // check if a another search with this name already exists for (AtlasUserSavedSearch search : userProfile.getSavedSearches()) { if (StringUtils.equals(search.getName(), savedSearch.getName())) { if (!StringUtils.equals(search.getGuid(), savedSearch.getGuid())) { throw new AtlasBaseException(AtlasErrorCode.SAVED_SEARCH_ALREADY_EXISTS, savedSearch.getName(), savedSearch.getOwnerName()); } } } } return dataAccess.save(savedSearch); }
Example 10
Source File: EntityGraphMapper.java From atlas with Apache License 2.0 | 4 votes |
private AtlasEdge mapObjectIdValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> mapObjectIdValue({})", ctx); } AtlasEdge ret = null; String guid = getGuid(ctx.getValue()); AtlasVertex entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(guid); if (entityVertex == null) { if (AtlasTypeUtil.isAssignedGuid(guid)) { entityVertex = context.getVertex(guid); } if (entityVertex == null) { AtlasObjectId objId = getObjectId(ctx.getValue()); if (objId != null) { entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId); } } } if (entityVertex == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString())); } if (ctx.getCurrentEdge() != null) { ret = updateEdge(ctx.getAttributeDef(), ctx.getValue(), ctx.getCurrentEdge(), entityVertex); } else if (ctx.getValue() != null) { String edgeLabel = AtlasGraphUtilsV2.getEdgeLabel(ctx.getVertexProperty()); try { ret = graphHelper.getOrCreateEdge(ctx.getReferringVertex(), entityVertex, edgeLabel); } catch (RepositoryException e) { throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e); } } if (LOG.isDebugEnabled()) { LOG.debug("<== mapObjectIdValue({})", ctx); } return ret; }
Example 11
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 12
Source File: EntityGraphMapper.java From incubator-atlas with Apache License 2.0 | 4 votes |
private AtlasEdge mapObjectIdValue(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> mapObjectIdValue({})", ctx); } AtlasEdge ret = null; String guid = getGuid(ctx.getValue()); AtlasVertex entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(guid); if (entityVertex == null) { AtlasObjectId objId = getObjectId(ctx.getValue()); if (objId != null) { entityVertex = context.getDiscoveryContext().getResolvedEntityVertex(objId); } } if (entityVertex == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString())); } if (ctx.getCurrentEdge() != null) { ret = updateEdge(ctx.getAttributeDef(), ctx.getValue(), ctx.getCurrentEdge(), entityVertex); } else if (ctx.getValue() != null) { String edgeLabel = AtlasGraphUtilsV1.getEdgeLabel(ctx.getVertexProperty()); try { ret = graphHelper.getOrCreateEdge(ctx.getReferringVertex(), entityVertex, edgeLabel); } catch (RepositoryException e) { throw new AtlasBaseException(AtlasErrorCode.INTERNAL_ERROR, e); } } if (LOG.isDebugEnabled()) { LOG.debug("<== mapObjectIdValue({})", ctx); } return ret; }
Example 13
Source File: EntityGraphMapper.java From incubator-atlas with Apache License 2.0 | 4 votes |
private AtlasEdge mapObjectIdValueUsingRelationship(AttributeMutationContext ctx, EntityMutationContext context) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> mapObjectIdValueUsingRelationship({})", ctx); } AtlasVertex attributeVertex = context.getDiscoveryContext().getResolvedEntityVertex(getGuid(ctx.getValue())); AtlasVertex entityVertex = ctx.getReferringVertex(); AtlasEdge ret; if (attributeVertex == null) { AtlasObjectId objectId = getObjectId(ctx.getValue()); attributeVertex = (objectId != null) ? context.getDiscoveryContext().getResolvedEntityVertex(objectId) : null; } if (attributeVertex == null) { throw new AtlasBaseException(AtlasErrorCode.INVALID_OBJECT_ID, (ctx.getValue() == null ? null : ctx.getValue().toString())); } String attributeName = ctx.getAttribute().getName(); AtlasType type = typeRegistry.getType(AtlasGraphUtilsV1.getTypeName(entityVertex)); AtlasRelationshipEdgeDirection edgeDirection = ctx.getAttribute().getRelationshipEdgeDirection(); String edgeLabel = ctx.getAttribute().getRelationshipEdgeLabel(); if (type instanceof AtlasEntityType) { AtlasEntityType entityType = (AtlasEntityType) type; // use relationship to create/update edges if (entityType.hasRelationshipAttribute(attributeName)) { if (ctx.getCurrentEdge() != null) { ret = updateRelationship(ctx.getCurrentEdge(), attributeVertex, edgeDirection, ctx.getAttribute()); recordEntityUpdate(attributeVertex); } else { String relationshipName = graphHelper.getRelationshipDefName(entityVertex, entityType, attributeName); AtlasVertex fromVertex; AtlasVertex toVertex; if (edgeDirection == IN) { fromVertex = attributeVertex; toVertex = entityVertex; } else { fromVertex = entityVertex; toVertex = attributeVertex; } boolean relationshipExists = isRelationshipExists(fromVertex, toVertex, edgeLabel); ret = getOrCreateRelationship(fromVertex, toVertex, relationshipName, ctx.getAttribute()); // if relationship did not exist before and new relationship was created // record entity update on both relationship vertices if (!relationshipExists) { recordEntityUpdate(attributeVertex); } } } else { // use legacy way to create/update edges if (LOG.isDebugEnabled()) { LOG.debug("No RelationshipDef defined between {} and {} on attribute: {}", getTypeName(entityVertex), getTypeName(attributeVertex), attributeName); } ret = mapObjectIdValue(ctx, context); } } else { // if type is StructType having objectid as attribute ret = mapObjectIdValue(ctx, context); } if (LOG.isDebugEnabled()) { LOG.debug("<== mapObjectIdValueUsingRelationship({})", ctx); } return ret; }