From d97a006227c765f35e133d258076d9d935e69ba3 Mon Sep 17 00:00:00 2001 From: Yohann Paris Date: Wed, 11 Dec 2024 08:54:58 -0500 Subject: [PATCH] Update NotebookSessionController.java (#5796) --- .../NotebookSessionController.java | 32 +++++++++---------- .../src/main/resources/messages.properties | 2 ++ 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/NotebookSessionController.java b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/NotebookSessionController.java index 1e39498e7e..7974c3d36a 100644 --- a/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/NotebookSessionController.java +++ b/packages/server/src/main/java/software/uncharted/terarium/hmiserver/controller/dataservice/NotebookSessionController.java @@ -33,6 +33,7 @@ import software.uncharted.terarium.hmiserver.service.data.NotebookSessionService; import software.uncharted.terarium.hmiserver.service.data.ProjectAssetService; import software.uncharted.terarium.hmiserver.service.data.ProjectService; +import software.uncharted.terarium.hmiserver.utils.Messages; import software.uncharted.terarium.hmiserver.utils.rebac.Schema; /** Rest controller for storing, retrieving, modifying and deleting notebook sessions in the dataservice */ @@ -43,7 +44,7 @@ public class NotebookSessionController { final NotebookSessionService sessionService; - + private final Messages messages; private final ProjectService projectService; private final ProjectAssetService projectAssetService; private final CurrentUserService currentUserService; @@ -249,27 +250,26 @@ ResponseEntity cloneNotebookSession( currentUserService.get().getId(), projectId ); - try { - final Optional session = sessionService.getAsset(id, permission); - if (session.isEmpty()) { - return ResponseEntity.notFound().build(); - } - final NotebookSession newNotebookSession = sessionService.createAsset( - session.get().clone(), - projectId, - permission - ); - - final Optional project = projectService.getProject(projectId); + final NotebookSession session = sessionService + .getAsset(id, permission) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("notebook-session.not-found"))); - projectAssetService.createProjectAsset(project.get(), AssetType.NOTEBOOK_SESSION, newNotebookSession, permission); - - return ResponseEntity.status(HttpStatus.OK).body(newNotebookSession); + NotebookSession newNotebookSession; + try { + newNotebookSession = sessionService.createAsset(session.clone(), projectId, permission); } catch (final Exception e) { final String error = "Unable to clone notebook session"; log.error(error, e); throw new ResponseStatusException(org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR, error); } + + final Project project = projectService + .getProject(projectId) + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, messages.get("projects.not-found"))); + + projectAssetService.createProjectAsset(project, AssetType.NOTEBOOK_SESSION, newNotebookSession, permission); + + return ResponseEntity.status(HttpStatus.OK).body(newNotebookSession); } /** diff --git a/packages/server/src/main/resources/messages.properties b/packages/server/src/main/resources/messages.properties index df35022021..9c496adb8b 100644 --- a/packages/server/src/main/resources/messages.properties +++ b/packages/server/src/main/resources/messages.properties @@ -54,6 +54,8 @@ modelconfig.unable-to-zip = We couldn't package your model config for export. Pl modelconfig.upload-content-missing = We couldn't import the provided model configuration. One or more parts of the file may be missing. Please try exporting and reimporting again modelconfig.upload-content-damaged = We couldn't import the provided model configuration. One or more parts of the file may be damaged. Please try exporting and reimporting again +notebook-session.not-found = We couldn't find the requested Notebook Session. Please verify that the notebook session you selected is correct or contact support. + postgres.service-unavailable = Our data storage is temporarily unavailable. Please try again later. projects.asset-already-added = A resource with the same ID already exists in another project. If this problem continues, please contact support.