SEBSERV-133 Client Configuration

This commit is contained in:
anhefti 2022-05-05 09:51:49 +02:00
parent ebcbc134af
commit 698e7231cd
4 changed files with 78 additions and 0 deletions

View file

@ -522,6 +522,11 @@ public enum ActionDefinition {
ImageIcon.EXPORT,
PageStateDefinitionImpl.SEB_CLIENT_CONFIG_VIEW,
ActionCategory.FORM),
SEB_CLIENT_CONFIG_DELETE(
new LocTextKey("sebserver.clientconfig.action.delete"),
ImageIcon.DELETE,
PageStateDefinitionImpl.SEB_CLIENT_CONFIG_VIEW,
ActionCategory.FORM),
SEB_EXAM_CONFIG_LIST(
new LocTextKey("sebserver.examconfig.action.list"),

View file

@ -44,11 +44,13 @@ import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import ch.ethz.seb.sebserver.gui.service.page.PageMessageException;
import ch.ethz.seb.sebserver.gui.service.page.PageService;
import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer;
import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction;
import ch.ethz.seb.sebserver.gui.service.remote.download.DownloadService;
import ch.ethz.seb.sebserver.gui.service.remote.download.SEBClientConfigDownload;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.ActivateClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.DeactivateClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.DeleteClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.NewClientConfig;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.SaveClientConfig;
@ -114,6 +116,11 @@ public class SEBClientConfigForm implements TemplateComposer {
private static final LocTextKey FORM_CONFIRM_ENCRYPT_SECRET_TEXT_KEY =
new LocTextKey("sebserver.clientconfig.form.encryptSecret.confirm");
private static final LocTextKey DELETE_CONFIRM =
new LocTextKey("sebserver.clientconfig.action.delete.confirm");
private static final LocTextKey DELETE_SUCCESS =
new LocTextKey("sebserver.clientconfig.action.delete.success");
private static final String DEFAULT_PING_INTERVAL = String.valueOf(1000);
private static final String FALLBACK_DEFAULT_TIME = String.valueOf(30 * Constants.SECOND_IN_MILLIS);
private static final String FALLBACK_DEFAULT_ATTEMPTS = String.valueOf(5);
@ -193,6 +200,12 @@ public class SEBClientConfigForm implements TemplateComposer {
.withEntityKey(entityKey)
.publishIf(() -> modifyGrant && isReadonly)
.newAction(ActionDefinition.SEB_CLIENT_CONFIG_DELETE)
.withEntityKey(entityKey)
.withConfirm(() -> DELETE_CONFIRM)
.withExec(this::deleteConnectionConfig)
.publishIf(() -> modifyGrant && isReadonly)
.newAction(ActionDefinition.SEB_CLIENT_CONFIG_EXPORT)
.withEntityKey(entityKey)
.withExec(action -> {
@ -234,6 +247,24 @@ public class SEBClientConfigForm implements TemplateComposer {
.publishIf(() -> !isReadonly);
}
private PageAction deleteConnectionConfig(final PageAction pageAction) {
this.restService.getBuilder(DeleteClientConfig.class)
.withURIVariable(API.PARAM_MODEL_ID, pageAction.getEntityKey().modelId)
.call()
.onError(error -> pageAction.pageContext().notifyUnexpectedError(error))
.ifPresent(rep -> {
if (rep.getErrors().isEmpty()) {
pageAction.pageContext().publishInfo(DELETE_SUCCESS);
} else {
pageAction.pageContext().notifyUnexpectedError(
new RuntimeException(rep.errors.iterator().next().errorMessage.details));
}
});
return pageAction;
}
private void buildForm(
final SEBClientConfig clientConfig,
final PageContext formContext,

View file

@ -0,0 +1,40 @@
/*
* Copyright (c) 2022 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
package ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig;
import org.springframework.context.annotation.Lazy;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import com.fasterxml.jackson.core.type.TypeReference;
import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.EntityType;
import ch.ethz.seb.sebserver.gbl.model.EntityProcessingReport;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall;
@Lazy
@Component
@GuiProfile
public class DeleteClientConfig extends RestCall<EntityProcessingReport> {
public DeleteClientConfig() {
super(new TypeKey<>(
CallType.DELETE,
EntityType.EXAM,
new TypeReference<EntityProcessingReport>() {
}),
HttpMethod.DELETE,
MediaType.APPLICATION_FORM_URLENCODED,
API.SEB_CLIENT_CONFIG_ENDPOINT + API.MODEL_ID_VAR_PATH_SEGMENT);
}
}

View file

@ -816,6 +816,8 @@ sebserver.clientconfig.action.save=Save Connection Configuration
sebserver.clientconfig.action.activate=Activate Connection Configuration
sebserver.clientconfig.action.deactivate=Deactivate Connection Configuration
sebserver.clientconfig.action.export=Export Connection Configuration
sebserver.clientconfig.action.delete=Delete Connection Configuration
sebserver.clientconfig.action.delete.confirm=Please note that after deletion of this Connection Configuration,<br/>a SEB that loads a former download of this Connection Configuration will never be able to connect to SEB Server again.
################################
# SEB Exam Configuration