Make exemptions for project type apply to partner as well #128
core/src
main/java/se/su/dsv/scipro/match
test/java/se/su/dsv/scipro/match
test-data/src/main/java/se/su/dsv/scipro/testdata
@ -235,10 +235,8 @@ public class IdeaServiceImpl extends AbstractServiceImpl<Idea, Long> implements
|
||||
if (authorParticipatingOnActiveIdea(coAuthor, ap)) {
|
||||
return new Pair<>(Boolean.FALSE, PARTNER_ALREADY_PARTICIPATING_ERROR);
|
||||
}
|
||||
if (
|
||||
coAuthor.getDegreeType() != ProjectType.UNKNOWN &&
|
||||
coAuthor.getDegreeType() != idea.getProjectType().getDegreeType()
|
||||
) {
|
||||
List<ProjectType> typesForCoAuthor = applicationPeriodService.getTypesForStudent(ap, coAuthor);
|
||||
if (!typesForCoAuthor.contains(idea.getProjectType())) {
|
||||
return new Pair<>(Boolean.FALSE, WRONG_LEVEL_FOR_YOUR_PARTNER);
|
||||
}
|
||||
if (!projectService.getActiveProjectsByUserAndProjectType(coAuthor, idea.getProjectType()).isEmpty()) {
|
||||
|
@ -241,6 +241,7 @@ public class IdeaServiceImplTest {
|
||||
when(generalSystemSettingsService.getGeneralSystemSettingsInstance()).thenReturn(new GeneralSystemSettings());
|
||||
Idea idea = createBachelorIdea(Idea.Status.UNMATCHED);
|
||||
when(applicationPeriodService.getTypesForStudent(applicationPeriod, student)).thenReturn(List.of(bachelor));
|
||||
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(bachelor));
|
||||
|
||||
Pair<Boolean, String> acceptance = ideaService.validateStudentAcceptance(
|
||||
idea,
|
||||
@ -401,6 +402,39 @@ public class IdeaServiceImplTest {
|
||||
assertEquals(expected, ideaService.countAuthorsByApplicationPeriod(applicationPeriod, params));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrong_type_for_author() {
|
||||
when(applicationPeriodService.getTypesForStudent(applicationPeriod, student)).thenReturn(List.of(master));
|
||||
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(bachelor));
|
||||
|
||||
assertPair(
|
||||
false,
|
||||
"The idea is the wrong level for you, please pick another one.",
|
||||
ideaService.validateStudentAcceptance(
|
||||
createBachelorIdea(Idea.Status.UNMATCHED),
|
||||
student,
|
||||
coAuthor,
|
||||
applicationPeriod
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void wrong_type_for_partner() {
|
||||
when(applicationPeriodService.getTypesForStudent(applicationPeriod, coAuthor)).thenReturn(List.of(master));
|
||||
|
||||
assertPair(
|
||||
false,
|
||||
"The idea is the wrong level for your partner, please pick another one.",
|
||||
ideaService.validateStudentAcceptance(
|
||||
createBachelorIdea(Idea.Status.UNMATCHED),
|
||||
student,
|
||||
coAuthor,
|
||||
applicationPeriod
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private Idea mockInactiveIdea() {
|
||||
Idea idea = new Idea();
|
||||
Match match = new Match();
|
||||
|
@ -1,6 +1,9 @@
|
||||
package se.su.dsv.scipro.testdata;
|
||||
|
||||
import java.util.List;
|
||||
import se.su.dsv.scipro.match.Keyword;
|
||||
import se.su.dsv.scipro.system.ProjectType;
|
||||
import se.su.dsv.scipro.system.ResearchArea;
|
||||
|
||||
/// All the base test data that can be re-used in different test cases.
|
||||
///
|
||||
@ -16,4 +19,11 @@ public interface BaseData {
|
||||
ProjectType bachelor();
|
||||
ProjectType magister();
|
||||
ProjectType master();
|
||||
|
||||
/**
|
||||
* @return generic research area with some keywords attached to it
|
||||
*/
|
||||
ResearchAreaAndKeywords researchArea();
|
||||
|
||||
record ResearchAreaAndKeywords(ResearchArea researchArea, List<Keyword> keywords) {}
|
||||
}
|
||||
|
@ -2193,6 +2193,11 @@ public class DataInitializer implements Lifecycle, BaseData, Factory {
|
||||
return createEmployee(firstName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResearchAreaAndKeywords researchArea() {
|
||||
return new ResearchAreaAndKeywords(researchArea1, List.of(keyword1, keyword2));
|
||||
}
|
||||
|
||||
private static final class SimpleTextFile implements FileUpload {
|
||||
|
||||
private final User uploader;
|
||||
|
68
test-data/src/main/java/se/su/dsv/scipro/testdata/populators/PartnerTypeExemption.java
vendored
Normal file
68
test-data/src/main/java/se/su/dsv/scipro/testdata/populators/PartnerTypeExemption.java
vendored
Normal file
@ -0,0 +1,68 @@
|
||||
package se.su.dsv.scipro.testdata.populators;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.Set;
|
||||
import org.springframework.stereotype.Service;
|
||||
import se.su.dsv.scipro.match.ApplicationPeriod;
|
||||
import se.su.dsv.scipro.match.ApplicationPeriodService;
|
||||
import se.su.dsv.scipro.match.Idea;
|
||||
import se.su.dsv.scipro.match.IdeaService;
|
||||
import se.su.dsv.scipro.match.Target;
|
||||
import se.su.dsv.scipro.match.TargetService;
|
||||
import se.su.dsv.scipro.system.User;
|
||||
import se.su.dsv.scipro.testdata.BaseData;
|
||||
import se.su.dsv.scipro.testdata.Factory;
|
||||
import se.su.dsv.scipro.testdata.TestDataPopulator;
|
||||
|
||||
@Service
|
||||
public class PartnerTypeExemption implements TestDataPopulator {
|
||||
|
||||
private final ApplicationPeriodService applicationPeriodService;
|
||||
private final IdeaService ideaService;
|
||||
private final TargetService targetService;
|
||||
|
||||
@Inject
|
||||
public PartnerTypeExemption(
|
||||
ApplicationPeriodService applicationPeriodService,
|
||||
IdeaService ideaService,
|
||||
TargetService targetService
|
||||
) {
|
||||
this.applicationPeriodService = applicationPeriodService;
|
||||
this.ideaService = ideaService;
|
||||
this.targetService = targetService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void populate(BaseData baseData, Factory factory) {
|
||||
factory.createAuthor("Oskar");
|
||||
|
||||
User johan = factory.createAuthor("Johan");
|
||||
johan.setDegreeType(baseData.master().getDegreeType());
|
||||
|
||||
User supervisor = factory.createSupervisor("Elsa");
|
||||
|
||||
ApplicationPeriod applicationPeriod = new ApplicationPeriod("Supervisor ideas");
|
||||
applicationPeriod.setStartDate(LocalDate.now());
|
||||
applicationPeriod.setEndDate(LocalDate.now().plusDays(14));
|
||||
applicationPeriod.setCourseStartDateTime(LocalDateTime.now().plusDays(15));
|
||||
applicationPeriod.setProjectTypes(Set.of(baseData.bachelor()));
|
||||
applicationPeriodService.save(applicationPeriod);
|
||||
|
||||
Target target = targetService.findOne(applicationPeriod, supervisor, baseData.bachelor());
|
||||
target.setTarget(10);
|
||||
targetService.save(target);
|
||||
|
||||
Idea idea = new Idea();
|
||||
idea.setPublished(true);
|
||||
idea.setTitle("The next gen AI 2.0 turbo edition");
|
||||
idea.setPrerequisites("Hacker experience");
|
||||
idea.setDescription("Better than all the rest");
|
||||
idea.setProjectType(baseData.bachelor());
|
||||
idea.setApplicationPeriod(applicationPeriod);
|
||||
idea.setResearchArea(baseData.researchArea().researchArea());
|
||||
|
||||
ideaService.saveSupervisorIdea(idea, supervisor, baseData.researchArea().keywords(), true);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user