fixes and prepare for demo

This commit is contained in:
anhefti 2019-06-06 09:07:54 +02:00
parent b18febb75f
commit 9e34312ef3
7 changed files with 49 additions and 30 deletions

View file

@ -11,4 +11,13 @@
<Match>
<Package name="ch.ethz.seb.sebserver.webservice.datalayer.batis.model"/>
</Match>
<Match>
<Class name="ch.ethz.seb.sebserver.gbl.api.ExamAPIDiscovery" />
<Bug pattern="URF_UNREAD_PUBLIC_OR_PROTECTED_FIELD" />
</Match>
<Match>
<Class name="ch.ethz.seb.sebserver.gui.widget.*" />
<Bug pattern="SE_BAD_FIELD" />
</Match>
</FindBugsFilter>

View file

@ -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();

View file

@ -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) {

View file

@ -241,11 +241,12 @@ public abstract class RestCall<T> {
}
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;

View file

@ -353,9 +353,14 @@ public class EntityTable<ROW extends Entity> {
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<ROW extends Entity> {
(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<ROW> 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);

View file

@ -61,6 +61,10 @@ public class TableFilter<ROW extends Entity> {
buildComponents();
}
public int size() {
return this.components.size();
}
public MultiValueMap<String, String> getFilterParameter() {
return this.components
.stream()

View file

@ -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),