Skip to content

Commit 7c2df18

Browse files
feat: add rename method to v2 assets (#1333) + feat: add tags filtering to Project.get_case_ids, Project.get_project_ids, and metadata (#1346)
* feat: Migrate Folder class to v2 API (#1317) * [FXC-2051] Removed unsteady initial_blade_direction check and also removed comments in v1 json (#1310) (#1312) * bug(): Removed duplicate pressure output when pressure is specified (#1309) * feat: migrate Folder class to v2 API endpoints * remove unused v1 import, run styling + lint checks * rerun isort + lint * disable pylint duplicate code * fix example files * delete test_folder_tree.py * delete examples, remove comments, update pydantic * fix: run linting + formatting --------- Co-authored-by: Ben <106089368+benflexcompute@users.noreply.github.com> * feat: Add folder parameter to project creation (#1325) * feat: add rename method to v2 assets (#1333) * feat: add rename method to v2 assets (Folder, Project, SurfaceMesh, VolumeMesh, Case, etc) * fix: raise rename method to AssetBase class * fix: remove self return after renaming asset * fix: remove return docstring + missed self returns * feat: add tags filtering to Project.get_case_ids, Project.get_project_ids, and metadata (#1341) * feat: add tag filtering support to Project class + metadata and class property, get_case_ids/get_project_ids methods 499f63b * fix: remove unused imports + dangerous default value * feat: add property tags to AssetBase --------- Co-authored-by: dawood <mrblackcto@outlook.com>
1 parent 25706ce commit 7c2df18

File tree

12 files changed

+990
-23
lines changed

12 files changed

+990
-23
lines changed

examples/workflow_management/folder/examples.ipynb

Lines changed: 429 additions & 0 deletions
Large diffs are not rendered by default.

flow360/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from flow360.component.project import Project
1010
from flow360.component.simulation import migration, services
1111
from flow360.component.simulation import units as u
12+
from flow360.component.simulation.folder import Folder
1213
from flow360.component.simulation.meshing_param.edge_params import (
1314
AngleBasedRefinement,
1415
AspectRatioBasedRefinement,
@@ -238,6 +239,7 @@
238239
"DetachedEddySimulation",
239240
"KOmegaSSTModelConstants",
240241
"LinearSolver",
242+
"Folder",
241243
"ForcePerArea",
242244
"Air",
243245
"Sutherland",

flow360/cloud/flow360_requests.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,3 +232,20 @@ def _validate_force_creation_config(self):
232232
f"cannot be later than 'up_to' ({self.up_to})."
233233
)
234234
return self
235+
236+
237+
class MoveToFolderRequestV2(Flow360RequestsV2):
238+
"""Data model for moving folder using v2 endpoint"""
239+
240+
name: Optional[str] = pd_v2.Field(default=None, description="folder to move name")
241+
tags: List[str] = pd_v2.Field(default=[], description="folder tags")
242+
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: 32 additions & 2 deletions
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
@@ -178,7 +182,6 @@ class CaseMetaV2(AssetMetaBaseModelV2):
178182
"""
179183

180184
id: str = pd.Field(alias="caseId")
181-
case_mesh_id: str = pd.Field(alias="caseMeshId")
182185
status: Flow360Status = pd.Field()
183186

184187
def to_case(self) -> Case:
@@ -542,6 +545,13 @@ def info(self) -> CaseMetaV2:
542545
"""
543546
return super().info
544547

548+
@property
549+
def info_v2(self) -> CaseMetaV2:
550+
"""
551+
returns metadata v2 info for case
552+
"""
553+
return self._web_api_v2.info
554+
545555
@property
546556
def project_id(self) -> Optional[str]:
547557
"""Returns the project id of the case if case was run with V2 interface."""
@@ -551,6 +561,13 @@ def project_id(self) -> Optional[str]:
551561
return self.info.project_id
552562
raise ValueError("Case info is not of type CaseMeta or CaseMetaV2")
553563

564+
@property
565+
def tags(self) -> List[str]:
566+
"""
567+
get case tags
568+
"""
569+
return self._web_api_v2.info.tags
570+
554571
@property
555572
def volume_mesh(self) -> "VolumeMeshV2":
556573
"""
@@ -668,6 +685,19 @@ def move_to_folder(self, folder: Folder):
668685
)
669686
return self
670687

688+
def rename(self, new_name: str):
689+
"""
690+
Rename the current case.
691+
692+
Parameters
693+
----------
694+
new_name : str
695+
The new name for the case.
696+
"""
697+
RestApi(CaseInterfaceV2.endpoint).patch(
698+
RenameAssetRequestV2(name=new_name).dict(), method=self.id
699+
)
700+
671701
@classmethod
672702
def _interface(cls):
673703
return CaseInterface

flow360/component/geometry.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import os
88
import threading
99
from enum import Enum
10-
from typing import Any, List, Literal, Union
10+
from typing import Any, List, Literal, Optional, Union
1111

1212
import pydantic as pd
1313

@@ -25,6 +25,7 @@
2525
ResourceDraft,
2626
)
2727
from flow360.component.simulation.entity_info import GeometryEntityInfo
28+
from flow360.component.simulation.folder import Folder
2829
from flow360.component.simulation.primitives import Edge, GeometryBodyGroup, Surface
2930
from flow360.component.simulation.unit_system import LengthType
3031
from flow360.component.simulation.utils import model_attribute_unlock
@@ -91,12 +92,14 @@ def __init__(
9192
solver_version: str = None,
9293
length_unit: LengthUnitType = "m",
9394
tags: List[str] = None,
95+
folder: Optional[Folder] = None,
9496
):
9597
self._file_names = file_names
9698
self.project_name = project_name
9799
self.tags = tags if tags is not None else []
98100
self.length_unit = length_unit
99101
self.solver_version = solver_version
102+
self.folder = folder
100103
self._validate()
101104
ResourceDraft.__init__(self)
102105

@@ -186,9 +189,7 @@ def submit(self, description="", progress_callback=None, run_async=False) -> Geo
186189
)
187190
for file_path in self.file_names + mapbc_files
188191
],
189-
# pylint: disable=fixme
190-
# TODO: remove hardcoding
191-
parent_folder_id="ROOT.FLOW360",
192+
parent_folder_id=self.folder.id if self.folder else "ROOT.FLOW360",
192193
length_unit=self.length_unit,
193194
description=description,
194195
)
@@ -296,9 +297,12 @@ def from_file(
296297
solver_version: str = None,
297298
length_unit: LengthUnitType = "m",
298299
tags: List[str] = None,
300+
folder: Optional[Folder] = None,
299301
) -> GeometryDraft:
300302
# For type hint only but proper fix is to fully abstract the Draft class too.
301-
return super().from_file(file_names, project_name, solver_version, length_unit, tags)
303+
return super().from_file(
304+
file_names, project_name, solver_version, length_unit, tags, folder=folder
305+
)
302306

303307
def show_available_groupings(self, verbose_mode: bool = False):
304308
"""Display all the possible groupings for faces and edges"""

flow360/component/interfaces.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ class BaseInterface(BaseModel):
6868

6969
FolderInterface = BaseInterface(resource_type="Folder", s3_transfer_method=None, endpoint="folders")
7070

71+
FolderInterfaceV2 = BaseInterface(
72+
resource_type="Folder", s3_transfer_method=None, endpoint="v2/folders"
73+
)
74+
7175
ReportInterface = BaseInterface(
7276
resource_type="Report",
7377
s3_transfer_method=S3TransferType.REPORT,

0 commit comments

Comments
 (0)