Skip to content
Snippets Groups Projects
Commit e4aa2749 authored by Henry Page's avatar Henry Page :speech_balloon:
Browse files

delete data when not in core

parent 02858e3d
No related branches found
No related tags found
1 merge request!619Draft: Resolve "Trying to view lab information after respective modules are deleted results in NullPointer"
...@@ -180,6 +180,8 @@ public class LabController { ...@@ -180,6 +180,8 @@ public class LabController {
List<? extends Request<?>> requests; List<? extends Request<?>> requests;
if (qSession instanceof Lab lab) { if (qSession instanceof Lab lab) {
requests = lrr.findAllByFilter(List.of(lab), filter, Language.ANY); requests = lrr.findAllByFilter(List.of(lab), filter, Language.ANY);
requests.removeIf(rq -> qSession.getRequests().stream().map(Request::getId)
.noneMatch(rId -> rId.equals(rq.getId())));
} else { } else {
requests = qSession.getRequests(); requests = qSession.getRequests();
} }
...@@ -816,7 +818,11 @@ public class LabController { ...@@ -816,7 +818,11 @@ public class LabController {
Set<Long> alreadyInGroup = sgCache.getByPerson(person.getId()).stream() Set<Long> alreadyInGroup = sgCache.getByPerson(person.getId()).stream()
.map(g -> g.getModule().getId()).collect(Collectors.toSet()); .map(g -> g.getModule().getId()).collect(Collectors.toSet());
Set<Long> hasEmptyGroups = qSession.getModules().stream()
Set<Long> hasEmptyGroups = mCache
.getAndHandle(new ArrayList<>(qSession.getModules()),
id -> ls.removeModuleForSession(qSession, id))
.stream().map(ModuleDetailsDTO::getId)
.filter(m -> !alreadyInGroup.contains(m)) .filter(m -> !alreadyInGroup.contains(m))
.filter(m -> sgApi.getAllGroupsInModule(m).any(g -> g.getMemberUsernames().isEmpty()) .filter(m -> sgApi.getAllGroupsInModule(m).any(g -> g.getMemberUsernames().isEmpty())
.block()) .block())
...@@ -834,7 +840,7 @@ public class LabController { ...@@ -834,7 +840,7 @@ public class LabController {
} else { } else {
model.addAttribute("modules", model.addAttribute("modules",
mCache.getAndHandle(qSession.getModules().stream(), mCache.getAndHandle(qSession.getModules().stream(),
moduleID -> qSession.getModules().remove(moduleID)) moduleId -> ls.removeModuleForSession(qSession, moduleId))
.stream().sorted(Comparator.comparing(ModuleDetailsDTO::getName)) .stream().sorted(Comparator.comparing(ModuleDetailsDTO::getName))
.collect(Collectors.toList())); .collect(Collectors.toList()));
} }
......
...@@ -36,9 +36,11 @@ import nl.tudelft.labracore.api.SessionControllerApi; ...@@ -36,9 +36,11 @@ import nl.tudelft.labracore.api.SessionControllerApi;
import nl.tudelft.labracore.api.dto.*; import nl.tudelft.labracore.api.dto.*;
import nl.tudelft.labracore.lib.security.user.Person; import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.librador.dto.view.View; import nl.tudelft.librador.dto.view.View;
import nl.tudelft.queue.cache.AssignmentCacheManager;
import nl.tudelft.queue.cache.EditionCacheManager; import nl.tudelft.queue.cache.EditionCacheManager;
import nl.tudelft.queue.cache.EditionCollectionCacheManager; import nl.tudelft.queue.cache.EditionCollectionCacheManager;
import nl.tudelft.queue.cache.SessionCacheManager; import nl.tudelft.queue.cache.SessionCacheManager;
import nl.tudelft.queue.cache.StudentGroupCacheManager;
import nl.tudelft.queue.csv.*; import nl.tudelft.queue.csv.*;
import nl.tudelft.queue.dto.create.QueueSessionCreateDTO; import nl.tudelft.queue.dto.create.QueueSessionCreateDTO;
import nl.tudelft.queue.dto.create.labs.AbstractSlottedLabCreateDTO; import nl.tudelft.queue.dto.create.labs.AbstractSlottedLabCreateDTO;
...@@ -88,9 +90,15 @@ public class LabService { ...@@ -88,9 +90,15 @@ public class LabService {
@Autowired @Autowired
private EditionCacheManager eCache; private EditionCacheManager eCache;
@Autowired
private StudentGroupCacheManager sgCache;
@Autowired @Autowired
private EditionCollectionCacheManager ecCache; private EditionCollectionCacheManager ecCache;
@Autowired
private AssignmentCacheManager aCache;
@Autowired @Autowired
private SessionCacheManager sCache; private SessionCacheManager sCache;
...@@ -537,6 +545,24 @@ public class LabService { ...@@ -537,6 +545,24 @@ public class LabService {
return labs.stream().map(Lab::getOnlineModes).flatMap(Set::stream).collect(Collectors.toSet()); return labs.stream().map(Lab::getOnlineModes).flatMap(Set::stream).collect(Collectors.toSet());
} }
/**
* Responsible for removing things that are no longer needed when a module is deleted.
*
* @param qs The session in question
* @param moduleId The module id that was deleted.
*/
@Transactional
public void removeModuleForSession(QueueSession<?> qs, Long moduleId) {
qs.getModules().remove(moduleId);
qs.getRequests().removeIf(r -> sgCache.get(r.getStudentGroup()).isEmpty());
if (qs instanceof Lab) {
Lab lab = (Lab) qs;
lab.getAllowedRequests().removeIf(ar -> aCache.get(ar.getAssignment()).isEmpty());
lab.getRequests().removeIf(r -> aCache.get(r.getAssignment()).isEmpty());
}
}
/** /**
* Adds students, identified by their netid in a CSV file to an exam lab to give them priority during the * Adds students, identified by their netid in a CSV file to an exam lab to give them priority during the
* review. * review.
......
...@@ -236,6 +236,10 @@ public class RequestTableService { ...@@ -236,6 +236,10 @@ public class RequestTableService {
rCache.getAndIgnoreMissing( rCache.getAndIgnoreMissing(
requests.stream().map(Request::getRoom).filter(Objects::nonNull).distinct()); requests.stream().map(Request::getRoom).filter(Objects::nonNull).distinct());
for (Request r : requests) {
r.toViewDTO();
}
// Map each of the request to view DTOs that individually do cache requests // Map each of the request to view DTOs that individually do cache requests
return requests.stream().map(Request::toViewDTO).collect(Collectors.toList()); return requests.stream().map(Request::toViewDTO).collect(Collectors.toList());
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment