Skip to content

Commit 332385e

Browse files
committed
feat: add rename method to v2 assets (Folder, Project, SurfaceMesh, VolumeMesh, Case, etc)
1 parent 1315fb8 commit 332385e

File tree

7 files changed

+142
-5
lines changed

7 files changed

+142
-5
lines changed

flow360/cloud/flow360_requests.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,17 @@ def _validate_force_creation_config(self):
235235

236236

237237
class MoveToFolderRequestV2(Flow360RequestsV2):
238-
"""v2 request implementation for moving folder"""
238+
"""Data model for moving folder using v2 endpoint"""
239239

240240
name: Optional[str] = pd_v2.Field(default=None, description="folder to move name")
241241
tags: Optional[List[str]] = pd_v2.Field(default=[], description="folder tags")
242242
parent_folder_id: str = pd_v2.Field(alias="parentFolderId", default="ROOT.FLOW360")
243+
244+
245+
class RenameAssetRequestV2(Flow360RequestsV2):
246+
"""
247+
Data model for renaming an asset (folder, project, surface mesh, volume mesh,
248+
or case (other request fields, like folder to move to, already have implementations)
249+
"""
250+
251+
name: str = pd_v2.Field(description="case to rename")

flow360/component/case.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
import pydantic.v1 as pd_v1
1515

1616
from .. import error_messages
17-
from ..cloud.flow360_requests import MoveCaseItem, MoveToFolderRequest
17+
from ..cloud.flow360_requests import (
18+
MoveCaseItem,
19+
MoveToFolderRequest,
20+
RenameAssetRequestV2,
21+
)
1822
from ..cloud.rest_api import RestApi
1923
from ..cloud.s3_utils import CloudFileNotFoundError
2024
from ..exceptions import Flow360RuntimeError, Flow360ValidationError, Flow360ValueError
@@ -668,6 +672,25 @@ def move_to_folder(self, folder: Folder):
668672
)
669673
return self
670674

675+
def rename(self, new_name: str):
676+
"""
677+
Rename the current case.
678+
679+
Parameters
680+
----------
681+
new_name : str
682+
The new name for the case.
683+
684+
Returns
685+
-------
686+
self
687+
Returns the modified case after it has been renamed.
688+
"""
689+
RestApi(CaseInterfaceV2.endpoint).patch(
690+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
691+
)
692+
return self
693+
671694
@classmethod
672695
def _interface(cls):
673696
return CaseInterface

flow360/component/geometry.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
GeometryFileMeta,
1616
LengthUnitType,
1717
NewGeometryRequest,
18+
RenameAssetRequestV2,
1819
)
1920
from flow360.cloud.heartbeat import post_upload_heartbeat
2021
from flow360.cloud.rest_api import RestApi
@@ -345,6 +346,25 @@ def from_local_storage(
345346
asset_id=geometry_id, local_storage_path=local_storage_path, meta_data=meta_data
346347
)
347348

349+
def rename(self, new_name: str):
350+
"""
351+
Rename the current (uploaded) geometry.
352+
353+
Parameters
354+
----------
355+
new_name : str
356+
The new name for the geometry.
357+
358+
Returns
359+
-------
360+
self
361+
Returns the modified geometry after it has been renamed.
362+
"""
363+
RestApi(GeometryInterface.endpoint).patch(
364+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
365+
)
366+
return self
367+
348368
def _show_available_entity_groups(
349369
self,
350370
entity_type_name: Literal["faces", "edges", "bodies"],

flow360/component/project.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
from PrettyPrint import PrettyPrintTree
1515
from pydantic import PositiveInt
1616

17-
from flow360.cloud.flow360_requests import LengthUnitType
17+
from flow360.cloud.flow360_requests import LengthUnitType, RenameAssetRequestV2
1818
from flow360.cloud.rest_api import RestApi
1919
from flow360.component.case import Case
2020
from flow360.component.geometry import Geometry
@@ -1197,6 +1197,25 @@ def refresh_project_tree(self):
11971197
"""Refresh the local project tree by fetching the latest project tree from cloud."""
11981198
return self._get_tree_from_cloud()
11991199

1200+
def rename(self, new_name: str):
1201+
"""
1202+
Rename the current project.
1203+
1204+
Parameters
1205+
----------
1206+
new_name : str
1207+
The new name for the project.
1208+
1209+
Returns
1210+
-------
1211+
self
1212+
Returns the modified project after it has been renamed.
1213+
"""
1214+
RestApi(ProjectInterface.endpoint).patch(
1215+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
1216+
)
1217+
return self
1218+
12001219
def print_project_tree(self, line_width: int = 30, is_horizontal: bool = True):
12011220
"""Print the project tree to the terminal.
12021221

flow360/component/simulation/folder.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010

1111
import pydantic.v1 as pd
1212

13-
from ...cloud.flow360_requests import MoveToFolderRequestV2, NewFolderRequest
13+
from ...cloud.flow360_requests import (
14+
MoveToFolderRequestV2,
15+
NewFolderRequest,
16+
RenameAssetRequestV2,
17+
)
1418
from ...cloud.rest_api import RestApi
1519
from ...exceptions import Flow360ValueError
1620
from ...log import log
@@ -134,6 +138,25 @@ def move_to_folder(self, folder: Folder):
134138
)
135139
return self
136140

141+
def rename(self, new_name: str):
142+
"""
143+
Rename the current folder.
144+
145+
Parameters
146+
----------
147+
new_name : str
148+
The new name for the folder.
149+
150+
Returns
151+
-------
152+
self
153+
Returns the modified folder after it has been renamed.
154+
"""
155+
RestApi(FolderInterfaceV2.endpoint).patch(
156+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
157+
)
158+
return self
159+
137160
@classmethod
138161
def _interface(cls):
139162
return FolderInterface

flow360/component/surface_mesh_v2.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@
1111

1212
import pydantic as pd
1313

14-
from flow360.cloud.flow360_requests import LengthUnitType, NewSurfaceMeshRequestV2
14+
from flow360.cloud.flow360_requests import (
15+
LengthUnitType,
16+
NewSurfaceMeshRequestV2,
17+
RenameAssetRequestV2,
18+
)
1519
from flow360.cloud.heartbeat import post_upload_heartbeat
1620
from flow360.cloud.rest_api import RestApi
1721
from flow360.component.interfaces import SurfaceMeshInterfaceV2
@@ -316,6 +320,25 @@ def get_default_settings(self, simulation_dict: dict):
316320
"""Get the default surface mesh settings from the simulation dict"""
317321
return super().get_default_settings(simulation_dict)
318322

323+
def rename(self, new_name: str):
324+
"""
325+
Rename the current surface mesh.
326+
327+
Parameters
328+
----------
329+
new_name : str
330+
The new name for the surface mesh.
331+
332+
Returns
333+
-------
334+
self
335+
Returns the modified surface mesh after it has been renamed.
336+
"""
337+
RestApi(SurfaceMeshInterfaceV2.endpoint).patch(
338+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
339+
)
340+
return self
341+
319342
@property
320343
def boundary_names(self) -> List[str]:
321344
"""

flow360/component/volume_mesh.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
CopyExampleVolumeMeshRequest,
2626
LengthUnitType,
2727
NewVolumeMeshRequestV2,
28+
RenameAssetRequestV2,
2829
)
2930
from flow360.cloud.heartbeat import post_upload_heartbeat
3031
from flow360.cloud.rest_api import RestApi
@@ -1179,6 +1180,25 @@ def get_default_settings(self, simulation_dict: dict):
11791180
"""Get the default volume mesh settings from the simulation dict"""
11801181
return super().get_default_settings(simulation_dict)
11811182

1183+
def rename(self, new_name: str):
1184+
"""
1185+
Rename the current volume mesh.
1186+
1187+
Parameters
1188+
----------
1189+
new_name : str
1190+
The new name for the volume mesh.
1191+
1192+
Returns
1193+
-------
1194+
self
1195+
Returns the modified volume mesh after it has been renamed.
1196+
"""
1197+
RestApi(VolumeMeshInterfaceV2.endpoint).patch(
1198+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
1199+
)
1200+
return self
1201+
11821202
@cached_property
11831203
def stats(self) -> VolumeMeshStats:
11841204
"""

0 commit comments

Comments
 (0)