Do not add duplicate supervisors in Daisy

Daisy's API does not support the function "change supervisor" and only what comes down to SQL INSERT and DELETE on a specific table. If the removal of the previous supervisor(s) failed the new one was still added. This change makes it so that if the removal of any (there is no limit in the API) current supervisor fails it will not attempt to add the new supervisor.
This commit is contained in:
Andreas Svanberg 2024-11-25 16:02:40 +01:00
parent aabb2e9d10
commit f3c4f7aeb8
3 changed files with 18 additions and 4 deletions
core/src/main/java/se/su/dsv/scipro/daisyExternal/http
daisy-integration/src/main/java/se/su/dsv/scipro/integration/daisy/workers

@ -30,7 +30,7 @@ public interface DaisyAPI {
Response addContributor(Integer projectId, ProjectParticipant contributor);
void deleteThesisPerson(Integer projectId, Integer personId);
Response deleteThesisPerson(Integer projectId, Integer personId);
Response createProject(ThesisToBeCreated project);

@ -157,8 +157,8 @@ public class DaisyAPIImpl implements DaisyAPI {
}
@Override
public void deleteThesisPerson(Integer projectId, Integer personId) {
thesis()
public Response deleteThesisPerson(Integer projectId, Integer personId) {
return thesis()
.path(String.valueOf(projectId))
.path(PERSON)
.path(String.valueOf(personId))

@ -23,6 +23,7 @@ import se.su.dsv.scipro.workerthreads.AbstractWorker;
import jakarta.inject.Inject;
import jakarta.inject.Named;
import jakarta.ws.rs.core.Response;
import java.time.Instant;
import java.time.Period;
import java.util.Calendar;
@ -247,7 +248,20 @@ public class ProjectExporter extends AbstractWorker {
if (contributor.getPerson().getId().equals(project.getHeadSupervisor().getIdentifier())) {
add = false;
} 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.
add = false;
}
}
}
}