search_v3_alpha.py 4.19 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# Copyright 2021 Schlumberger
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

from fastapi import APIRouter, Depends
fabian serin's avatar
fabian serin committed
16
from odes_search.models import CursorQueryResponse
17

18
19
from app.utils import Context
from .search_v3 import (
fabian serin's avatar
fabian serin committed
20
21
    SearchQueryRequest,
    DEFAULT_QUERYREQUEST,
22
    OSDU_WELLBORE_KIND,
fabian serin's avatar
fabian serin committed
23
    OSDU_WELLBORETRAJECTORY_KIND,
fabian serin's avatar
fabian serin committed
24
    OSDU_WELLLOG_KIND,
fabian serin's avatar
fabian serin committed
25
26
27
    escape_forbidden_characters_for_search,
    update_query_with_names_based_search,
    query_request,
fabian serin's avatar
fabian serin committed
28
29
    added_relationships_query,
    WELLBORE_RELATIONSHIP,
30
    get_ctx,
fabian serin's avatar
cleanup    
fabian serin committed
31
32
    query_type,
    update_query_with_nested_names_based_search)
33
34
35
36
37
from ..common_parameters import REQUIRED_ROLES_READ

router = APIRouter()


38
@router.post('/query/wellbores', summary='Query with cursor or offset, get wellbores',
39
40
41
             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)
42
async def query_wellbores_by_name(names: str = None, body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
43
44
45
46
                                  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)
    return await query_request(query_type, OSDU_WELLBORE_KIND, ctx, body)
fabian serin's avatar
fabian serin committed
47
48
49
50
51
52
53
54
55
56
57
58


@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)
fabian serin's avatar
fabian serin committed
59
60


61
@router.post('/query/welllogs',
62
63
             summary='Query with cursor, search WellLogs by name and optionally by wellbore ID and curves mnemonics',
             description=f"""Get all WellLogs objects using its name and optionally relationship Wellbore ID. Filtering can be done on curves mnemonics
fabian serin's avatar
fabian serin committed
64
65
            <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)
66
67
68
async def query_welllogs_by_name(names: str = None, wellbore_id: str = None, mnemonics: str = None,
                                 body: SearchQueryRequest = DEFAULT_QUERYREQUEST,
                                 ctx: Context = Depends(get_ctx)):
fabian serin's avatar
fabian serin committed
69
70
71
    if wellbore_id is not None:
        body.query = added_relationships_query(wellbore_id, WELLBORE_RELATIONSHIP, body.query)
    names = escape_forbidden_characters_for_search(names)
72
    mnemonics = escape_forbidden_characters_for_search(mnemonics)
fabian serin's avatar
fabian serin committed
73
    body.query = update_query_with_names_based_search(names=names, user_query=body.query, name_field="data.Name")
74
75
    body.query = update_query_with_nested_names_based_search(array_field='data.Curves', nested_field='Mnemonic',
                                                             names=mnemonics, user_query=body.query)
fabian serin's avatar
fabian serin committed
76
    return await query_request(query_type, OSDU_WELLLOG_KIND, ctx, body)