Skip to content
Merged
6 changes: 3 additions & 3 deletions geoengine/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def to_api_enum(self) -> geoengine_openapi_client.OgrSourceErrorSpec:


class DatasetName:
'''A wrapper for a dataset id'''
'''A wrapper for a dataset name'''

__dataset_name: str

Expand All @@ -266,7 +266,7 @@ def __init__(self, dataset_name: str) -> None:

@classmethod
def from_response(cls, response: geoengine_openapi_client.CreateDatasetHandler200Response) -> DatasetName:
'''Parse a http response to an `DatasetId`'''
'''Parse a http response to an `DatasetName`'''
return DatasetName(response.dataset_name)

def __str__(self) -> str:
Expand All @@ -276,7 +276,7 @@ def __repr__(self) -> str:
return str(self)

def __eq__(self, other) -> bool:
'''Checks if two dataset ids are equal'''
'''Checks if two dataset names are equal'''
if not isinstance(other, self.__class__):
return False

Expand Down
19 changes: 14 additions & 5 deletions geoengine/permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from enum import Enum

import ast
from typing import Dict, Literal, Any
from typing import Dict, Literal, Any, Union
from uuid import UUID

import geoengine_openapi_client
Expand Down Expand Up @@ -82,7 +82,7 @@ def __repr__(self) -> str:
class Resource:
'''A wrapper for a resource id'''

def __init__(self, resource_type: Literal['dataset', 'layer', 'layerCollection'],
def __init__(self, resource_type: Literal['dataset', 'layer', 'layerCollection', 'mlModel'],
resource_id: str) -> None:
'''Create a resource id'''
self.__type = resource_type
Expand All @@ -99,9 +99,16 @@ def from_layer_collection_id(cls, layer_collection_id: LayerCollectionId) -> Res
return Resource('layerCollection', str(layer_collection_id))

@classmethod
def from_dataset_name(cls, dataset_name: DatasetName) -> Resource:
'''Create a resource id from a dataset id'''
return Resource('dataset', str(dataset_name))
def from_dataset_name(cls, dataset_name: Union[DatasetName, str]) -> Resource:
'''Create a resource id from a dataset name'''
if isinstance(dataset_name, DatasetName):
dataset_name = str(dataset_name)
return Resource('dataset', dataset_name)

@classmethod
def from_ml_model_name(cls, ml_model_name: str) -> Resource:
'''Create a resource from an ml model name'''
return Resource('mlModel', ml_model_name)

def to_api_dict(self) -> geoengine_openapi_client.Resource:
'''Convert to a dict for the API'''
Expand All @@ -115,6 +122,8 @@ def to_api_dict(self) -> geoengine_openapi_client.Resource:
inner = geoengine_openapi_client.ProjectResource(type="project", id=self.__id)
elif self.__type == "dataset":
inner = geoengine_openapi_client.DatasetResource(type="dataset", id=self.__id)
elif self.__type == "mlModel":
inner = geoengine_openapi_client.MlModelResource(type="mlModel", id=self.__id)

return geoengine_openapi_client.Resource(inner)

Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ package_dir =
packages = find:
python_requires = >=3.9
install_requires =
geoengine-openapi-client == 0.0.18
geoengine-openapi-client @ git+https://github.com/geo-engine/openapi-client@ml_and_dataset_name_as_resource_name#subdirectory=python
Comment thread
michaelmattig marked this conversation as resolved.
Outdated
geopandas >=0.9,<0.15
matplotlib >=3.5,<3.8
numpy >=1.21,<2
Expand Down