Commit bea93ba0 authored by fabian serin's avatar fabian serin
Browse files

Merge branch 'fserin/search_wellLog_by_name' into 'master'

Add api to search wellLogs by names using wildcards and optionally by wellboreID

See merge request !217
parents e8dbc811 3eada8d2
Pipeline #60524 passed with stages
in 7 minutes and 43 seconds
......@@ -127,14 +127,18 @@ async def query_request_with_specific_attribute(query_type: str, attribute: str,
def update_query_with_names_based_search(names: str = None, user_query: str = None) -> str:
generated_query = f"data.FacilityName:{names}"
def update_query_with_names_based_search(names: str = None, user_query: str = None, name_field = "data.FacilityName") -> str:
if names is None:
return user_query
generated_query = f"{name_field}:{names}"
return added_query(generated_query, user_query)
def escape_forbidden_characters_for_search(input_str: str) -> str:
# Reserved character are listed here https://community.opengroup.org/osdu/documentation/-/blob/master/platform/tutorials/core-services/SearchService.md
# ? and * are allowed for wildcard search
if input_str is None:
return None
reserved_char_list = ['+', '-', '=', '>', '<', '!', '(', ')', '{', '}', '[', ']', '^', '"', '~',
':', '\\', '/']
......
......@@ -20,6 +20,7 @@ from .search_v3 import (
DEFAULT_QUERYREQUEST,
OSDU_WELLBORE_KIND,
OSDU_WELLBORETRAJECTORY_KIND,
OSDU_WELLLOG_KIND,
escape_forbidden_characters_for_search,
update_query_with_names_based_search,
query_request,
......@@ -32,11 +33,11 @@ from ..common_parameters import REQUIRED_ROLES_READ
router = APIRouter()
@router.post('/query/wellbores/byname', summary='Query with cursor or offset, get wellbores',
@router.post('/query/wellbores', summary='Query with cursor or offset, get wellbores',
description=f"""Get Wellbores object by name. <p>The wellbore kind is {OSDU_WELLBORE_KIND}
returns all records directly based on existing schemas. The query is done on data.FacilityName field</p>{REQUIRED_ROLES_READ}""",
response_model=CursorQueryResponse)
async def query_wellbores_by_name(names: str, body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
async def query_wellbores_by_name(names: str = None, body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
ctx: Context = Depends(get_ctx)):
names = escape_forbidden_characters_for_search(names)
body.query = update_query_with_names_based_search(names=names, user_query=body.query)
......@@ -53,3 +54,17 @@ async def query_trajectories_bywellbore(wellboreId: str, body: SearchQueryReques
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)
@router.post('/query/welllogs',
summary='Query with cursor, search WellLogs by name and optionally by wellbore ID',
description=f"""Get all WellLogs objects using its name and optionally relationship Wellbore ID.
<p>The WellLogs kind is {OSDU_WELLLOG_KIND} returns all records directly based on existing schemas. The query is done on data.Name field</p>{REQUIRED_ROLES_READ}""",
response_model=CursorQueryResponse)
async def query_welllogs_by_name(names: str = None, wellbore_id: str = None, body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
ctx: Context = Depends(get_ctx)):
if wellbore_id is not None:
body.query = added_relationships_query(wellbore_id, WELLBORE_RELATIONSHIP, body.query)
names = escape_forbidden_characters_for_search(names)
body.query = update_query_with_names_based_search(names=names, user_query=body.query, name_field="data.Name")
return await query_request(query_type, OSDU_WELLLOG_KIND, ctx, body)
......@@ -48,7 +48,7 @@ from app.routers.ddms_v3 import (
from app.routers.bulk import bulk_routes
from app.routers.trajectory import trajectory_ddms_v2
from app.routers.dipset import dipset_ddms_v2, dip_ddms_v2
from app.routers.search import search, fast_search, search_v3, fast_search_v3, search_v3_wellbore
from app.routers.search import search, fast_search, search_v3, fast_search_v3, search_v3_alpha
from app.clients import StorageRecordServiceClient, SearchServiceClient
from app.utils import (
get_http_client_session,
......@@ -206,7 +206,7 @@ wdms_app.include_router(fast_search.router, prefix='/ddms', tags=['fast-search']
wdms_app.include_router(search_v3.router, prefix=DDMS_V3_PATH, tags=['search v3'], dependencies=basic_dependencies)
wdms_app.include_router(fast_search_v3.router, prefix=DDMS_V3_PATH, tags=['fast-search v3'],
dependencies=basic_dependencies)
wdms_app.include_router(search_v3_wellbore.router, prefix=ALPHA_APIS_PREFIX+DDMS_V3_PATH, tags=['ALPHA feature: search v3'],
wdms_app.include_router(search_v3_alpha.router, prefix=ALPHA_APIS_PREFIX + DDMS_V3_PATH, tags=['ALPHA feature: search v3'],
dependencies=basic_dependencies)
......
......@@ -9204,15 +9204,15 @@
]
}
},
"/alpha/ddms/v3/query/wellbores/byname": {
"/alpha/ddms/v3/query/wellbores": {
"post": {
"description": "Get Wellbores object by name. <p>The wellbore kind is *:wks:master-data--Wellbore:*\n returns all records directly based on existing schemas. The query is done on data.FacilityName field</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_wellbores_by_name_alpha_ddms_v3_query_wellbores_byname_post",
"operationId": "query_wellbores_by_name_alpha_ddms_v3_query_wellbores_post",
"parameters": [
{
"in": "query",
"name": "names",
"required": true,
"required": false,
"schema": {
"title": "Names",
"type": "string"
......@@ -9354,6 +9354,90 @@
]
}
},
"/alpha/ddms/v3/query/welllogs": {
"post": {
"description": "Get all WellLogs objects using its name and optionally relationship Wellbore ID. \n <p>The WellLogs kind is *:wks:work-product-component--WellLog:* returns all records directly based on existing schemas. The query is done on data.Name field</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_welllogs_by_name_alpha_ddms_v3_query_welllogs_post",
"parameters": [
{
"in": "query",
"name": "names",
"required": false,
"schema": {
"title": "Names",
"type": "string"
}
},
{
"in": "query",
"name": "wellbore_id",
"required": false,
"schema": {
"title": "Wellbore Id",
"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 WellLogs by name and optionally 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",
......
......@@ -353,7 +353,7 @@ def build_request_search_wellbore_by_name() -> RequestRunner:
rq_proto = Request(
name='search wellbore by name',
method='POST',
url='{{base_url}}/alpha/ddms/v3/{{search_query_type}}/wellbores/byname?names=wdms_e2e_search_refs_v%2A',
url='{{base_url}}/alpha/ddms/v3/{{search_query_type}}/wellbores?names=wdms_e2e_search_refs_v%2A',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
......@@ -379,3 +379,37 @@ def build_request_search_trajectory_by_wellbore_id() -> RequestRunner:
payload='{}'
)
return RequestRunner(rq_proto)
def build_request_search_welllog_by_name() -> RequestRunner:
rq_proto = Request(
name='search wellbore by name',
method='POST',
url='{{base_url}}/alpha/ddms/v3/{{search_query_type}}/welllogs?names=wdms_e2e_search_record_%2A',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
'Connection': '{{header_connection}}',
'Authorization': 'Bearer {{token}}',
},
payload='{}'
)
return RequestRunner(rq_proto)
def build_request_search_welllog_by_name_and_wellbore() -> RequestRunner:
rq_proto = Request(
name='search wellbore by name',
method='POST',
url='{{base_url}}/alpha/ddms/v3/{{search_query_type}}/welllogs?names=wdms_e2e_search_record_%2A'
'&wellbore_id={{setup_search_osdu_wellbore_id}}',
headers={
'accept': 'application/json',
'data-partition-id': '{{data_partition}}',
'Connection': '{{header_connection}}',
'Authorization': 'Bearer {{token}}',
},
payload='{}'
)
return RequestRunner(rq_proto)
......@@ -30,7 +30,7 @@ variables_dict = {
"authorityKind": "{{data_partition}}",
"osduWellboreKind": "osdu:wks:master-data--Wellbore:1.0.0",
"osduWellKind": "osdu:wks:master-data--Well:1.0.0",
"osduWellLogKind": "osdu:wks:work-product-component--WellLog:1.0.0",
"osduWellLogKind": "osdu:wks:work-product-component--WellLog:1.1.0",
"osduWellboreTrajectoryKind": "osdu:wks:work-product-component--WellboreTrajectory:1.1.0",
"osduWellboreMarkerSetKind": "osdu:wks:work-product-component--WellboreMarkerSet:1.0.0",
"acl_domain": "p4d.cloud.slb-ds.com",
......
......@@ -114,3 +114,23 @@ def test_search_trajectory_by_wellbore_id(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
@pytest.mark.tag('search')
@pytest.mark.dependency(depends=["test_setup_for_search"])
def test_search_wellLog_by_name(with_wdms_env):
#Only search and no fast search
env = with_wdms_env
env.set('search_query_type', 'query')
resobj = build_request_search_welllog_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_wellLog_by_name_and_wellbore(with_wdms_env):
#Only search and no fast search
env = with_wdms_env
env.set('search_query_type', 'query')
resobj = build_request_search_welllog_by_name_and_wellbore().call(with_wdms_env, assert_status=200).get_response_obj()
assert resobj.totalCount >= 1
......@@ -34,7 +34,7 @@ def test_added_relationships_query(id, user_query, expected_query):
NAMES_QUERY_PARAMS = [
(None, None, 'data.FacilityName:None'),
(None, None, None),
('Fab OR Fred', None, 'data.FacilityName:Fab OR Fred'),
('Fab', 'data.AnyField:\\"any value\\"', 'data.FacilityName:Fab AND (data.AnyField:\\"any value\\")'),
]
......
Markdown is supported
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