diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java index 47e322db..27b4437f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/MultiSelectionCombo.java @@ -134,22 +134,10 @@ public final class MultiSelectionCombo extends Composite implements Selection { Arrays.asList(StringUtils.split(keys, Constants.LIST_SEPARATOR)) .stream() - .map(this::itemForName) + .map(this::itemForId) .forEach(this::addSelection); } - private Tuple itemForName(final String name) { - final Optional> findFirst = this.availableValues - .stream() - .filter(it -> it._2 != null && it._2.equals(name)) - .findFirst(); - if (findFirst.isPresent()) { - return findFirst.get(); - } - - return null; - } - @Override public String getSelectionValue() { if (this.selectedValues.isEmpty()) { @@ -237,4 +225,28 @@ public final class MultiSelectionCombo extends Composite implements Selection { } } + private Tuple itemForName(final String name) { + final Optional> findFirst = this.availableValues + .stream() + .filter(it -> it._2 != null && it._2.equals(name)) + .findFirst(); + if (findFirst.isPresent()) { + return findFirst.get(); + } + + return null; + } + + private Tuple itemForId(final String id) { + final Optional> findFirst = this.availableValues + .stream() + .filter(it -> it._1 != null && it._1.equals(id)) + .findFirst(); + if (findFirst.isPresent()) { + return findFirst.get(); + } + + return null; + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SebInstructionServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SebInstructionServiceImpl.java index a1d18902..3e3f0ffa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SebInstructionServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/session/impl/SebInstructionServiceImpl.java @@ -75,7 +75,8 @@ public class SebInstructionServiceImpl implements SebInstructionService { loadInstruction() .onError( - error -> log.error("Failed to initialize and load persistent storage SEB client instructions: ", + error -> log.error( + "Failed to initialize and load persistent storage SEB client instructions: ", error)); if (this.instructions.size() > 0) { @@ -116,6 +117,9 @@ public class SebInstructionServiceImpl implements SebInstructionService { @Override public String getInstructionJSON(final String connectionToken) { refreshCache(); + if (this.instructions.isEmpty()) { + return null; + } final ClientInstructionRecord clientInstruction = this.instructions.remove(connectionToken); if (clientInstruction != null) { diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java index fdef0d1c..47886a31 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAPI_V1_Controller.java @@ -13,7 +13,6 @@ import java.security.Principal; import java.util.Arrays; import java.util.Collection; import java.util.List; -import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executor; import java.util.stream.Collectors; @@ -26,6 +25,7 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.http.HttpStatus; import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import org.springframework.util.MultiValueMap; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestHeader; @@ -129,7 +129,8 @@ public class ExamAPI_V1_Controller { } if (result.isEmpty()) { - log.warn("There are no currently running exams for institution: {}. SEB connection creation denied", institutionId); + log.warn("There are no currently running exams for institution: {}. SEB connection creation denied", + institutionId); throw new IllegalStateException("There are no currently running exams"); } @@ -306,22 +307,48 @@ public class ExamAPI_V1_Controller { } } + private static final ResponseEntity EMPTY_PING_RESPONSE = ResponseEntity + .ok() + .build(); + @RequestMapping( path = API.EXAM_API_PING_ENDPOINT, method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, produces = MediaType.APPLICATION_JSON_UTF8_VALUE) - public CompletableFuture ping( + public ResponseEntity ping( @RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken, @RequestParam(name = API.EXAM_API_PING_TIMESTAMP, required = true) final long timestamp, @RequestParam(name = API.EXAM_API_PING_NUMBER, required = false) final int pingNumber) { - return CompletableFuture.supplyAsync( - () -> this.sebClientConnectionService - .notifyPing(connectionToken, timestamp, pingNumber), - this.executor); + final String notifyPing = this.sebClientConnectionService + .notifyPing(connectionToken, timestamp, pingNumber); + + if (notifyPing == null) { + return EMPTY_PING_RESPONSE; + } + + return ResponseEntity + .ok() + .body(notifyPing); } +// @RequestMapping( +// path = API.EXAM_API_PING_ENDPOINT, +// method = RequestMethod.POST, +// consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE, +// produces = MediaType.APPLICATION_JSON_UTF8_VALUE) +// public CompletableFuture ping( +// @RequestHeader(name = API.EXAM_API_SEB_CONNECTION_TOKEN, required = true) final String connectionToken, +// @RequestParam(name = API.EXAM_API_PING_TIMESTAMP, required = true) final long timestamp, +// @RequestParam(name = API.EXAM_API_PING_NUMBER, required = false) final int pingNumber) { +// +// return CompletableFuture.supplyAsync( +// () -> this.sebClientConnectionService +// .notifyPing(connectionToken, timestamp, pingNumber), +// this.executor); +// } + @RequestMapping( path = API.EXAM_API_EVENT_ENDPOINT, method = RequestMethod.POST, diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java index 55cd8c94..6ecbab0c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ExamAdministrationController.java @@ -339,6 +339,14 @@ public class ExamAdministrationController extends EntityController { .flatMap(this.examAdminService::applyAdditionalSEBRestrictions); } + @Override + protected Result notifySaved(final Exam entity) { + return Result.tryCatch(() -> { + this.examSessionService.flushCache(entity); + return entity; + }); + } + @Override protected Result validForCreate(final Exam entity) { return super.validForCreate(entity)