Do not add duplicate supervisors in Daisy #26
|
@ -30,7 +30,7 @@ public interface DaisyAPI {
|
||||||
|
|
||||||
Response addContributor(Integer projectId, ProjectParticipant contributor);
|
Response addContributor(Integer projectId, ProjectParticipant contributor);
|
||||||
|
|
||||||
void deleteThesisPerson(Integer projectId, Integer personId);
|
Response deleteThesisPerson(Integer projectId, Integer personId);
|
||||||
|
|
||||||
Response createProject(ThesisToBeCreated project);
|
Response createProject(ThesisToBeCreated project);
|
||||||
|
|
||||||
|
|
|
@ -157,8 +157,8 @@ public class DaisyAPIImpl implements DaisyAPI {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteThesisPerson(Integer projectId, Integer personId) {
|
public Response deleteThesisPerson(Integer projectId, Integer personId) {
|
||||||
thesis()
|
return thesis()
|
||||||
.path(String.valueOf(projectId))
|
.path(String.valueOf(projectId))
|
||||||
.path(PERSON)
|
.path(PERSON)
|
||||||
.path(String.valueOf(personId))
|
.path(String.valueOf(personId))
|
||||||
|
|
|
@ -23,6 +23,7 @@ import se.su.dsv.scipro.workerthreads.AbstractWorker;
|
||||||
|
|
||||||
import jakarta.inject.Inject;
|
import jakarta.inject.Inject;
|
||||||
import jakarta.inject.Named;
|
import jakarta.inject.Named;
|
||||||
|
import jakarta.ws.rs.core.Response;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.Period;
|
import java.time.Period;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -240,18 +241,31 @@ public class ProjectExporter extends AbstractWorker {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateHeadSupervisor(Project project) throws ExternalExportException {
|
private void updateHeadSupervisor(Project project) throws ExternalExportException {
|
||||||
boolean add = true;
|
boolean toAdd = true;
|
||||||
Set<ProjectParticipant> contributors = daisyAPI.getContributors(project.getIdentifier());
|
Set<ProjectParticipant> contributors = daisyAPI.getContributors(project.getIdentifier());
|
||||||
for (ProjectParticipant contributor : contributors) {
|
for (ProjectParticipant contributor : contributors) {
|
||||||
if (contributor.getRole() == Role.SUPERVISOR) {
|
if (contributor.getRole() == Role.SUPERVISOR) {
|
||||||
if (contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier())) {
|
if (contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier())) {
|
||||||
add = false;
|
toAdd = false;
|
||||||
ansv7779 marked this conversation as resolved
Outdated
|
|||||||
} else {
|
} else {
|
||||||
daisyAPI.deleteThesisPerson(project.getIdentifier(), contributor.getPerson().getId());
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (add) {
|
if (toAdd) {
|
||||||
externalExporter.addContributorToProject(project, project.getHeadSupervisor(), Role.SUPERVISOR);
|
externalExporter.addContributorToProject(project, project.getHeadSupervisor(), Role.SUPERVISOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user
I suggest, while we are still on it, rename the variable from "add" to "toAdd".