Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Supervision controller and service to be used by supervision tools #407

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package org.gridsuite.study.server;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licence header


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add author

@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<List<SupervisionStudyInfos>> getStudyList() {
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getStudies());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.gridsuite.study.server.dto.supervision;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licence header


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add author

@NoArgsConstructor
@Getter
@ToString(callSuper = true)
@Schema(description = "Supervision Study attributes")
public class SupervisionStudyInfos extends StudyInfos {
private UUID networkUuid;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.gridsuite.study.server.service;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add licence header


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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add author

public class SupervisionService {
private final StudyRepository studyRepository;

public SupervisionService (StudyRepository studyRepository) {
this.studyRepository = studyRepository;
}

public List<SupervisionStudyInfos> getStudies() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add @transactional(readOnly)

return studyRepository.findAll().stream()
.map(SupervisionService::toSupervisionStudyInfos)
.collect(Collectors.toList());
}

private static SupervisionStudyInfos toSupervisionStudyInfos(StudyEntity entity) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

toDto ?

return SupervisionStudyInfos.builder()
.id(entity.getId())
.caseFormat(entity.getCaseFormat())
.networkUuid(entity.getNetworkUuid())
.build();
}

}