From 9e34312ef3b9f704f911973810611ce4f8fd19df Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 6 Jun 2019 09:07:54 +0200 Subject: [PATCH] fixes and prepare for demo --- findbugs-excludes.xml | 9 +++++++ .../seb/sebserver/gbl/api/POSTMapper.java | 15 ++--------- .../ch/ethz/seb/sebserver/gbl/util/Utils.java | 25 ++++++++++++------- .../remote/webservice/api/RestCall.java | 5 ++-- .../seb/sebserver/gui/table/EntityTable.java | 19 ++++++++++---- .../seb/sebserver/gui/table/TableFilter.java | 4 +++ src/main/resources/data-demo.sql | 2 +- 7 files changed, 49 insertions(+), 30 deletions(-) diff --git a/findbugs-excludes.xml b/findbugs-excludes.xml index 61d2fba0..3d6358a7 100644 --- a/findbugs-excludes.xml +++ b/findbugs-excludes.xml @@ -11,4 +11,13 @@ + + + + + + + + + \ No newline at end of file diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java index f9fd3b5e..d48a3a14 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/POSTMapper.java @@ -8,8 +8,6 @@ package ch.ethz.seb.sebserver.gbl.api; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.nio.CharBuffer; import java.util.Arrays; import java.util.Collections; @@ -48,22 +46,13 @@ public class POSTMapper { } public String getString(final String name) { - final String first = this.params.getFirst(name); - if (StringUtils.isNotBlank(first)) { - try { - return URLDecoder.decode(first, "UTF-8"); - } catch (final UnsupportedEncodingException e) { - log.warn("Failed to decode form URL formatted string value: ", e); - return first; - } - } - return first; + return Utils.decodeFormURL_UTF_8(this.params.getFirst(name)); } public char[] getCharArray(final String name) { final String value = getString(name); if (value == null || value.length() <= 0) { - return null; + return new char[] {}; } return value.toCharArray(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java index 72a0b49d..70b7af05 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java @@ -8,7 +8,7 @@ package ch.ethz.seb.sebserver.gbl.util; -import java.io.UnsupportedEncodingException; +import java.net.URLDecoder; import java.net.URLEncoder; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -27,8 +27,6 @@ import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; import org.joda.time.DateTime; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; @@ -37,8 +35,6 @@ import ch.ethz.seb.sebserver.gbl.Constants; public final class Utils { - private static final Logger log = LoggerFactory.getLogger(Utils.class); - /** This Collector can be used within stream collect to get one expected singleton element from * the given Stream. * This first collects the given Stream to a list and then check if there is one expected element. @@ -211,12 +207,23 @@ public final class Utils { } public static final String encodeFormURL_UTF_8(final String value) { - try { - return URLEncoder.encode(value, StandardCharsets.UTF_8.name()); - } catch (final UnsupportedEncodingException e) { - log.error("Unexpected error while trying to encode to from URL UTF-8: ", e); + if (StringUtils.isBlank(value)) { return value; } + + return URLEncoder.encode(value, StandardCharsets.UTF_8); + } + + public static final String decodeFormURL_UTF_8(final String value) { + if (StringUtils.isBlank(value)) { + return value; + } + + return URLDecoder.decode( + (value.indexOf('+') >= 0) + ? value.replaceAll("\\+", "%2b") + : value, + StandardCharsets.UTF_8); } public static void clearCharArray(final char[] array) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java index c14354b2..18abfef4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/RestCall.java @@ -241,11 +241,12 @@ public abstract class RestCall { } public RestCallBuilder withFormParam(final String name, final String value) { + final String encodedVal = Utils.encodeFormURL_UTF_8(value); if (StringUtils.isBlank(this.body)) { - this.body = name + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + value; + this.body = name + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + encodedVal; } else { this.body = this.body + Constants.FORM_URL_ENCODED_SEPARATOR + name + - Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + value; + Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR + encodedVal; } return this; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java index f18e5c44..2825c938 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/EntityTable.java @@ -353,9 +353,14 @@ public class EntityTable { private void adaptColumnWidth(final Event event) { try { - final int currentTableWidth = this.table.getParent().getClientArea().width; - int index = 0; + int currentTableWidth = this.table.getParent().getClientArea().width; + // If we have all columns with filter we need some more space for the + // filter actions in the right hand side. This tweak gives enough space for that + if (this.filter != null && this.columns.size() == this.filter.size()) { + currentTableWidth -= 60; + } + // The proportion size, the sum of all given proportion values final int pSize = this.columns .stream() .filter(c -> c.getWidthProportion() > 0) @@ -363,14 +368,18 @@ public class EntityTable { (acc, c) -> acc + c.getWidthProportion(), (acc1, acc2) -> acc1 + acc2); - final int columnSize = (pSize > 0) + // The unit size either with proportion or for a entire column if all columns are equal in size + final int columnUnitSize = (pSize > 0) ? currentTableWidth / pSize : currentTableWidth / this.columns.size(); + // Apply the column width for each column + int index = 0; for (final ColumnDefinition column : this.columns) { - final TableColumn tableColumn = this.table.getColumn(index); - final int newWidth = (pSize > 0) ? columnSize * column.getWidthProportion() : columnSize; + final int newWidth = (pSize > 0) + ? columnUnitSize * column.getWidthProportion() + : columnUnitSize; tableColumn.setWidth(newWidth); if (this.filter != null) { this.filter.adaptColumnWidth(this.table.indexOf(tableColumn), newWidth); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java index a200d59a..c1dcc6c0 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/table/TableFilter.java @@ -61,6 +61,10 @@ public class TableFilter { buildComponents(); } + public int size() { + return this.components.size(); + } + public MultiValueMap getFilterParameter() { return this.components .stream() diff --git a/src/main/resources/data-demo.sql b/src/main/resources/data-demo.sql index 093a5145..d33baa1c 100644 --- a/src/main/resources/data-demo.sql +++ b/src/main/resources/data-demo.sql @@ -1,5 +1,5 @@ INSERT IGNORE INTO institution VALUES - (1, 'ETH Züich', 'ethz', null, null, 1), + (1, 'ETH Zürich', 'ethz', null, null, 1), (2, 'Institution 2', 'inst2', null, null, 1), (3, 'Institution 3', 'inst3', null, null, 0), (4, 'Institution 4', 'inst4', null, null, 0),