From 71fb39749bd00f80e8f727b36eab1fc4473a76da Mon Sep 17 00:00:00 2001 From: anhefti Date: Wed, 27 Nov 2019 12:08:48 +0100 Subject: [PATCH] minor fixes --- .../ClientHttpRequestFactoryService.java | 2 +- .../seb/sebserver/gbl/api/APIMessage.java | 2 +- .../ethz/seb/sebserver/gbl/util/Result.java | 8 +++++++ .../gui/content/SebExamConfigPropForm.java | 23 +++++++++++-------- .../seb/sebserver/gui/form/FormHandle.java | 2 +- .../sebserver/gui/form/FormPostException.java | 19 +++++++++++++++ .../gui/service/page/impl/PageAction.java | 7 ++++++ .../service/page/impl/PageContextImpl.java | 2 +- .../seb/sebserver/gui/widget/Message.java | 6 ++++- .../config/application-dev-ws.properties | 4 ++-- src/main/resources/messages.properties | 16 ++++++------- 11 files changed, 66 insertions(+), 25 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/form/FormPostException.java diff --git a/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java b/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java index b6a21ecc..b1aebd12 100644 --- a/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java +++ b/src/main/java/ch/ethz/seb/sebserver/ClientHttpRequestFactoryService.java @@ -68,7 +68,7 @@ public class ClientHttpRequestFactoryService { final Environment environment, final ClientCredentialService clientCredentialService, @Value("${sebserver.http.client.connect-timeout:15000}") final int connectTimeout, - @Value("${sebserver.http.client.connection-request-timeout:10000}") final int connectionRequestTimeout, + @Value("${sebserver.http.client.connection-request-timeout:20000}") final int connectionRequestTimeout, @Value("${sebserver.http.client.read-timeout:10000}") final int readTimeout) { this.environment = environment; diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java index b49186eb..6cc76981 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/APIMessage.java @@ -199,7 +199,7 @@ public class APIMessage implements Serializable { public static String toHTML(final String errorMessage, final List messages) { final StringBuilder builder = new StringBuilder(); - builder.append("Failure: ").append(errorMessage).append("

"); + builder.append("Failure: ").append("

").append(errorMessage).append("

"); builder.append("Detail Messages:

"); messages.stream() .forEach(message -> { diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java index f453b4ee..983ae22e 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java @@ -144,6 +144,14 @@ public final class Result { return this.value; } + public T getOrThrow(final Function errorWrapper) { + if (this.error != null) { + throw errorWrapper.apply(this.error); + } + + return this.value; + } + /** Use this to get the resulting value or (if null) to get a given other value * * @param supplier supplier to get the value from if the computed value is null 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 84c44208..a728646d 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 @@ -173,15 +173,6 @@ public class SebExamConfigPropForm implements TemplateComposer { .putStaticValue( Domain.CONFIGURATION_NODE.ATTR_TYPE, ConfigurationType.EXAM_CONFIG.name()) - .addField(FormBuilder.text( - Domain.CONFIGURATION_NODE.ATTR_NAME, - FORM_NAME_TEXT_KEY, - examConfig.name)) - .addField(FormBuilder.text( - Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, - FORM_DESCRIPTION_TEXT_KEY, - examConfig.description) - .asArea()) .addFieldIf( () -> !examConfigTemplateResources.isEmpty(), () -> FormBuilder.singleSelection( @@ -192,11 +183,23 @@ public class SebExamConfigPropForm implements TemplateComposer { : String.valueOf(examConfig.templateId), resourceService::getExamConfigTemplateResources) .readonly(!isNew)) + .addField(FormBuilder.text( + Domain.CONFIGURATION_NODE.ATTR_NAME, + FORM_NAME_TEXT_KEY, + examConfig.name)) + .addField(FormBuilder.text( + Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, + FORM_DESCRIPTION_TEXT_KEY, + examConfig.description) + .asArea() + .withInputSpan(3)) + .addField(FormBuilder.singleSelection( Domain.CONFIGURATION_NODE.ATTR_STATUS, FORM_STATUS_TEXT_KEY, examConfig.status.name(), - () -> resourceService.examConfigStatusResources(isAttachedToExam))) + () -> resourceService.examConfigStatusResources(isAttachedToExam)) + .withEmptyCellSeparation(false)) .buildFor((isNew) ? this.restService.getRestCall(NewExamConfig.class) : this.restService.getRestCall(SaveExamConfig.class)); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java index 8571e490..d26360a9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java @@ -120,7 +120,7 @@ public class FormHandle { return resultAction; }) .onError(this::handleError) - .getOrThrow(); + .getOrThrow(error -> new FormPostException(error)); } public boolean handleError(final Exception error) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormPostException.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormPostException.java new file mode 100644 index 00000000..937ce71e --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormPostException.java @@ -0,0 +1,19 @@ +/* + * Copyright (c) 2019 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.form; + +public class FormPostException extends RuntimeException { + + private static final long serialVersionUID = 5693899812633519455L; + + public FormPostException(final Exception cause) { + super(cause); + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java index 518e9a76..a6fccfdb 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageAction.java @@ -22,6 +22,7 @@ import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gbl.util.Utils; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; +import ch.ethz.seb.sebserver.gui.form.FormPostException; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageContext.AttributeKeys; @@ -172,6 +173,12 @@ public final class PageAction { restCallError); } return Result.ofError(restCallError); + } catch (final FormPostException e) { + log.error("Failed to execute action: {} | error: {} | cause: {}", + PageAction.this.getName(), + e.getMessage(), + Utils.getErrorCauseMessage(e)); + return Result.ofError(e); } catch (final Exception e) { log.error("Failed to execute action: {} | error: {} | cause: {}", PageAction.this.getName(), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java index c8f4ab8f..781beddf 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/page/impl/PageContextImpl.java @@ -300,7 +300,7 @@ public class PageContextImpl implements PageContext { final MessageBox messageBox = new Message( getShell(), this.i18nSupport.getText("sebserver.error.unexpected"), - Utils.formatHTMLLines(errorMessage), + Utils.formatHTMLLines(errorMessage + "

Cause: " + error.getMessage()), SWT.ERROR); messageBox.open(null); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java index f6e8dabb..3dca7f00 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/Message.java @@ -14,6 +14,8 @@ import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.MessageBox; import org.eclipse.swt.widgets.Shell; +import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant; + public final class Message extends MessageBox { private static final int NORMAL_WIDTH = 400; @@ -28,6 +30,7 @@ public final class Message extends MessageBox { super(parent, type); super.setText(title); super.setMessage(message); + super.setMarkupEnabled(true); } @Override @@ -39,7 +42,8 @@ public final class Message extends MessageBox { layout.marginRight = 10; layout.verticalSpacing = 10; layout.horizontalSpacing = 10; - super.shell.setData(RWT.CUSTOM_VARIANT, "message"); + super.shell.setData(RWT.CUSTOM_VARIANT, CustomVariant.MESSAGE.key); + final Rectangle bounds = super.shell.getBounds(); if (bounds.width < NORMAL_WIDTH) { bounds.x = bounds.x - (NORMAL_WIDTH - bounds.width) / 2; diff --git a/src/main/resources/config/application-dev-ws.properties b/src/main/resources/config/application-dev-ws.properties index 1c39685e..fd3ad06c 100644 --- a/src/main/resources/config/application-dev-ws.properties +++ b/src/main/resources/config/application-dev-ws.properties @@ -15,9 +15,9 @@ spring.datasource.hikari.connectionTimeout=30000 spring.datasource.hikari.idleTimeout=600000 spring.datasource.hikari.maxLifetime=1800000 -sebserver.http.client.connect-timeout=1500 +sebserver.http.client.connect-timeout=15000 sebserver.http.client.connection-request-timeout=10000 -sebserver.http.client.read-timeout=1000 +sebserver.http.client.read-timeout=10000 # webservice configuration sebserver.webservice.distributed=false diff --git a/src/main/resources/messages.properties b/src/main/resources/messages.properties index 696f2f51..c038efd6 100644 --- a/src/main/resources/messages.properties +++ b/src/main/resources/messages.properties @@ -81,14 +81,14 @@ sebserver.dialog.confirm.title=Confirmation sebserver.dialog.confirm.deactivation=Note that there are {0} other entities that belongs to this entity.
Those will also be deactivated by deactivating this entity.

Are You sure to deactivate this entity? sebserver.dialog.confirm.deactivation.noDependencies=Are You sure you want to deactivate? -sebserver.error.action.unexpected.message=

Failed to process action. There was an unexpected error.
Please try again or contact a system-administrator if this error persists -sebserver.error.get.entity=

Failed to load {0}.
Please try again or contact a system-administrator if this error persists -sebserver.error.remove.entity=

Failed to remove {0}.
Please try again or contact a system-administrator if this error persists -sebserver.error.activate.entity=

Failed to activate/deactivate {0}.
Please try again or contact a system-administrator if this error persists -sebserver.error.save.entity=

Failed to save {0}.
Please try again or contact a system-administrator if this error persists +sebserver.error.action.unexpected.message=Failed to process action. There was an unexpected error.
Please try again or contact a system-administrator if this error persists +sebserver.error.get.entity=Failed to load {0}.
Please try again or contact a system-administrator if this error persists +sebserver.error.remove.entity=Failed to remove {0}.
Please try again or contact a system-administrator if this error persists +sebserver.error.activate.entity=Failed to activate/deactivate {0}.
Please try again or contact a system-administrator if this error persists +sebserver.error.save.entity=Failed to save {0}.
Please try again or contact a system-administrator if this error persists sebserver.error.exam.seb.restriction=

Failed to automatically set Safe Exam Browser restriction on/off for this exam on the corresponding LMS.
Please check the LMS Setup and try again or contact a system-administrator if this error persists -sebserver.error.import=

Failed to import {0}.
Please try again or contact a system-administrator if this error persists -sebserver.error.logout=

Failed to logout properly.
Please try again or contact a system-administrator if this error persists +sebserver.error.import=Failed to import {0}.
Please try again or contact a system-administrator if this error persists +sebserver.error.logout=Failed to logout properly.
Please try again or contact a system-administrator if this error persists ################################ # Login Page ################################ @@ -481,7 +481,7 @@ sebserver.examconfig.form.title=Exam Configuration sebserver.examconfig.form.name=Name sebserver.examconfig.form.description=Description sebserver.examconfig.form.with-history=With History -sebserver.examconfig.form.template=From Template +sebserver.examconfig.form.template=Template sebserver.examconfig.form.status=Status sebserver.examconfig.form.config-key.title=Config Key sebserver.examconfig.form.attched-to=Attached To Exam