From 2af692f9ffb1d37dae108425d59732f5fc14e80d Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 7 Oct 2019 10:53:23 +0200 Subject: [PATCH] SEBSERV-46 front-end implementation --- .../gui/content/SebExamConfigPropForm.java | 21 +++++++++++++------ .../gui/service/page/PageService.java | 5 +++++ .../service/page/impl/PageServiceImpl.java | 10 +++++++++ .../remote/webservice/api/RestService.java | 7 ------- .../session/ClientConnectionTable.java | 3 ++- 5 files changed, 32 insertions(+), 14 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java index 3ae72197..d2670438 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropForm.java @@ -50,6 +50,7 @@ import ch.ethz.seb.sebserver.gui.service.remote.download.SebExamConfigPlaintextD import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ExportConfigKey; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNode; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ImportExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.NewExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; @@ -94,13 +95,12 @@ public class SebExamConfigPropForm implements TemplateComposer { protected SebExamConfigPropForm( final PageService pageService, - final RestService restService, final CurrentUser currentUser, final DownloadService downloadService, @Value("${sebserver.gui.seb.exam.config.download.filename}") final String downloadFileName) { this.pageService = pageService; - this.restService = restService; + this.restService = pageService.getRestService(); this.currentUser = currentUser; this.downloadService = downloadService; this.downloadFileName = downloadFileName; @@ -282,7 +282,9 @@ public class SebExamConfigPropForm implements TemplateComposer { dialog.open( FORM_IMPORT_TEXT_KEY, - SebExamConfigPropForm::doImport, + formHandle -> SebExamConfigPropForm.doImport( + pageService, + formHandle), Utils.EMPTY_EXECUTION, importFormBuilder); @@ -290,15 +292,22 @@ public class SebExamConfigPropForm implements TemplateComposer { }; } - // TODO - private static final void doImport(final FormHandle formHandle) { + private static final void doImport( + final PageService pageService, + final FormHandle formHandle) { + final Form form = formHandle.getForm(); final EntityKey entityKey = formHandle.getContext().getEntityKey(); final Control fieldControl = form.getFieldControl(IMPORT_FILE_ATTR_NAME); if (fieldControl != null && fieldControl instanceof FileUploadSelection) { final InputStream inputStream = ((FileUploadSelection) fieldControl).getInputStream(); if (inputStream != null) { - // TODO + pageService.getRestService() + .getBuilder(ImportExamConfig.class) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) + .withBody(inputStream) + .call() + .getOrThrow(); } } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java index 47dfd64f..662f4be5 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/PageService.java @@ -81,6 +81,11 @@ public interface PageService { * @return the JSONMapper for parse, read and write JSON */ JSONMapper getJSONMapper(); + /** Get the RestService bean + * + * @return the RestService bean */ + RestService getRestService(); + /** Get the PageState of the current user. * * @return PageState of the current user. */ diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java index 60a84962..e61793d1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageServiceImpl.java @@ -41,6 +41,7 @@ import ch.ethz.seb.sebserver.gui.service.page.event.ActionPublishEvent; import ch.ethz.seb.sebserver.gui.service.page.event.PageEvent; import ch.ethz.seb.sebserver.gui.service.page.event.PageEventListener; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCall; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.AuthorizationContextHolder; import ch.ethz.seb.sebserver.gui.table.TableBuilder; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; @@ -108,6 +109,15 @@ public class PageServiceImpl implements PageService { return this.jsonMapper; } + @Override + public RestService getRestService() { + if (this.resourceService == null) { + return null; + } + + return this.resourceService.getRestService(); + } + @Override public PageState getCurrentState() { try { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestService.java index f79f6ea2..a6d63ec8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestService.java @@ -71,11 +71,4 @@ public interface RestService { EntityType entityType, CallType callType); -// /** Performs an activation Action on RestCall specified within the given Action. -// * The RestCall must be of CallType.ACTIVATION_ACTIVATE or CallType.ACTIVATION_DEACTIVATE -// * -// * @param action the Action that defines an entity activation -// * @return the successfully executed Action */ -// PageAction activation(PageAction action); - } \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java index 44bce129..2ec7ceaa 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/session/ClientConnectionTable.java @@ -261,7 +261,7 @@ public final class ClientConnectionTable { private ClientConnectionData connectionData; private int[] thresholdColorIndices; private boolean duplicateChecked = false; - private final boolean duplicateMarked = false; + private boolean duplicateMarked = false; private boolean isDuplicate = false; UpdatableTableItem(final Long connectionId) { @@ -299,6 +299,7 @@ public final class ClientConnectionTable { void updateDuplicateColor(final TableItem tableItem) { if (this.isDuplicate && this.duplicateChecked && !this.duplicateMarked) { tableItem.setBackground(0, ClientConnectionTable.this.statusData.color3); + this.duplicateMarked = true; } else { tableItem.setBackground(0, null); }