Skip to content
Snippets Groups Projects

Resolve "[Queue-2.0] Enqueueing errors when no student group is found"

3 files
+ 59
4
Compare changes
  • Side-by-side
  • Inline

Files

@@ -25,8 +25,11 @@ import java.util.stream.Collectors;
import javax.transaction.Transactional;
import nl.tudelft.labracore.api.StudentGroupControllerApi;
import nl.tudelft.labracore.api.dto.PersonSummaryDTO;
import nl.tudelft.labracore.api.dto.*;
import nl.tudelft.labracore.lib.security.user.Person;
import nl.tudelft.queue.cache.AssignmentCacheManager;
import nl.tudelft.queue.cache.PersonCacheManager;
import nl.tudelft.queue.cache.SessionCacheManager;
import nl.tudelft.queue.dto.create.RequestCreateDTO;
import nl.tudelft.queue.dto.util.RequestTableFilterDTO;
import nl.tudelft.queue.model.ClosableTimeSlot;
@@ -40,6 +43,8 @@ import nl.tudelft.queue.repository.RequestRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import reactor.core.publisher.Mono;
@Service
public class RequestService {
@Autowired
@@ -60,6 +65,15 @@ public class RequestService {
@Autowired
private StudentGroupControllerApi sgApi;
@Autowired
private AssignmentCacheManager aCache;
@Autowired
private PersonCacheManager pCache;
@Autowired
private SessionCacheManager sCache;
/**
* Creates a request in the request daabase based on the person that posted the request and the
* information the user posted in the form of a {@link RequestCreateDTO}.
@@ -73,8 +87,10 @@ public class RequestService {
public void createRequest(RequestCreateDTO dto, Long personId, boolean sendEvent) {
Request request = dto.apply();
request.setRequester(personId);
request.setStudentGroup(sgApi.getGroupForPersonAndAssignment(
personId, dto.getAssignment()).block().getId());
request.setStudentGroup(sgApi
.getGroupForPersonAndAssignment(personId, dto.getAssignment())
.onErrorResume(e -> createIndividualStudentGroup(dto, personId))
.block().getId());
if (request.getLab().getCommunicationMethod().isOnline()) {
request.setJitsiRoom(js.createJitsiRoomName(request));
@@ -295,4 +311,30 @@ public class RequestService {
return requests.stream().skip(new Random().nextInt(requests.size())).findFirst();
}
/**
* Creates an individual student group for one student without a current group so that they may place a
* request with that student group.
*
* TODO: Create a two-in-one function in StudentGroupController to check whether one exists and create a
* student group if one does not exist yet.
*
* @param dto The DTO containing user request information.
* @param personId The id of the person that posted the request.
* @return A mono containing the created student group.
*/
private Mono<StudentGroupDetailsDTO> createIndividualStudentGroup(RequestCreateDTO dto, Long personId) {
var person = pCache.getOrThrow(personId);
var assignment = aCache.getOrThrow(dto.getAssignment());
var session = sCache.getOrThrow(dto.getLab().getSession());
return sgApi.addGroup(new StudentGroupCreateDTO()
.name(person.getDisplayName())
.capacity(1)
.addMembersItem(new RoleIdDTO().id(new Id()
.personId(person.getId())
.editionId(session.getEdition().getId())))
.module(new ModuleIdDTO().id(assignment.getModule().getId())))
.flatMap(id -> sgApi.getStudentGroupsById(List.of(id)).collectList().map(l -> l.get(0)));
}
}
Loading