Commit 54a422bc authored by fabian serin's avatar fabian serin
Browse files

fixes id with version for welllog, markerset and trajectories

parent 1232cc9f
Pipeline #63455 passed with stages
in 14 minutes and 57 seconds
......@@ -6,8 +6,11 @@ OSDU_WELLBORE_VERSION_REGEX = re.compile(r'^([\w\-\.]+:master-data\-\-Wellbore:[
OSDU_WELLBORE_REGEX = re.compile(r'^[\w\-\.]+:master-data\-\-Wellbore:[\w\-\.\:\%]+$')
OSDU_WELL_VERSION_REGEX = re.compile(r'^([\w\-\.]+:master-data\-\-Well:[\w\-\.\:\%]+):([0-9]*)$')
OSDU_WELL_REGEX = re.compile(r'^[\w\-\.]+:master-data\-\-Well:[\w\-\.\:\%]+$')
DELFI_REGEX = re.compile(r'^[\w\-\.]+:[\w\-\.]+:[\w\-\.]+$')
OSDU_WELLLOG_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellLog:[\w\-\.\:\%]+):([0-9]*)$')
OSDU_WELLBORETRAJECTORY_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellboreTrajectory:[\w\-\.\:\%]+):([0-9]*)$')
OSDU_WELLBOREMARKERSET_VERSION_REGEX = re.compile(r'^([\w\-\.]+:work-product-component\-\-WellboreMarkerSet:[\w\-\.\:\%]+):([0-9]*)$')
DELFI_REGEX = re.compile(r'^[\w\-\.]+:[\w\-\.]+:[\w\-\.]+$')
class DMSV3RouterUtils:
@staticmethod
......@@ -32,6 +35,11 @@ class DMSV3RouterUtils:
return False, None, None
return True, matches.group(1), matches.group(2)
@staticmethod
def get_id_without_version(entity_regexp, entity_id: str) -> str:
is_versioned, id_without_version, _ = DMSV3RouterUtils.is_osdu_versionned_entity_id(entity_regexp, entity_id)
return id_without_version if is_versioned else entity_id
@staticmethod
def is_osdu_versionned_wellbore_id(entity_id: str) -> Tuple[bool, str, str]:
return DMSV3RouterUtils.is_osdu_versionned_entity_id(OSDU_WELLBORE_VERSION_REGEX, entity_id)
......
......@@ -23,13 +23,13 @@ from app.clients.storage_service_client import get_storage_record_service
from app.model.model_utils import to_record, from_record
from app.model.osdu_model import WellboreMarkerSet
from app.routers.common_parameters import REQUIRED_ROLES_READ, REQUIRED_ROLES_WRITE
from app.routers.ddms_v3.ddms_v3_utils import DMSV3RouterUtils, OSDU_WELLBOREMARKERSET_VERSION_REGEX
from app.utils import Context
from app.utils import get_ctx
from app.utils import load_schema_example
router = APIRouter()
@router.get(
"/wellboremarkersets/{wellboremarkersetid}",
response_model=WellboreMarkerSet,
......@@ -45,6 +45,8 @@ async def get_wellbore_markerset_osdu(
wellboremarkersetid: str, ctx: Context = Depends(get_ctx)
) -> WellboreMarkerSet:
storage_client = await get_storage_record_service(ctx)
wellboremarkersetid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBOREMARKERSET_VERSION_REGEX,
wellboremarkersetid)
wellboreMarkerset_record = await storage_client.get_record(
id=wellboremarkersetid, data_partition_id=ctx.partition_id
)
......@@ -68,6 +70,8 @@ async def get_wellbore_markerset_osdu(
)
async def del_osdu_wellboreMarkerset(wellboremarkersetid: str, ctx: Context = Depends(get_ctx)):
storage_client = await get_storage_record_service(ctx)
wellboremarkersetid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBOREMARKERSET_VERSION_REGEX,
wellboremarkersetid)
await storage_client.delete_record(
id=wellboremarkersetid, data_partition_id=ctx.partition_id
)
......@@ -107,6 +111,8 @@ async def get_osdu_wellboreMarkerset_version(
wellboremarkersetid: str, version: int, ctx: Context = Depends(get_ctx)
) -> WellboreMarkerSet:
storage_client = await get_storage_record_service(ctx)
wellboremarkersetid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBOREMARKERSET_VERSION_REGEX,
wellboremarkersetid)
wellboreMarkerset_record = await storage_client.get_record_version(
id=wellboremarkersetid, version=version, data_partition_id=ctx.partition_id
)
......
......@@ -23,6 +23,7 @@ from odes_storage.models import (
from app.clients.storage_service_client import get_storage_record_service
from app.model.osdu_model import WellboreTrajectory110 as WellboreTrajectory
from app.routers.common_parameters import REQUIRED_ROLES_READ, REQUIRED_ROLES_WRITE
from app.routers.ddms_v3.ddms_v3_utils import DMSV3RouterUtils, OSDU_WELLBORETRAJECTORY_VERSION_REGEX
from app.utils import Context
from app.utils import get_ctx
from app.model.model_utils import to_record, from_record
......@@ -47,6 +48,9 @@ async def get_wellbore_trajectory_osdu(
wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)
) -> WellboreTrajectory:
storage_client = await get_storage_record_service(ctx)
wellboretrajectoryid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBORETRAJECTORY_VERSION_REGEX,
wellboretrajectoryid)
wellboreTrajectory_record = await storage_client.get_record(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
)
......@@ -70,6 +74,8 @@ async def get_wellbore_trajectory_osdu(
)
async def del_osdu_wellboreTrajectory(wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)):
storage_client = await get_storage_record_service(ctx)
wellboretrajectoryid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBORETRAJECTORY_VERSION_REGEX,
wellboretrajectoryid)
await storage_client.delete_record(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
)
......@@ -88,6 +94,8 @@ async def del_osdu_wellboreTrajectory(wellboretrajectoryid: str, ctx: Context =
async def get_osdu_wellboreTrajectory_versions(
wellboretrajectoryid: str, ctx: Context = Depends(get_ctx)
) -> RecordVersions:
wellboretrajectoryid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBORETRAJECTORY_VERSION_REGEX,
wellboretrajectoryid)
storage_client = await get_storage_record_service(ctx)
return await storage_client.get_all_record_versions(
id=wellboretrajectoryid, data_partition_id=ctx.partition_id
......@@ -109,6 +117,8 @@ async def get_osdu_wellboreTrajectory_version(
wellboretrajectoryid: str, version: int, ctx: Context = Depends(get_ctx)
) -> WellboreTrajectory:
storage_client = await get_storage_record_service(ctx)
wellboretrajectoryid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLBORETRAJECTORY_VERSION_REGEX,
wellboretrajectoryid)
wellboreTrajectory_record = await storage_client.get_record_version(
id=wellboretrajectoryid, version=version, data_partition_id=ctx.partition_id
)
......
......@@ -27,6 +27,7 @@ from app.model.model_utils import from_record, to_record
from app.model.osdu_model import WellLog110 as WellLog
from app.utils import Context, get_ctx, load_schema_example
from .ddms_v3_utils import DMSV3RouterUtils, OSDU_WELLLOG_VERSION_REGEX
from ..common_parameters import REQUIRED_ROLES_READ, REQUIRED_ROLES_WRITE
......@@ -50,6 +51,8 @@ async def get_welllog_osdu(
welllogid: str, ctx: Context = Depends(get_ctx)
) -> WellLog:
storage_client = await get_storage_record_service(ctx)
welllogid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLLOG_VERSION_REGEX,
welllogid)
welllog_record = await storage_client.get_record(
id=welllogid, data_partition_id=ctx.partition_id
)
......@@ -73,6 +76,8 @@ async def get_welllog_osdu(
)
async def del_osdu_welllog(welllogid: str, ctx: Context = Depends(get_ctx)):
storage_client = await get_storage_record_service(ctx)
welllogid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLLOG_VERSION_REGEX,
welllogid)
await storage_client.delete_record(
id=welllogid, data_partition_id=ctx.partition_id
)
......@@ -92,6 +97,8 @@ async def get_osdu_welllog_versions(
welllogid: str, ctx: Context = Depends(get_ctx)
) -> RecordVersions:
storage_client = await get_storage_record_service(ctx)
welllogid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLLOG_VERSION_REGEX,
welllogid)
return await storage_client.get_all_record_versions(
id=welllogid, data_partition_id=ctx.partition_id
)
......@@ -112,6 +119,8 @@ async def get_osdu_welllog_version(
welllogid: str, version: int, ctx: Context = Depends(get_ctx)
) -> WellLog:
storage_client = await get_storage_record_service(ctx)
welllogid = DMSV3RouterUtils.get_id_without_version(OSDU_WELLLOG_VERSION_REGEX,
welllogid)
welllog_record = await storage_client.get_record_version(
id=welllogid, version=version, data_partition_id=ctx.partition_id
)
......
......@@ -67,8 +67,8 @@ async def query_request_with_spatial_filter(query_type: str, spatial_filter: Spa
query_request=query_request)
def query_spatial_filter_builder(spacial_filter_type: str, latitude1: str = None, longitude1: float = None,
latitude2: str = None, longitude2: float = None, distance: int = None,
def query_spatial_filter_builder(spacial_filter_type: str, latitude1: float = None, longitude1: float = None,
latitude2: float = None, longitude2: float = None, distance: int = None,
points: List[Point] = None, geo_field: str = crs_format):
if spacial_filter_type == "bydistance":
point = Point(latitude=latitude1, longitude=longitude1)
......
# 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.
import pytest
from app.routers.ddms_v3.ddms_v3_utils import DMSV3RouterUtils, OSDU_WELL_VERSION_REGEX, OSDU_WELLBORE_VERSION_REGEX, \
OSDU_WELLLOG_VERSION_REGEX, OSDU_WELLBORETRAJECTORY_VERSION_REGEX, OSDU_WELLBOREMARKERSET_VERSION_REGEX
GET_WO_VERSION_PARAMS = [
(OSDU_WELL_VERSION_REGEX, "", ""),
(OSDU_WELL_VERSION_REGEX, "9nlnBplxN:master-data--Well:g657DSIO", "9nlnBplxN:master-data--Well:g657DSIO"),
(OSDU_WELL_VERSION_REGEX, "9nlnBplxN:master-data--Well:g657DSIO:", "9nlnBplxN:master-data--Well:g657DSIO"),
(OSDU_WELL_VERSION_REGEX, "9nlnBplxN:master-data--Well:g657DSIO:123456", "9nlnBplxN:master-data--Well:g657DSIO"),
(OSDU_WELLBORE_VERSION_REGEX, "", ""),
(OSDU_WELLBORE_VERSION_REGEX, "9nlnBplxN:master-data--Wellbore:g657DSIO", "9nlnBplxN:master-data--Wellbore:g657DSIO"),
(OSDU_WELLBORE_VERSION_REGEX, "9nlnBplxN:master-data--Wellbore:g657DSIO:", "9nlnBplxN:master-data--Wellbore:g657DSIO"),
(OSDU_WELLBORE_VERSION_REGEX, "9nlnBplxN:master-data--Wellbore:g657DSIO:123456", "9nlnBplxN:master-data--Wellbore:g657DSIO"),
(OSDU_WELLLOG_VERSION_REGEX, "", ""),
(OSDU_WELLLOG_VERSION_REGEX, "9nlnBplxN:work-product-component--WellLog:g657DSIO", "9nlnBplxN:work-product-component--WellLog:g657DSIO"),
(OSDU_WELLLOG_VERSION_REGEX, "9nlnBplxN:work-product-component--WellLog:g657DSIO:", "9nlnBplxN:work-product-component--WellLog:g657DSIO"),
(OSDU_WELLLOG_VERSION_REGEX, "9nlnBplxN:work-product-component--WellLog:g657DSIO:123456", "9nlnBplxN:work-product-component--WellLog:g657DSIO"),
(OSDU_WELLBORETRAJECTORY_VERSION_REGEX, "", ""),
(OSDU_WELLBORETRAJECTORY_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO", "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO"),
(OSDU_WELLBORETRAJECTORY_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO:", "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO"),
(OSDU_WELLBORETRAJECTORY_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO:123456", "9nlnBplxN:work-product-component--WellboreTrajectory:g657DSIO"),
(OSDU_WELLBOREMARKERSET_VERSION_REGEX, "", ""),
(OSDU_WELLBOREMARKERSET_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO", "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO"),
(OSDU_WELLBOREMARKERSET_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO:", "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO"),
(OSDU_WELLBOREMARKERSET_VERSION_REGEX, "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO:123456", "9nlnBplxN:work-product-component--WellboreMarkerSet:g657DSIO"),
]
@pytest.mark.parametrize("version_regexp, record_id, expected_id", GET_WO_VERSION_PARAMS)
def test_get_id_without_version(version_regexp, record_id, expected_id):
record_wo_version = DMSV3RouterUtils.get_id_without_version(version_regexp, record_id)
assert record_wo_version == expected_id
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