private boolean shouldIncludeType(IDataType type, Map<TYPE_FILTER, String> filterMap) { if (filterMap == null) { return true; } for (Entry<TYPE_FILTER, String> filterEntry : filterMap.entrySet()) { switch (filterEntry.getKey()) { case CATEGORY: if (!filterEntry.getValue().equals(type.getTypeCategory().name())) { return false; } break; case SUPERTYPE: if (!validSupertypeFilterCategories.contains(type.getTypeCategory()) || !((HierarchicalType) type).getAllSuperTypeNames().contains(filterEntry.getValue())) { return false; } break; case NOT_SUPERTYPE: if (!validSupertypeFilterCategories.contains(type.getTypeCategory()) || type.getName().equals(filterEntry.getValue()) || ((HierarchicalType) type).getAllSuperTypeNames().contains(filterEntry.getValue())) { return false; } break; } } return true; }
@VisibleForTesting public boolean isTypeVertex(AtlasVertex vertex, TypeCategory category) { boolean ret = false; if (isTypeVertex(vertex)) { Object objTypeCategory = vertex.getProperty(Constants.TYPE_CATEGORY_PROPERTY_KEY, Object.class); TypeCategory vertexCategory = null; if(objTypeCategory instanceof TypeCategory) { vertexCategory = (TypeCategory) objTypeCategory; } else if (objTypeCategory != null) { vertexCategory = TypeCategory.valueOf(objTypeCategory.toString()); } ret = category.equals(vertexCategory); } return ret; }
put(TypeCache.TYPE_FILTER.CATEGORY, TypeCategory.TRAIT.name()); put(TypeCache.TYPE_FILTER.SUPERTYPE, "A"); }});
put(TypeCache.TYPE_FILTER.CATEGORY, TypeCategory.TRAIT.name()); put(TypeCache.TYPE_FILTER.SUPERTYPE, "A"); }});
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name());
@Override public AtlasRelationshipDef updateByGuid(String guid, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByGuid({})", guid); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-Def ", (existingDef != null ? existingDef.getName() : guid)); validateType(relationshipDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); // updates should not effect the edges between the types as we do not allow updates that change the endpoints. AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef); } AtlasClassificationDef existingDef = typeRegistry.getClassificationDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update classification-def ", name); validateType(classificationDef); AtlasType type = typeRegistry.getType(classificationDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexAddReferences(classificationDef, vertex); AtlasClassificationDef ret = toClassificationDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}", name, classificationDef, ret); } return ret; }
private boolean shouldIncludeType(IDataType type, Map<TYPE_FILTER, String> filterMap) { if (filterMap == null) { return true; } for (Entry<TYPE_FILTER, String> filterEntry : filterMap.entrySet()) { switch (filterEntry.getKey()) { case CATEGORY: if (!filterEntry.getValue().equals(type.getTypeCategory().name())) { return false; } break; case SUPERTYPE: if (!validSupertypeFilterCategories.contains(type.getTypeCategory()) || !((HierarchicalType) type).getAllSuperTypeNames().contains(filterEntry.getValue())) { return false; } break; case NOT_SUPERTYPE: if (!validSupertypeFilterCategories.contains(type.getTypeCategory()) || type.getName().equals(filterEntry.getValue()) || ((HierarchicalType) type).getAllSuperTypeNames().contains(filterEntry.getValue())) { return false; } break; } } return true; }
@Override public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name); validateType(relationshipDef); AtlasType type = typeRegistry.getType(relationshipDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret); } return ret; }
@Override public AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid); } AtlasStructDef existingDef = typeRegistry.getStructDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update struct-def ", (existingDef != null ? existingDef.getName() : guid)); validateType(structDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } AtlasStructDefStoreV2.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore); AtlasStructDefStoreV2.updateVertexAddReferences(structDef, vertex, typeDefStore); AtlasStructDef ret = toStructDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasStructDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasStructDef updateByGuid(String guid, AtlasStructDef structDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasStructDefStoreV1.updateByGuid({})", guid); } AtlasStructDef existingDef = typeRegistry.getStructDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update struct-def ", (existingDef != null ? existingDef.getName() : guid)); validateType(structDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.STRUCT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } AtlasStructDefStoreV2.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore); AtlasStructDefStoreV2.updateVertexAddReferences(structDef, vertex, typeDefStore); AtlasStructDef ret = toStructDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasStructDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasStructDef updateByName(String name, AtlasStructDef structDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasStructDefStoreV1.updateByName({}, {})", name, structDef); } AtlasStructDef existingDef = typeRegistry.getStructDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update struct-def ", name); validateType(structDef); AtlasType type = typeRegistry.getType(structDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.STRUCT) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, structDef.getName(), TypeCategory.STRUCT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.STRUCT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } AtlasStructDefStoreV2.updateVertexPreUpdate(structDef, (AtlasStructType)type, vertex, typeDefStore); AtlasStructDefStoreV2.updateVertexAddReferences(structDef, vertex, typeDefStore); AtlasStructDef ret = toStructDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasStructDefStoreV1.updateByName({}, {}): {}", name, structDef, ret); } return ret; }
@Override public AtlasRelationshipDef updateByName(String name, AtlasRelationshipDef relationshipDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasRelationshipDefStoreV1.updateByName({}, {})", name, relationshipDef); } AtlasRelationshipDef existingDef = typeRegistry.getRelationshipDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update relationship-def ", name); validateType(relationshipDef); AtlasType type = typeRegistry.getType(relationshipDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.RELATIONSHIP) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, relationshipDef.getName(), TypeCategory.RELATIONSHIP.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.RELATIONSHIP); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } preUpdateCheck(relationshipDef, (AtlasRelationshipType) type, vertex); AtlasRelationshipDef ret = toRelationshipDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasRelationshipDefStoreV1.updateByName({}, {}): {}", name, relationshipDef, ret); } return ret; }
@Override public AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.updateByGuid({})", guid); } AtlasClassificationDef existingDef = typeRegistry.getClassificationDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update classification-def ", (existingDef != null ? existingDef.getName() : guid)); validateType(classificationDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexAddReferences(classificationDef, vertex); AtlasClassificationDef ret = toClassificationDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasEntityDef updateByGuid(String guid, AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.updateByGuid({})", guid); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update entity-def ", (existingDef != null ? existingDef.getName() : guid)); validateType(entityDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasClassificationDef updateByGuid(String guid, AtlasClassificationDef classificationDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.updateByGuid({})", guid); } AtlasClassificationDef existingDef = typeRegistry.getClassificationDefByGuid(guid); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update classification-def ", (existingDef != null ? existingDef.getName() : guid)); validateType(classificationDef); AtlasType type = typeRegistry.getTypeByGuid(guid); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByGuidAndCategory(guid, TypeCategory.TRAIT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_GUID_NOT_FOUND, guid); } updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexAddReferences(classificationDef, vertex); AtlasClassificationDef ret = toClassificationDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.updateByGuid({}): {}", guid, ret); } return ret; }
@Override public AtlasClassificationDef updateByName(String name, AtlasClassificationDef classificationDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasClassificationDefStoreV1.updateByName({}, {})", name, classificationDef); } AtlasClassificationDef existingDef = typeRegistry.getClassificationDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update classification-def ", name); validateType(classificationDef); AtlasType type = typeRegistry.getType(classificationDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.CLASSIFICATION) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, classificationDef.getName(), TypeCategory.TRAIT.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.TRAIT); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(classificationDef, (AtlasClassificationType)type, vertex); updateVertexAddReferences(classificationDef, vertex); AtlasClassificationDef ret = toClassificationDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasClassificationDefStoreV1.updateByName({}, {}): {}", name, classificationDef, ret); } return ret; }
@Override public AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.updateByName({}, {})", name, entityDef); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update entity-def ", name); validateType(entityDef); AtlasType type = typeRegistry.getType(entityDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.updateByName({}, {}): {}", name, entityDef, ret); } return ret; }
@Override public AtlasEntityDef updateByName(String name, AtlasEntityDef entityDef) throws AtlasBaseException { if (LOG.isDebugEnabled()) { LOG.debug("==> AtlasEntityDefStoreV1.updateByName({}, {})", name, entityDef); } AtlasEntityDef existingDef = typeRegistry.getEntityDefByName(name); AtlasAuthorizationUtils.verifyAccess(new AtlasTypeAccessRequest(AtlasPrivilege.TYPE_UPDATE, existingDef), "update entity-def ", name); validateType(entityDef); AtlasType type = typeRegistry.getType(entityDef.getName()); if (type.getTypeCategory() != org.apache.atlas.model.TypeCategory.ENTITY) { throw new AtlasBaseException(AtlasErrorCode.TYPE_MATCH_FAILED, entityDef.getName(), TypeCategory.CLASS.name()); } AtlasVertex vertex = typeDefStore.findTypeVertexByNameAndCategory(name, TypeCategory.CLASS); if (vertex == null) { throw new AtlasBaseException(AtlasErrorCode.TYPE_NAME_NOT_FOUND, name); } updateVertexPreUpdate(entityDef, (AtlasEntityType)type, vertex); updateVertexAddReferences(entityDef, vertex); AtlasEntityDef ret = toEntityDef(vertex); if (LOG.isDebugEnabled()) { LOG.debug("<== AtlasEntityDefStoreV1.updateByName({}, {}): {}", name, entityDef, ret); } return ret; }