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

rename study #24

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
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