-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Get or create unique collection #209
Open
jdroenner
wants to merge
7
commits into
main
Choose a base branch
from
get_or_create_unique_collection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+266
−123
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
614a12e
LayerCollection get or create unique collection
jdroenner 27d1cfb
cyclic imports and instances
jdroenner c70d325
resolve dependency circle, add method to get dataset info from server
jdroenner ac66bd5
reorder imports
jdroenner f9fe7e5
add dataset / layers
jdroenner 3ce013a
raster downloader: add bands
jdroenner afbb326
raster writer: skip empty timestaps
jdroenner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
''' Types that identify a ressource in the Geo Engine''' | ||
|
||
from __future__ import annotations | ||
from typing import Any, Literal, NewType | ||
from uuid import UUID | ||
import geoengine_openapi_client | ||
|
||
LayerId = NewType('LayerId', str) | ||
LayerCollectionId = NewType('LayerCollectionId', str) | ||
LayerProviderId = NewType('LayerProviderId', UUID) | ||
|
||
LAYER_DB_PROVIDER_ID = LayerProviderId(UUID('ce5e84db-cbf9-48a2-9a32-d4b7cc56ea74')) | ||
LAYER_DB_ROOT_COLLECTION_ID = LayerCollectionId('05102bb3-a855-4a37-8a8a-30026a91fef1') | ||
|
||
|
||
class DatasetName: | ||
'''A wrapper for a dataset id''' | ||
|
||
__dataset_name: str | ||
|
||
def __init__(self, dataset_name: str) -> None: | ||
self.__dataset_name = dataset_name | ||
|
||
@classmethod | ||
def from_response(cls, response: geoengine_openapi_client.CreateDatasetHandler200Response) -> DatasetName: | ||
'''Parse a http response to an `DatasetId`''' | ||
return DatasetName(response.dataset_name) | ||
|
||
def __str__(self) -> str: | ||
return self.__dataset_name | ||
|
||
def __repr__(self) -> str: | ||
return str(self) | ||
|
||
def __eq__(self, other) -> bool: | ||
'''Checks if two dataset ids are equal''' | ||
if not isinstance(other, self.__class__): | ||
return False | ||
|
||
return self.__dataset_name == other.__dataset_name # pylint: disable=protected-access | ||
|
||
def to_api_dict(self) -> geoengine_openapi_client.CreateDatasetHandler200Response: | ||
return geoengine_openapi_client.CreateDatasetHandler200Response( | ||
dataset_name=str(self.__dataset_name) | ||
) | ||
|
||
|
||
class UploadId: | ||
'''A wrapper for an upload id''' | ||
|
||
__upload_id: UUID | ||
|
||
def __init__(self, upload_id: UUID) -> None: | ||
self.__upload_id = upload_id | ||
|
||
@classmethod | ||
def from_response(cls, response: geoengine_openapi_client.AddCollection200Response) -> UploadId: | ||
'''Parse a http response to an `UploadId`''' | ||
return UploadId(UUID(response.id)) | ||
|
||
def __str__(self) -> str: | ||
return str(self.__upload_id) | ||
|
||
def __repr__(self) -> str: | ||
return str(self) | ||
|
||
def __eq__(self, other) -> bool: | ||
'''Checks if two upload ids are equal''' | ||
if not isinstance(other, self.__class__): | ||
return False | ||
|
||
return self.__upload_id == other.__upload_id # pylint: disable=protected-access | ||
|
||
def to_api_dict(self) -> geoengine_openapi_client.AddCollection200Response: | ||
'''Converts the upload id to a dict for the api''' | ||
return geoengine_openapi_client.AddCollection200Response( | ||
id=str(self.__upload_id) | ||
) | ||
|
||
|
||
class Resource: | ||
'''A wrapper for a resource id''' | ||
|
||
def __init__(self, resource_type: Literal['dataset', 'layer', 'layerCollection'], | ||
resource_id: str) -> None: | ||
'''Create a resource id''' | ||
self.__type = resource_type | ||
self.__id = resource_id | ||
|
||
@classmethod | ||
def from_layer_id(cls, layer_id: LayerId) -> Resource: | ||
'''Create a resource id from a layer id''' | ||
return Resource('layer', str(layer_id)) | ||
|
||
@classmethod | ||
def from_layer_collection_id(cls, layer_collection_id: LayerCollectionId) -> Resource: | ||
'''Create a resource id from a layer collection id''' | ||
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 to_api_dict(self) -> geoengine_openapi_client.Resource: | ||
'''Convert to a dict for the API''' | ||
inner: Any = None | ||
|
||
if self.__type == "layer": | ||
inner = geoengine_openapi_client.LayerResource(type="layer", id=self.__id) | ||
elif self.__type == "layerCollection": | ||
inner = geoengine_openapi_client.LayerCollectionResource(type="layerCollection", id=self.__id) | ||
elif self.__type == "project": | ||
inner = geoengine_openapi_client.ProjectResource(type="project", id=self.__id) | ||
elif self.__type == "dataset": | ||
inner = geoengine_openapi_client.DatasetResource(type="dataset", id=self.__id) | ||
|
||
return geoengine_openapi_client.Resource(inner) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is quite complex. Could you add a test that verifies that it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really don't want to build the mock thingy for that...