Replace head supervisor
updateHeadSupervisor method has been updated to conform with the new daisy api changes. We no longer need to delete supervisor before replacing (updating).
This commit is contained in:
parent
130ab46284
commit
ff2ba01690
daisy-integration/src
main/java/se/su/dsv/scipro/integration/daisy/workers
test/java/se/su/dsv/scipro/integration/daisy/workers
@ -2,7 +2,6 @@ package se.su.dsv.scipro.integration.daisy.workers;
|
||||
|
||||
import jakarta.inject.Inject;
|
||||
import jakarta.inject.Named;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import se.su.dsv.scipro.daisyexternal.http.DaisyAPI;
|
||||
@ -264,29 +263,7 @@ public class ProjectExporter extends AbstractWorker {
|
||||
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;
|
||||
}
|
||||
}
|
||||
toAdd = !contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier());
|
||||
}
|
||||
}
|
||||
if (toAdd) {
|
||||
|
23
daisy-integration/src/test/java/se/su/dsv/scipro/integration/daisy/workers/ProjectExporterTest.java
23
daisy-integration/src/test/java/se/su/dsv/scipro/integration/daisy/workers/ProjectExporterTest.java
@ -144,22 +144,29 @@ 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user