Commit 9213b8f3 authored by fabian serin's avatar fabian serin
Browse files

Merge branch 'fserin/search_trajectory_by_wellbore' into 'master'

Add api to search all trajectories associated to a wellbore

See merge request !214
parents 9281bd83 f7bf53b3
Pipeline #59391 passed with stages
in 21 minutes and 43 seconds
......@@ -21,7 +21,7 @@ from odes_search.models import (
Field,
Optional)
from app.clients.search_service_client import get_search_service
from ..common_parameters import REQUIRED_ROLES_READ
from app.routers.common_parameters import REQUIRED_ROLES_READ
from app.utils import Context
import app.routers.search.search_wrapper as search_wrapper
from .search import (
......@@ -39,6 +39,7 @@ router = APIRouter()
OSDU_WELLBORE_KIND = '*:wks:master-data--Wellbore:*'
OSDU_WELLLOG_KIND = '*:wks:work-product-component--WellLog:*'
OSDU_WELLBOREMARKERSET_KIND = '*:wks:work-product-component--WellboreMarkerSet:*'
OSDU_WELLBORETRAJECTORY_KIND = '*:wks:work-product-component--WellboreTrajectory:*'
WELLBORE_RELATIONSHIP = "WellboreID"
......
......@@ -14,15 +14,17 @@
from fastapi import APIRouter, Depends
from odes_search.models import CursorQueryResponse
from app.utils import Context
from .search_v3 import (
SearchQueryRequest,
DEFAULT_QUERYREQUEST,
OSDU_WELLBORE_KIND,
OSDU_WELLBORETRAJECTORY_KIND,
escape_forbidden_characters_for_search,
update_query_with_names_based_search,
query_request,
added_relationships_query,
WELLBORE_RELATIONSHIP,
get_ctx,
query_type)
from ..common_parameters import REQUIRED_ROLES_READ
......@@ -39,3 +41,15 @@ async def query_wellbores_by_name(names: str, body: SearchQueryRequest = DEFAULT
names = escape_forbidden_characters_for_search(names)
body.query = update_query_with_names_based_search(names=names, user_query=body.query)
return await query_request(query_type, OSDU_WELLBORE_KIND, ctx, body)
@router.post('/query/wellbores/{wellboreId}/wellboretrajectories',
summary='Query with cursor, search wellbore trajectories by wellbore ID',
description=f"""Get all Wellbore Trajectories objects using its relationship Wellbore ID. <p>All Wellbore Trajectories linked to this
specific ID will be returned</p>
<p>The Wellbore Trajectories kind is {OSDU_WELLBORETRAJECTORY_KIND} returns all records directly based on existing schemas</p>{REQUIRED_ROLES_READ}""",
response_model=CursorQueryResponse)
async def query_trajectories_bywellbore(wellboreId: str, body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
ctx: Context = Depends(get_ctx)):
body.query = added_relationships_query(wellboreId, WELLBORE_RELATIONSHIP, body.query)
return await query_request(query_type, OSDU_WELLBORETRAJECTORY_KIND, ctx, body)
......@@ -9279,6 +9279,81 @@
]
}
},
"/alpha/ddms/v3/query/wellbores/{wellboreId}/wellboretrajectories": {
"post": {
"description": "Get all Wellbore Trajectories objects using its relationship Wellbore ID. <p>All Wellbore Trajectories linked to this\n specific ID will be returned</p>\n <p>The Wellbore Trajectories kind is *:wks:work-product-component--WellboreTrajectory:* returns all records directly based on existing schemas</p>\n<p>Required roles: 'users.datalake.viewers' or 'users.datalake.editors' or 'users.datalake.admins'.\n\"In addition, users must be a member of data groups to access the data.</p>\n",
"operationId": "query_trajectories_bywellbore_alpha_ddms_v3_query_wellbores__wellboreId__wellboretrajectories_post",
"parameters": [
{
"in": "path",
"name": "wellboreId",
"required": true,
"schema": {
"title": "Wellboreid",
"type": "string"
}
},
{
"description": "identifier of the data partition to query",
"in": "header",
"name": "data-partition-id",
"required": false,
"schema": {
"description": "identifier of the data partition to query",
"minLength": 1,
"title": "data partition id",
"type": "string"
}
}
],
"requestBody": {
"content": {
"application/json": {
"schema": {
"allOf": [
{
"$ref": "#/components/schemas/SearchQueryRequest"
}
],
"default": {},
"title": "Body"
}
}
}
},
"responses": {
"200": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/CursorQueryResponse"
}
}
},
"description": "Successful Response"
},
"422": {
"content": {
"application/json": {
"schema": {
"$ref": "#/components/schemas/HTTPValidationError"
}
}
},
"description": "Validation Error"
}
},
"security": [
{
"HTTPBearer": []
}
],
"summary": "Query with cursor, search wellbore trajectories by wellbore ID",
"tags": [
"ALPHA feature: search v3"
]
}
},
"/ddms/fastquery/logs": {
"post": {
"description": "Get all Logs object. <p>The Logs kind is\n *:wks:log:* returns all records IDs directly based on existing schemas</p>\n<p>Required roles: 'users.datalake.viewers' or 'users.datalake.editors' or 'users.datalake.admins'.\n\"In addition, users must be a member of data groups to access the data.</p>\n",
......
......@@ -363,3 +363,19 @@ def build_request_search_wellbore_by_name() -> RequestRunner:
payload='{}'
)
return RequestRunner(rq_proto)
def build_request_search_trajectory_by_wellbore_id() -> RequestRunner:
rq_proto = Request(
name='search wellbore by name',
method='POST',
url='{{base_url}}/alpha/ddms/v3/{{search_query_type}}/wellbores/{{setup_search_osdu_wellbore_id}}/wellboretrajectories',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
'Connection': '{{header_connection}}',
'Authorization': 'Bearer {{token}}',
},
payload='{}'
)
return RequestRunner(rq_proto)
......@@ -200,7 +200,7 @@ def build_request_seach_tests_setup_create_logsets() -> RequestRunner:
return RequestRunner(rq_proto)
def build_request_seach_tests_setup_create_osdu_welllogs() -> RequestRunner:
def build_request_search_tests_setup_create_osdu_welllogs() -> RequestRunner:
rq_proto = Request(
name='seach_tests_setup_create_osdu_welllog',
method='POST',
......@@ -219,6 +219,19 @@ def build_request_seach_tests_setup_create_osdu_welllogs() -> RequestRunner:
"data": {
"WellboreID": "{{setup_search_osdu_wellbore_id}}:",
"Name": "wdms_e2e_search_record_v{{search_record_version}}",
"VerticalMeasurement": {
"EffectiveDateTime": "2020-02-13T09:13:15.55Z",
"VerticalMeasurement": 12345.6,
"TerminationDateTime": "2020-02-13T09:13:15.55Z",
"VerticalMeasurementTypeID": "namespace:reference-data--VerticalMeasurementType:Plug%20Back%20depth:",
"VerticalMeasurementPathID": "namespace:reference-data--VerticalMeasurementPath:SomeUniqueVerticalMeasurementPathID:",
"VerticalMeasurementSourceID": "namespace:reference-data--VerticalMeasurementSource:SomeUniqueVerticalMeasurementSourceID:",
"WellboreTVDTrajectoryID": "namespace:work-product-component--WellboreTrajectory:WellboreTrajectory-123456:",
"VerticalMeasurementUnitOfMeasureID": "namespace:reference-data--UnitOfMeasure:m:",
"VerticalCRSID": "namespace:reference-data--CoordinateReferenceSystem:SomeUniqueCoordinateReferenceSystemID:",
"VerticalReferenceID": "Example VerticalReferenceID",
"VerticalMeasurementDescription": "Example VerticalMeasurementDescription"
},
"Curves": [{
"CurveID": "Example CurveID",
"DateStamp": "2020-02-13T09:13:15.55Z",
......@@ -237,20 +250,7 @@ def build_request_seach_tests_setup_create_osdu_welllogs() -> RequestRunner:
"LogCurveTypeID": "namespace:reference-data--LogCurveType:SomeUniqueLogCurveTypeID:",
"LogCurveBusinessValueID": "namespace:reference-data--LogCurveBusinessValue:SomeUniqueLogCurveBusinessValueID:",
"LogCurveMainFamilyID": "namespace:reference-data--LogCurveMainFamily:SomeUniqueLogCurveMainFamilyID:",
"LogCurveFamilyID": "namespace:reference-data--LogCurveFamily:SomeUniqueLogCurveFamilyID:",
"VerticalMeasurement": {
"EffectiveDateTime": "2020-02-13T09:13:15.55Z",
"VerticalMeasurement": 12345.6,
"TerminationDateTime": "2020-02-13T09:13:15.55Z",
"VerticalMeasurementTypeID": "namespace:reference-data--VerticalMeasurementType:Plug%20Back%20depth:",
"VerticalMeasurementPathID": "namespace:reference-data--VerticalMeasurementPath:SomeUniqueVerticalMeasurementPathID:",
"VerticalMeasurementSourceID": "namespace:reference-data--VerticalMeasurementSource:SomeUniqueVerticalMeasurementSourceID:",
"WellboreTVDTrajectoryID": "namespace:work-product-component--WellboreTrajectory:WellboreTrajectory-123456:",
"VerticalMeasurementUnitOfMeasureID": "namespace:reference-data--UnitOfMeasure:m:",
"VerticalCRSID": "namespace:reference-data--CoordinateReferenceSystem:SomeUniqueCoordinateReferenceSystemID:",
"VerticalReferenceID": "Example VerticalReferenceID",
"VerticalMeasurementDescription": "Example VerticalMeasurementDescription"
}
"LogCurveFamilyID": "namespace:reference-data--LogCurveFamily:SomeUniqueLogCurveFamilyID:"
}]
},
"meta": [
......@@ -619,7 +619,7 @@ def build_request_seach_tests_setup_create_wellbore() -> RequestRunner:
return RequestRunner(rq_proto)
def build_request_seach_tests_setup_create_osdu_wellbore() -> RequestRunner:
def build_request_search_tests_setup_create_osdu_wellbore() -> RequestRunner:
rq_proto = Request(
name='seach_tests_setup_create_osdu_wellbore',
method='POST',
......@@ -869,7 +869,7 @@ def build_request_seach_tests_setup_create_markers() -> RequestRunner:
return RequestRunner(rq_proto)
def build_request_seach_tests_setup_create_osdu_markersets() -> RequestRunner:
def build_request_search_tests_setup_create_osdu_markersets() -> RequestRunner:
rq_proto = Request(
name='seach_tests_setup_create_osdu_markersets',
method='POST',
......@@ -914,6 +914,54 @@ def build_request_seach_tests_setup_create_osdu_markersets() -> RequestRunner:
return RequestRunner(rq_proto)
def build_request_search_tests_setup_create_osdu_trajectories() -> RequestRunner:
rq_proto = Request(
name='seach_tests_setup_create_osdu_trajectories',
method='POST',
url='{{base_url}}/ddms/v3/wellboretrajectories',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
'Connection': '{{header_connection}}',
'Authorization': 'Bearer {{token}}',
},
payload=r"""
[
{
"acl": {{record_acl}}, "legal": {{record_legal}},
"kind": "{{osduWellboreTrajectoryKind}}",
"data": {
"Name": "wdms_e2e_search_record_v{{search_record_version}}",
"WellboreID": "{{setup_search_osdu_wellbore_id}}:",
"TopDepthMeasuredDepth": 12345.6,
"BaseDepthMeasuredDepth": 123.6,
"AzimuthReferenceType": "namespace:reference-data--AzimuthReferenceType:TrueNorth:",
"CalculationMethodType": "namespace:reference-data--CalculationMethodType:MinimumCurvature:",
"ProjectedCRSID": "namespace:reference-data--CoordinateReferenceSystem:ProjectedCRS.EPSG.32615:",
"ActiveIndicator": true,
"VerticalMeasurement": {
"EffectiveDateTime": "2020-02-13T09:13:15.550000+00:00",
"VerticalMeasurement": 12345.6,
"TerminationDateTime": "2020-02-13T09:13:15.550000+00:00",
"VerticalMeasurementTypeID": "namespace:reference-data--VerticalMeasurementType:PBD:",
"VerticalMeasurementPathID": "namespace:reference-data--VerticalMeasurementPath:MD:",
"VerticalMeasurementSourceID": "namespace:reference-data--VerticalMeasurementSource:DRL:",
"WellboreTVDTrajectoryID": "namespace:work-product-component--WellboreTrajectory:WellboreTrajectory-456:",
"VerticalMeasurementUnitOfMeasureID": "namespace:reference-data--UnitOfMeasure:m:",
"VerticalCRSID": "namespace:reference-data--CoordinateReferenceSystem:BoundCRS::OSDU::23031018:",
"VerticalReferenceID": "Example VerticalReferenceID",
"VerticalMeasurementDescription": "Example VerticalMeasurementDescription"
},
"SurveyType": "Example Directional Survey Type"
}
}
]
"""
)
return RequestRunner(rq_proto)
def build_request_seach_tests_setup_start() -> RequestRunner:
rq_proto = Request(
name='seach_tests_setup_start',
......@@ -953,7 +1001,7 @@ def build_request_osdu_seach_tests_setup_start() -> RequestRunner:
payload=r"""
{
"kind": "{{osduWellLogKind}}",
"kind": "{{osduWellboreTrajectoryKind}}",
"query": "data.Name:\"wdms_e2e_search_record_v{{search_record_version}}\" AND _exists_:data.WellboreID",
"returnedFields": ["id", "data.WellboreID"]
}
......
......@@ -27,7 +27,6 @@ def query_for_record_set_available(env):
result = build_request_osdu_seach_tests_setup_start().call(env)
result.assert_ok()
return result.get_response_obj()
# return result.response.json()
@pytest.mark.tag('search')
@pytest.mark.dependency()
......@@ -50,17 +49,20 @@ def test_setup_for_search(with_wdms_env):
if nb_record == 0:
# create one wellbore
record_id = build_request_seach_tests_setup_create_osdu_wellbore().call(
record_id = build_request_search_tests_setup_create_osdu_wellbore().call(
env, assert_status=200).get_response_obj().recordIds[0]
env.set("setup_search_osdu_wellbore_id", record_id)
for _ in range(2): # create 2 logset
record_id = build_request_seach_tests_setup_create_osdu_welllogs().call(
record_id = build_request_search_tests_setup_create_osdu_welllogs().call(
env, assert_status=200).get_response_obj().recordIds[0]
env.set("setup_search_osdu_welllog_id", record_id) # it doesn't matter which logset id is set
for _ in range(2): # create 2 marker
build_request_seach_tests_setup_create_osdu_markersets().call(env, assert_status=200)
build_request_search_tests_setup_create_osdu_markersets().call(env, assert_status=200)
for _ in range(2): # create 2 trajectories
build_request_search_tests_setup_create_osdu_trajectories().call(env, assert_status=200)
# wait for the record to be searchable
while nb_record <= 0 and wait_attempt >= 0:
......@@ -102,3 +104,13 @@ def test_search_wellbore_by_name(with_wdms_env):
env.set('search_query_type', 'query')
resobj = build_request_search_wellbore_by_name().call(with_wdms_env, assert_status=200).get_response_obj()
assert resobj.totalCount >= 1
@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_trajectory_by_wellbore_id(with_wdms_env):
#Only search and no fast search
env = with_wdms_env
env.set('search_query_type', 'query')
resobj = build_request_search_trajectory_by_wellbore_id().call(with_wdms_env, assert_status=200).get_response_obj()
assert resobj.totalCount >= 1
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment