From ea74d631991ab12ad26936c5c94599f4fc8e90d1 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Wed, 12 Jul 2023 10:04:58 +0200 Subject: [PATCH 1/2] feat: supervision controller and service to be used by supervision tools Signed-off-by: LE SAULNIER Kevin --- .../study/server/SupervisionController.java | 35 +++++++++++++++++++ .../supervision/SupervisionStudyInfos.java | 19 ++++++++++ .../server/service/SupervisionService.java | 34 ++++++++++++++++++ 3 files changed, 88 insertions(+) create mode 100644 src/main/java/org/gridsuite/study/server/SupervisionController.java create mode 100644 src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java create mode 100644 src/main/java/org/gridsuite/study/server/service/SupervisionService.java diff --git a/src/main/java/org/gridsuite/study/server/SupervisionController.java b/src/main/java/org/gridsuite/study/server/SupervisionController.java new file mode 100644 index 000000000..de9673958 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/SupervisionController.java @@ -0,0 +1,35 @@ +package org.gridsuite.study.server; + +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; +import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; +import org.gridsuite.study.server.service.StudyService; +import org.gridsuite.study.server.service.SupervisionService; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +import java.util.List; + +@RestController +@RequestMapping(value = "/" + StudyApi.API_VERSION + "/supervision") +@Tag(name = "Study server - Supervision") +public class SupervisionController { + private final SupervisionService supervisionService; + + public SupervisionController(SupervisionService supervisionService) { + this.supervisionService = supervisionService; + } + + @GetMapping(value = "/studies") + @Operation(summary = "Get all studies") + @ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The list of studies")}) + public ResponseEntity> getStudyList() { + return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getStudies()); + } +} diff --git a/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java b/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java new file mode 100644 index 000000000..e3296d0eb --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/dto/supervision/SupervisionStudyInfos.java @@ -0,0 +1,19 @@ +package org.gridsuite.study.server.dto.supervision; + +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.ToString; +import lombok.experimental.SuperBuilder; +import org.gridsuite.study.server.dto.StudyInfos; + +import java.util.UUID; + +@SuperBuilder +@NoArgsConstructor +@Getter +@ToString(callSuper = true) +@Schema(description = "Supervision Study attributes") +public class SupervisionStudyInfos extends StudyInfos { + private UUID networkUuid; +} diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java new file mode 100644 index 000000000..8d9abc9e4 --- /dev/null +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -0,0 +1,34 @@ +package org.gridsuite.study.server.service; + +import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; +import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; +import org.gridsuite.study.server.repository.StudyEntity; +import org.gridsuite.study.server.repository.StudyRepository; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +public class SupervisionService { + private final StudyRepository studyRepository; + + public SupervisionService (StudyRepository studyRepository) { + this.studyRepository = studyRepository; + } + + public List getStudies() { + return studyRepository.findAll().stream() + .map(SupervisionService::toSupervisionStudyInfos) + .collect(Collectors.toList()); + } + + private static SupervisionStudyInfos toSupervisionStudyInfos(StudyEntity entity) { + return SupervisionStudyInfos.builder() + .id(entity.getId()) + .caseFormat(entity.getCaseFormat()) + .networkUuid(entity.getNetworkUuid()) + .build(); + } + +} From e98b51e99b12cdeb925d3fa897f05aa266606e0f Mon Sep 17 00:00:00 2001 From: Slimane AMAR Date: Wed, 2 Aug 2023 17:49:56 +0200 Subject: [PATCH 2/2] Code cleanup Signed-off-by: Slimane AMAR --- .../java/org/gridsuite/study/server/SupervisionController.java | 2 -- .../org/gridsuite/study/server/service/SupervisionService.java | 3 +-- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/SupervisionController.java b/src/main/java/org/gridsuite/study/server/SupervisionController.java index de9673958..1b4a986a7 100644 --- a/src/main/java/org/gridsuite/study/server/SupervisionController.java +++ b/src/main/java/org/gridsuite/study/server/SupervisionController.java @@ -4,9 +4,7 @@ import io.swagger.v3.oas.annotations.responses.ApiResponse; import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; -import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; -import org.gridsuite.study.server.service.StudyService; import org.gridsuite.study.server.service.SupervisionService; import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; diff --git a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java index 8d9abc9e4..8149b7da6 100644 --- a/src/main/java/org/gridsuite/study/server/service/SupervisionService.java +++ b/src/main/java/org/gridsuite/study/server/service/SupervisionService.java @@ -1,6 +1,5 @@ package org.gridsuite.study.server.service; -import org.gridsuite.study.server.dto.CreatedStudyBasicInfos; import org.gridsuite.study.server.dto.supervision.SupervisionStudyInfos; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.StudyRepository; @@ -13,7 +12,7 @@ public class SupervisionService { private final StudyRepository studyRepository; - public SupervisionService (StudyRepository studyRepository) { + public SupervisionService(StudyRepository studyRepository) { this.studyRepository = studyRepository; }