Skip to content

Commit

Permalink
Update NotebookSessionController.java (#5796)
Browse files Browse the repository at this point in the history
  • Loading branch information
YohannParis authored Dec 11, 2024
1 parent 51f6876 commit d97a006
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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;
Expand Down Expand Up @@ -249,27 +250,26 @@ ResponseEntity<NotebookSession> cloneNotebookSession(
currentUserService.get().getId(),
projectId
);
try {
final Optional<NotebookSession> 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> 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);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions packages/server/src/main/resources/messages.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit d97a006

Please sign in to comment.