Skip to content

Commit

Permalink
Merge pull request #24 from AntaresSimulatorTeam/fix/ANT-2686_rename_…
Browse files Browse the repository at this point in the history
…study

rename study
  • Loading branch information
vargastat authored Feb 4, 2025
2 parents 164aa55 + 7b52d13 commit e36c900
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;

import java.time.LocalDateTime;
Expand Down Expand Up @@ -90,7 +91,11 @@ public void deleteStudyById(Integer id) {

@Override
public StudyDTO createStudy(StudyDTO studyDTO) {
String studyName = studyDTO.getName() + "-" + studyDTO.getHorizon() + "_REF";
Assert.notNull(studyDTO.getName(), "Study name must be provided.");
Assert.notNull(studyDTO.getProject(), "Project name must be provided.");
Assert.notNull(studyDTO.getHorizon(), "Horizon year must be provided.");

String studyName = studyDTO.getName() + "-" + (Integer.parseInt(studyDTO.getHorizon()) + 1) + "_REF";
studyDTO.setName(studyName);
if (studyDTO.getProject() == null || studyDTO.getProject().isEmpty()) {
throw new BadRequestException("Project name must be provided.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,9 @@ void createStudyUsesExistingProjectWhenProjectExists() {

@Test
void createStudyThrowsBadRequestWhenNoProjectNameProvided() {
StudyDTO studyDTO = StudyDTO.builder().name("Study 1").createdBy("User 1").build();
StudyDTO studyDTO = StudyDTO.builder().name("Study 1").createdBy("User 1").horizon("2021").build();

BadRequestException exception = assertThrows(BadRequestException.class, () -> {
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> {
studyServiceImpl.createStudy(studyDTO);
});

Expand Down

0 comments on commit e36c900

Please sign in to comment.