search_v3_alpha.py 4.22 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 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.

15
16
from typing import Optional, Dict, List

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

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

router = APIRouter()


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


@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
60
61


62
@router.post('/query/welllogs',
63
64
             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
65
66
            <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)
67
68
69
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
70
71
72
    if wellbore_id is not None:
        body.query = added_relationships_query(wellbore_id, WELLBORE_RELATIONSHIP, body.query)
    names = escape_forbidden_characters_for_search(names)
73
    mnemonics = escape_forbidden_characters_for_search(mnemonics)
fabian serin's avatar
fabian serin committed
74
    body.query = update_query_with_names_based_search(names=names, user_query=body.query, name_field="data.Name")
75
76
    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
77
    return await query_request(query_type, OSDU_WELLLOG_KIND, ctx, body)