Merge commit '03570fc6db9bfbf82c256ffa33785d309718a836' into HEAD

This commit is contained in:
Jenkins 2025-02-21 00:27:41 +01:00
commit 14e38bdbb9
14 changed files with 193 additions and 81 deletions
core/src/main
daisy-integration/src
main/java/se/su/dsv/scipro
test/java/se/su/dsv/scipro
pom.xml
view/src/main
war/src/main/resources

@ -13,6 +13,7 @@ import java.util.*;
import java.util.function.Function;
import se.su.dsv.scipro.checklist.ChecklistCategory;
import se.su.dsv.scipro.file.FileUpload;
import se.su.dsv.scipro.match.*;
import se.su.dsv.scipro.match.ApplicationPeriod;
import se.su.dsv.scipro.match.Idea;
import se.su.dsv.scipro.match.IdeaService;
@ -85,16 +86,19 @@ public class DataInitializer implements Lifecycle {
private User stina_student;
private User sid_student;
private User simon_student;
private ProjectType bachelorClass;
private User sofia_student;
private Set<ResearchArea> researchAreas;
private Long researchAreaId = RESEARCH_AREA_ID;
private Set<Language> languages;
private ApplicationPeriod applicationPeriod;
private Keyword keyword1;
private Set<Language> languages = Set.of(Language.SWEDISH, Language.ENGLISH);
private Program program;
private ResearchArea researchArea1;
private ResearchArea researchArea2;
private Keyword keyword1;
private Keyword keyword2;
private ProjectType bachelorClass;
private ProjectType masterClass;
private ProjectType magisterClass;
private ApplicationPeriod applicationPeriod;
private Project project2;
@Transactional
@ -103,6 +107,7 @@ public class DataInitializer implements Lifecycle {
if (profile.getCurrentProfile() == Profiles.DEV && noUsers()) {
createDefaultProjectTypesIfNotDone();
createDefaultChecklistCategoriesIfNotDone();
createProgram();
createApplicationPeriodIfNotDone();
createGradingCriterionTemplateIfNotDone();
createResearchAreasForDemo();
@ -111,6 +116,8 @@ public class DataInitializer implements Lifecycle {
createUsers();
createMatchedIdea();
createProjects();
createTarget();
createStudentIdea();
createRoughDraftApproval();
}
if (profile.getCurrentProfile() == Profiles.DEV && noAdminUser()) {
@ -135,6 +142,15 @@ public class DataInitializer implements Lifecycle {
return userService.findByUsername(ADMIN + MAIL) == null;
}
private void createProgram() {
program = new Program();
program.setCode("AppCompSci");
program.setName("Tillämpad Datavetenskap");
program.setExternalId(123);
program.setNameEn("Applied Computer Science");
program = save(program);
}
private void createApplicationPeriodIfNotDone() {
applicationPeriod = new ApplicationPeriod("HT 2014");
applicationPeriod.setStartDate(LocalDate.now().minusDays(APPLICATION_PERIOD_START_MINUS_DAYS));
@ -150,12 +166,12 @@ public class DataInitializer implements Lifecycle {
keyword1 = new Keyword("IT");
keyword1.addResearchArea(researchArea1);
keyword1.addResearchArea(researchArea2);
save(keyword1);
keyword1 = save(keyword1);
Keyword keyword2 = new Keyword("Computers");
keyword2 = new Keyword("Computers");
keyword2.addResearchArea(researchArea1);
keyword2.addResearchArea(researchArea2);
save(keyword2);
keyword2 = save(keyword2);
}
private void createResearchAreasForDemo() {
@ -211,6 +227,11 @@ public class DataInitializer implements Lifecycle {
// can not be used as author on any idea
// can not be used as author on any project
createStudent("Stig");
// Used to test assign supervisor to student idea
// this student has a submitted idea, which has not assigned supervisor
// don't use this student for anything else
sofia_student = createStudent("Sofia");
}
private User createStudent(String firstName) {
@ -229,8 +250,11 @@ public class DataInitializer implements Lifecycle {
user.setUnit(u);
user.setResearchAreas(researchAreas);
user.setLanguages(languages);
user.setActiveAsSupervisor(true);
createBeta(user);
return user;
return save(user);
}
private User createUser(String firstName, String lastName) {
@ -304,6 +328,32 @@ public class DataInitializer implements Lifecycle {
save(getMagisterTemplate());
}
private void createTarget() {
Target target = new Target(eric_employee, applicationPeriod, bachelorClass);
target.setTarget(10);
save(target);
}
private void createStudentIdea() {
Idea idea = new Idea();
idea.setTitle("Fundamental Math Concepts of AI");
idea.setType(Idea.Type.STUDENT);
TholanderBox box = new TholanderBox();
box.setLiterature("Math AI Literature");
box.setBackground("Math AI Background");
box.setProblem("Math AI Problem");
box.setMethod("Math AI Method");
box.setInterests("Math AI Interests");
idea.setTholanderBox(box);
idea.setProjectType(bachelorClass);
idea.setApplicationPeriod(applicationPeriod);
List<Keyword> keywords = List.of(keyword1, keyword2);
ideaService.saveStudentIdea(idea, sofia_student, program, new HashSet<User>(), keywords, true);
}
private GradingReportTemplate getBachelorTemplate() {
GradingReportTemplate gradingReportTemplate = new GradingReportTemplate(
bachelorClass,

@ -1,7 +1,10 @@
package se.su.dsv.scipro.reusable;
import java.time.LocalDate;
import java.util.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
public final class SciProUtilities {
@ -75,15 +78,4 @@ public final class SciProUtilities {
}
return copy;
}
public static Calendar toCalendar(final LocalDate localDate) {
if (localDate == null) {
return null;
} else {
final Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(localDate.getYear(), localDate.getMonthValue() - 1, localDate.getDayOfMonth());
return calendar;
}
}
}

@ -9,6 +9,10 @@
parseMethod="jakarta.xml.bind.DatatypeConverter.parseDateTime"
printMethod="jakarta.xml.bind.DatatypeConverter.printDateTime" />
<jaxb:javaType name="java.time.LocalDate" xmlType="xs:date"
parseMethod="java.time.LocalDate.parse"
printMethod="java.time.format.DateTimeFormatter.ISO_LOCAL_DATE.format" />
<!-- Force all classes implements Serializable -->
<xjc:simple />
<xjc:serializable uid="1" />

@ -375,14 +375,16 @@
</xs:element>
<xs:element name="title_en" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="startDate" type="xs:dateTime" minOccurs="0">
<xs:element name="startDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="endDate" type="xs:dateTime" minOccurs="0">
<xs:element name="endDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="unit" type="serializableUnit" minOccurs="0">
</xs:element>
<xs:element name="researchAreas" type="researchAreas" minOccurs="0">
</xs:element>
<xs:element name="externalID" type="xs:string" minOccurs="0">
</xs:element>
</xs:sequence>
</xs:complexType>
@ -390,13 +392,15 @@
<xs:sequence>
<xs:element name="title_en" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="externalID" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="aborted" type="xs:boolean" minOccurs="1">
</xs:element>
<xs:element name="level" type="educationalLevel" minOccurs="0">
</xs:element>
<xs:element name="title" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="endDate" type="xs:dateTime" minOccurs="0">
<xs:element name="endDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="status" type="STATUS" minOccurs="0">
</xs:element>
@ -404,7 +408,7 @@
</xs:element>
<xs:element name="finished" type="xs:boolean" minOccurs="1">
</xs:element>
<xs:element name="startDate" type="xs:dateTime" minOccurs="0">
<xs:element name="startDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="id" type="xs:int" minOccurs="1">
</xs:element>
@ -475,9 +479,11 @@
</xs:element>
<xs:element name="title_en" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="startDate" type="xs:dateTime" minOccurs="0">
<xs:element name="externalID" type="xs:string" minOccurs="0">
</xs:element>
<xs:element name="endDate" type="xs:dateTime" minOccurs="0">
<xs:element name="startDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="endDate" type="xs:date" minOccurs="0">
</xs:element>
<xs:element name="aborted" type="xs:boolean" minOccurs="1">
</xs:element>

@ -4,10 +4,9 @@ import static com.querydsl.core.types.dsl.Expressions.anyOf;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.core.Response;
import java.time.Instant;
import java.time.LocalDate;
import java.time.Period;
import java.util.Calendar;
import java.util.Date;
import java.util.Optional;
import java.util.Set;
@ -38,7 +37,6 @@ import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.project.ProjectRepo;
import se.su.dsv.scipro.project.ProjectStatus;
import se.su.dsv.scipro.project.QProject;
import se.su.dsv.scipro.reusable.SciProUtilities;
import se.su.dsv.scipro.system.DegreeType;
import se.su.dsv.scipro.system.User;
import se.su.dsv.scipro.workerthreads.AbstractWorker;
@ -198,7 +196,7 @@ public class ProjectExporter extends AbstractWorker {
UnitWithID unit = new UnitWithID();
unit.setId(project.getHeadSupervisor().getUnit().getIdentifier());
Calendar startDate = SciProUtilities.toCalendar(project.getStartDate());
LocalDate startDate = project.getStartDate();
String title = finalThesis
.map(FinalThesis::getSwedishTitle)
@ -211,7 +209,7 @@ public class ProjectExporter extends AbstractWorker {
thesis.setUnit(unit);
thesis.setAborted(project.getProjectStatus() == ProjectStatus.INACTIVE);
thesis.setStartDate(startDate);
thesis.setEndDate(SciProUtilities.toCalendar(project.getExpectedEndDate()));
thesis.setEndDate(project.getExpectedEndDate());
final ResearchAreas researchAreas = new ResearchAreas();
if (project.getResearchArea() != null && project.getResearchArea().getIdentifier() != null) {
final ResearchAreaWithID researchArea2 = new ResearchAreaWithID();
@ -260,36 +258,14 @@ public class ProjectExporter extends AbstractWorker {
}
private void updateHeadSupervisor(Project project) throws ExternalExportException {
boolean toAdd = true;
boolean shouldChange = true;
Set<ProjectParticipant> contributors = daisyAPI.getContributors(project.getIdentifier());
for (ProjectParticipant contributor : contributors) {
if (contributor.getRole() == Role.SUPERVISOR) {
if (contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier())) {
toAdd = false;
} else {
Response response = daisyAPI.deleteThesisPerson(
project.getIdentifier(),
contributor.getPerson().getId()
);
if (response.getStatusInfo().getFamily() != Response.Status.Family.SUCCESSFUL) {
LOG.warn(
"Failed to delete supervisor from project: {} (id: {} / {})",
project.getTitle(),
project.getId(),
project.getIdentifier()
);
// Card 3413
// Do not attempt to add the new supervisor if the old one is still there to prevent
// the project from having multiple supervisors.
// Hopefully Daisy API will soon have support for the function "change supervisor"
// rather than just INSERT and DELETE rows in a table.
toAdd = false;
}
}
shouldChange = !contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier());
}
}
if (toAdd) {
if (shouldChange) {
externalExporter.addContributorToProject(project, project.getHeadSupervisor(), Role.SUPERVISOR);
}
}

@ -56,6 +56,7 @@ public class RejectedThesisWorker extends AbstractWorker {
if (supervisorGradingReport.getLastModified().before(rejectedDate)) {
supervisorGradingReport.setState(GradingReport.State.INITIAL);
supervisorGradingReport.setSubmitted(false);
supervisorGradingReport.setDateSubmittedToExaminer(null);
supervisorGradingReport.setRejectionComment(thesisRejection.getMessage());
}
}

@ -3,7 +3,7 @@ package se.su.dsv.scipro.io.impl;
import jakarta.inject.Inject;
import jakarta.ws.rs.core.Response;
import java.math.BigDecimal;
import java.util.Calendar;
import java.time.LocalDate;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import se.su.dsv.scipro.daisyexternal.http.DaisyAPI;
@ -21,7 +21,6 @@ import se.su.dsv.scipro.io.dto.ThesisToBeCreated;
import se.su.dsv.scipro.io.dto.UnitWithID;
import se.su.dsv.scipro.io.exceptions.ExternalExportException;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.reusable.SciProUtilities;
import se.su.dsv.scipro.system.Unit;
import se.su.dsv.scipro.system.User;
@ -46,9 +45,9 @@ public class ExternalExporterDaisyImpl implements ExternalExporter {
ThesisToBeCreated exportProjectDTO = new ThesisToBeCreated();
exportProjectDTO.setTitle(truncate(project.getTitle()));
Calendar startDate = SciProUtilities.toCalendar(project.getStartDate());
LocalDate startDate = project.getStartDate();
exportProjectDTO.setStartDate(startDate);
exportProjectDTO.setEndDate(SciProUtilities.toCalendar(project.getExpectedEndDate()));
exportProjectDTO.setEndDate(project.getExpectedEndDate());
exportProjectDTO.setUnit(unitDTO);
final ResearchAreas researchAreas = new ResearchAreas();
if (project.getResearchArea() != null && project.getResearchArea().getIdentifier() != null) {

@ -2,6 +2,7 @@ package se.su.dsv.scipro.integration.daisy.workers;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@ -144,22 +145,61 @@ public class ProjectExporterTest {
}
@Test
public void deletes_wrong_head_supervisor() {
Person person = new Person();
person.setId(234234);
public void change_head_supervisor() throws Exception {
User newSupervisor = User.builder()
.firstName("New")
.lastName("Supervisor")
.emailAddress("new@supervisor.com")
.build();
Unit unit = new Unit();
unit.setIdentifier(239478);
ProjectParticipant headSupervisor = new ProjectParticipant();
headSupervisor.setRole(Role.SUPERVISOR);
headSupervisor.setPerson(person);
newSupervisor.setIdentifier(12345);
newSupervisor.setUnit(unit);
exportedProject.setHeadSupervisor(newSupervisor);
Set<ProjectParticipant> contributors = new HashSet<>();
contributors.add(headSupervisor);
ProjectParticipant oldSupervisor = new ProjectParticipant();
oldSupervisor.setRole(Role.SUPERVISOR);
Person oldPerson = new Person();
oldPerson.setId(SUPERVISOR_IDENTIFIER);
oldSupervisor.setPerson(oldPerson);
contributors.add(oldSupervisor);
when(daisyAPI.getContributors(exportedProject.getIdentifier())).thenReturn(contributors);
projectExporter.run();
verify(daisyAPI).deleteThesisPerson(exportedProject.getIdentifier(), person.getId());
verify(externalExporter).addContributorToProject(exportedProject, newSupervisor, Role.SUPERVISOR);
}
@Test
public void should_not_change_head_supervisor_if_already_exists() throws Exception {
User newSupervisor = User.builder()
.firstName("New")
.lastName("Supervisor")
.emailAddress("new@supervisor.com")
.build();
Unit unit = new Unit();
unit.setIdentifier(239478);
newSupervisor.setIdentifier(SUPERVISOR_IDENTIFIER);
newSupervisor.setUnit(unit);
exportedProject.setHeadSupervisor(newSupervisor);
Set<ProjectParticipant> contributors = new HashSet<>();
ProjectParticipant oldSupervisor = new ProjectParticipant();
oldSupervisor.setRole(Role.SUPERVISOR);
Person oldPerson = new Person();
oldPerson.setId(SUPERVISOR_IDENTIFIER);
oldSupervisor.setPerson(oldPerson);
contributors.add(oldSupervisor);
when(daisyAPI.getContributors(exportedProject.getIdentifier())).thenReturn(contributors);
projectExporter.run();
verify(externalExporter, never()).addContributorToProject(exportedProject, newSupervisor, Role.SUPERVISOR);
}
@Test

@ -19,7 +19,6 @@ import org.mockito.junit.jupiter.MockitoExtension;
import se.su.dsv.scipro.daisyexternal.http.DaisyAPI;
import se.su.dsv.scipro.io.dto.ThesisToBeCreated;
import se.su.dsv.scipro.project.Project;
import se.su.dsv.scipro.reusable.SciProUtilities;
import se.su.dsv.scipro.system.DegreeType;
import se.su.dsv.scipro.system.ProjectType;
import se.su.dsv.scipro.system.Unit;
@ -71,6 +70,6 @@ public class ExternalExporterDaisyImplTest {
ArgumentCaptor<ThesisToBeCreated> captor = ArgumentCaptor.forClass(ThesisToBeCreated.class);
verify(daisyAPI).createProject(captor.capture());
assertEquals(captor.getValue().getStartDate(), SciProUtilities.toCalendar(daisyStartDate));
assertEquals(captor.getValue().getStartDate(), daisyStartDate);
}
}

20
pom.xml

@ -39,6 +39,12 @@
<jersey.version>3.1.6</jersey.version>
<poi.version>5.2.5</poi.version>
<jackson.version>2.17.0</jackson.version>
<!--
When updating spring-boot check if the transitive dependency on json-smart has been
updated to 2.5.2 or later.
If so, remove the dependency managed version of json-smart
-->
<spring.boot.version>3.4.1</spring.boot.version>
<springdoc.openapi.version>2.8.3</springdoc.openapi.version>
@ -213,6 +219,20 @@
<version>2.0.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<!--
2.5.1 is brought in transitively by
spring-boot-starter-oauth2-client
spring-security-oauth2-client
oauth2-oidc-sdk
json-smart
it has a known security vulnerability that's fixed in 2.5.2
should be removed when spring-boot-starter-oauth2-client is updated
-->
<groupId>net.minidev</groupId>
<artifactId>json-smart</artifactId>
<version>2.5.2</version>
</dependency>
<!-- Test stuff -->
<dependency>

@ -10,3 +10,4 @@ Type.NUMBER_OF_AUTHORS=Min/max author limitation
Type.SUBMIT_STUDENT_IDEA=Submit own idea outside open period
Type.SELECT_SUPERVISOR_IDEA=Select supervisor idea outside open period
type=Type to exempt
author.UniqueValidator=Exemption already exists, please remove the old one first

@ -205,17 +205,34 @@ public abstract class AbstractAdminIdeaPanel extends Panel {
ideaService.adminUnmatchIdea(idea, SciProSession.get().getUser());
info("Unmatched idea: " + idea.getTitle());
} else {
if (
targetService.hasTargetsLeft(
idea.getApplicationPeriod(),
newSelection,
idea.getProjectType()
)
) {
ideaService.changeSupervisor(idea, newSelection, SciProSession.get().getUser());
info("Supervisor changed");
ideaService.changeSupervisor(idea, newSelection, SciProSession.get().getUser());
Target currentTarget = targetService.findOne(
idea.getApplicationPeriod(),
newSelection,
idea.getProjectType()
);
Long countMatched = ideaService.countMatched(
idea.getApplicationPeriod(),
newSelection,
idea.getProjectType()
);
int targetCounter = (currentTarget == null) ? 0 : currentTarget.getTarget();
String msg =
"Supervisor changed: matched/target -> " +
countMatched +
" / " +
targetCounter +
" (" +
idea.getProjectType().getName() +
")";
if (countMatched > targetCounter) {
warn(msg);
} else {
error("The supervisor have reached current target numbers");
info(msg);
}
}
target.addListener(new AjaxFeedbackPanelUpdater());

@ -129,6 +129,12 @@ footer a:hover { color: #d95e00;}
border-color: #EBCCD1;
}
.feedbackPanelWARNING {
color: #000000;
background-color: #FFD105;
border-color: #EBCCD1;
}
.feedbackPanelINFO {
color: #3C763D;
background-color: #DFF0D8;

@ -9,6 +9,7 @@ spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.Ph
# We also need to set the implicit strategy to be JPA compliant, as we rely on this naming strategy for certain
# join tables (idea_Keyword vs idea_keyword)
spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.show-sql=false
spring.mvc.servlet.path=/api