Commit 1c5f26ff authored by fabian serin's avatar fabian serin
Browse files

CRUD API and unit/e2e tests for osdu wellbore trajectory meta

parent 6bec4cfa
Pipeline #37753 failed with stages
in 1 minute and 18 seconds
# 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, Response, status, Body
from app.clients.storage_service_client import get_storage_record_service
from odes_storage.models import (
CreateUpdateRecordsResponse,
List,
RecordVersions,
)
from app.model.osdu_model import WellboreTrajectory
from app.routers.conf import REQUIRED_ROLES_READ, REQUIRED_ROLES_WRITE
from app.utils import Context
from app.utils import get_ctx
from app.utils import load_schema_example
from app.model.model_utils import to_record, from_record
router = APIRouter()
@router.get(
"/wellboretrajectories/{wellboretrajectoryid}",
response_model=WellboreTrajectory,
response_model_exclude_unset=True,
summary="Get the WellboreTrajectory using osdu schema",
description="""Get the WellboreTrajectory object using its **id**. {}""".format(REQUIRED_ROLES_READ),
operation_id="get_wellbore_trajectory_osdu",
responses={
status.HTTP_404_NOT_FOUND: {"description": "Wellbore Trajectory not found"}
},
)
async def get_wellbore_trajectory_osdu(
wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)
) -> WellboreTrajectory:
storage_client = await get_storage_record_service(ctx)
wellboreTrajectory_record = await storage_client.get_record(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
)
return from_record(WellboreTrajectory, wellboreTrajectory_record)
@router.delete(
"/wellboretrajectories/{wellboretrajectoryid}",
summary="Delete the wellboreTrajectory. The API performs a logical deletion of the given record. "
"No recursive delete for OSDU kinds",
description="{}".format(REQUIRED_ROLES_WRITE),
operation_id="del_osdu_wellboreTrajectory",
status_code=status.HTTP_204_NO_CONTENT,
response_class=Response,
responses={
status.HTTP_404_NOT_FOUND: {"description": "WellboreTrajectory not found"},
status.HTTP_204_NO_CONTENT: {
"description": "Record deleted successfully"
},
},
)
async def del_osdu_wellboreTrajectory(wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)):
storage_client = await get_storage_record_service(ctx)
await storage_client.delete_record(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
)
@router.get(
"/wellboretrajectories/{wellboretrajectoryid}/versions",
response_model=RecordVersions,
summary="Get all versions of the WellboreTrajectory",
description="{}".format(REQUIRED_ROLES_READ),
operation_id="get_osdu_wellboreTrajectory_versions",
responses={
status.HTTP_404_NOT_FOUND: {"description": "WellboreTrajectory not found"}
},
)
async def get_osdu_wellboreTrajectory_versions(
wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)
) -> RecordVersions:
storage_client = await get_storage_record_service(ctx)
return await storage_client.get_all_record_versions(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
)
@router.get(
"/wellboretrajectories/{wellboretrajectoryid}/versions/{version}",
response_model=WellboreTrajectory,
summary="Get the given version of the WellboreTrajectory using OSDU wellboreTrajectory schema",
description=""""Get the WellboreTrajectory object using its **id**. {}""".format(REQUIRED_ROLES_READ),
operation_id="get_osdu_wellboreTrajectory_version",
responses={
status.HTTP_404_NOT_FOUND: {"description": "WellboreTrajectory not found"}
},
response_model_exclude_unset=True,
)
async def get_osdu_wellboreTrajectory_version(
wellboretrajectoryid: str, version: int, ctx: Context = Depends(get_ctx)
) -> WellboreTrajectory:
storage_client = await get_storage_record_service(ctx)
wellboreTrajectory_record = await storage_client.get_record_version(
id=wellboretrajectoryid, version=version, data_partition_id=ctx.partition_id
)
return from_record(WellboreTrajectory, wellboreTrajectory_record)
@router.post(
"/wellboretrajectories",
response_model=CreateUpdateRecordsResponse,
summary="Create or update the WellboreTrajectories using osdu schema",
description="{}".format(REQUIRED_ROLES_WRITE),
operation_id="post_wellboreTrajectory_osdu",
responses={
status.HTTP_400_BAD_REQUEST: {
"description": "Missing mandatory parameter or unknown parameter"
}
},
)
async def post_wellboreTrajectory_osdu(
wellboretrajectories: List[WellboreTrajectory]= Body(..., example= load_schema_example("wellLog_v3.json")), ctx: Context = Depends(get_ctx)
) -> CreateUpdateRecordsResponse:
storage_client = await get_storage_record_service(ctx)
return await storage_client.create_or_update_records(
record=[to_record(w) for w in wellboretrajectories],
data_partition_id=ctx.partition_id,
)
......@@ -46,15 +46,6 @@ router = APIRouter()
async def get_welllog_osdu(
welllogid: str, ctx: Context = Depends(get_ctx)
) -> WellLog:
"""
Regarding to the storage those fields are not stored and will be lost/not
retrieved:
- tags
- createTime
- createUser
- modifyTime
- modifyUser
"""
storage_client = await get_storage_record_service(ctx)
welllog_record = await storage_client.get_record(
id=welllogid, data_partition_id=ctx.partition_id
......
......@@ -34,7 +34,7 @@ from app.routers.ddms_v2 import (
log_ddms_v2,
well_ddms_v2
)
from app.routers.ddms_v3 import wellbore_ddms_v3, well_ddms_v3, welllog_ddms_v3
from app.routers.ddms_v3 import wellbore_ddms_v3, well_ddms_v3, welllog_ddms_v3, wellbore_trajectory_ddms_v3
from app.routers.trajectory import trajectory_ddms_v2
from app.routers.dipset import dipset_ddms_v2, dip_ddms_v2
from app.routers.logrecognition import log_recognition
......@@ -136,6 +136,7 @@ ddms_v3_routes_groups = [
(wellbore_ddms_v3, "Wellbore"),
(well_ddms_v3, "Well"),
(welllog_ddms_v3, "WellLog"),
(wellbore_trajectory_ddms_v3, "Trajectory")
]
for ddms_v3_routes_group in ddms_v3_routes_groups:
wdms_app.include_router(ddms_v3_routes_group[0].router,
......
......@@ -76,6 +76,16 @@ def build_request(path: Union[str, List[str]], sep: str = ".") -> "RequestRunner
return crud.osdu_welllog.build_request_get_versions_of_osdu_welllog()
if n_path == "crud.osdu_welllog.create_osdu_welllog":
return crud.osdu_welllog.build_request_create_osdu_welllog()
if n_path == "crud.osdu_wellboretrajectory.delete_osdu_wellboretrajectory":
return crud.osdu_wellboretrajectory.build_request_delete_osdu_wellboretrajectory()
if n_path == "crud.osdu_wellboretrajectory.get_osdu_wellboretrajectory_specific_version":
return crud.osdu_wellboretrajectory.build_request_get_osdu_wellboretrajectory_specific_version()
if n_path == "crud.osdu_wellboretrajectory.get_osdu_wellboretrajectory":
return crud.osdu_wellboretrajectory.build_request_get_osdu_wellboretrajectory()
if n_path == "crud.osdu_wellboretrajectory.get_versions_of_osdu_wellboretrajectory":
return crud.osdu_wellboretrajectory.build_request_get_versions_of_osdu_wellboretrajectory()
if n_path == "crud.osdu_wellboretrajectory.create_osdu_wellboretrajectory":
return crud.osdu_wellboretrajectory.build_request_create_osdu_wellboretrajectory()
if n_path == "crud.logset.get_versions_of_logset":
return crud.logset.build_request_get_versions_of_logset()
if n_path == "crud.logset.get_logset_specific_version":
......@@ -221,3 +231,5 @@ def get_cleaned_ref_and_res(kind: str, res_dict: dict) -> (dict, dict):
return crud.osdu_well.get_cleaned_ref_and_res(res_dict)
if kind =="osdu_welllog":
return crud.osdu_welllog.get_cleaned_ref_and_res(res_dict)
if kind =="osdu_wellboretrajectory":
return crud.osdu_wellboretrajectory.get_cleaned_ref_and_res(res_dict)
from ..crud import well, wellbore, logset, marker, trajectory, log, dips, osdu_wellbore, osdu_well, osdu_welllog
from ..crud import well, wellbore, logset, marker, trajectory, log, dips, osdu_wellbore, osdu_well, osdu_welllog, \
osdu_wellboretrajectory
__all__ = ["well", "wellbore", "logset", "marker", "trajectory", "log", "dips", "osdu_wellbore", "osdu_well",
"osdu_welllog"]
"osdu_welllog", "osdu_wellboretrajectory"]
......@@ -30,6 +30,7 @@ variables_dict = {
"osduWellboreKind": "{{data_partition}}:wks:master-data--Wellbore:1.0.0",
"osduWellKind": "{{data_partition}}:wks:master-data--Well:1.0.0",
"osduWellLogKind": "{{data_partition}}:wks:work-product-component--WellLog:1.0.0",
"osduWellboreTrajectoryKind": "{{data_partition}}:wks:work-product-component--WellboreTrajectory:1.0.0",
"acl_domain": "p4d.cloud.slb-ds.com",
"acl_owner": "data.default.owners@{{data_partition}}.{{acl_domain}}",
"acl_viewer": "data.default.viewers@{{data_partition}}.{{acl_domain}}",
......
......@@ -17,7 +17,7 @@ from .fixtures import with_wdms_env
from ..request_builders import build_request, get_cleaned_ref_and_res
kind_list = ['osdu_wellbore', 'osdu_well', 'osdu_welllog']
kind_list = ['osdu_wellbore', 'osdu_well', 'osdu_welllog', 'osdu_wellboretrajectory']
# parametrize of kind + dependency on the create_record
param_kind_depend_on_create = [
......
......@@ -28,7 +28,7 @@ from app.helper import traces
from app.middleware import require_data_partition_id
from app.model.entity_utils import Entity
from app.model.model_curated import *
from app.model.osdu_model import Wellbore, Well, WellLog
from app.model.osdu_model import Wellbore, Well, WellLog, WellboreTrajectory
from app.routers.ddms_v2.storage_helper import StorageHelper
from app.routers.search.search_wrapper import SearchWrapper
from app.utils import Context
......@@ -81,6 +81,21 @@ tests_parameters = [
},
data={},
)),
('/ddms/v3/wellboretrajectories', WellboreTrajectory(
id=r"namespace:work-product-component--WellboreTrajectory:c7c421a7-f496-5aef-8093-298c32bfdea9",
kind="namespace:osdu:WellboreTrajectory:2.7.112",
acl={"owners": ["me@osdu.org"], "viewers": ["ze@osdu.org"]},
legal={
"legaltags": ["string"],
"otherRelevantDataCountries": ["FR"],
},
data={
"WellboreID": r"namespace:master-data--Wellbore:c7c421a7-f496-5aef-8093-298c32bfdea9:456",
"TopDepthMeasuredDepth": 12.3,
"BaseDepthMeasuredDepth": 11.3,
"VerticalMeasurement": {}
},
))
]
tests_errors_422 = [
......
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