fixes for testing
This commit is contained in:
parent
7afa633a3c
commit
cee8e27fe2
1 changed files with 64 additions and 27 deletions
|
@ -37,6 +37,7 @@ import ch.ethz.seb.sebserver.gbl.util.Utils;
|
||||||
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.FormBinding;
|
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.FormBinding;
|
||||||
import ch.ethz.seb.sebserver.gui.widget.ImageUpload;
|
import ch.ethz.seb.sebserver.gui.widget.ImageUpload;
|
||||||
import ch.ethz.seb.sebserver.gui.widget.Selection;
|
import ch.ethz.seb.sebserver.gui.widget.Selection;
|
||||||
|
import ch.ethz.seb.sebserver.gui.widget.Selection.Type;
|
||||||
import ch.ethz.seb.sebserver.gui.widget.ThresholdList;
|
import ch.ethz.seb.sebserver.gui.widget.ThresholdList;
|
||||||
|
|
||||||
public final class Form implements FormBinding {
|
public final class Form implements FormBinding {
|
||||||
|
@ -70,11 +71,26 @@ public final class Form implements FormBinding {
|
||||||
appendFormUrlEncodedValue(buffer, entry.getKey(), entry.getValue());
|
appendFormUrlEncodedValue(buffer, entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
for (final Map.Entry<String, List<FormFieldAccessor>> entry : this.formFields.entrySet()) {
|
this.formFields.entrySet()
|
||||||
|
.stream()
|
||||||
|
.forEach(entry -> {
|
||||||
entry.getValue()
|
entry.getValue()
|
||||||
.stream()
|
.stream()
|
||||||
.forEach(ffa -> appendFormUrlEncodedValue(buffer, entry.getKey(), ffa.getStringValue()));
|
.forEach(ffa -> {
|
||||||
|
if (ffa.listValue) {
|
||||||
|
appendFormUrlEncodedValue(
|
||||||
|
buffer,
|
||||||
|
entry.getKey(),
|
||||||
|
ffa.getStringValue());
|
||||||
|
} else {
|
||||||
|
appendFormUrlEncodedSingleValue(
|
||||||
|
buffer,
|
||||||
|
entry.getKey(),
|
||||||
|
ffa.getStringValue(),
|
||||||
|
false);
|
||||||
}
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
return buffer.toString();
|
return buffer.toString();
|
||||||
}
|
}
|
||||||
|
@ -212,7 +228,11 @@ public final class Form implements FormBinding {
|
||||||
final Selection selection,
|
final Selection selection,
|
||||||
final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter) {
|
final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter) {
|
||||||
|
|
||||||
return new FormFieldAccessor(label, selection.adaptToControl(), jsonValueAdapter) {
|
return new FormFieldAccessor(
|
||||||
|
label,
|
||||||
|
selection.adaptToControl(),
|
||||||
|
jsonValueAdapter,
|
||||||
|
selection.type() != Type.SINGLE) {
|
||||||
@Override public String getStringValue() { return selection.getSelectionValue(); }
|
@Override public String getStringValue() { return selection.getSelectionValue(); }
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -246,15 +266,29 @@ public final class Form implements FormBinding {
|
||||||
* Checks first if the value String is a comma separated list. If true, splits values
|
* Checks first if the value String is a comma separated list. If true, splits values
|
||||||
* and adds every value within the same name mapping to the string buffer
|
* and adds every value within the same name mapping to the string buffer
|
||||||
*/
|
*/
|
||||||
private static void appendFormUrlEncodedValue(final StringBuffer buffer, final String name, final String value) {
|
private static void appendFormUrlEncodedValue(
|
||||||
|
final StringBuffer buffer,
|
||||||
|
final String name,
|
||||||
|
final String value) {
|
||||||
|
|
||||||
if (StringUtils.isBlank(value)) {
|
if (StringUtils.isBlank(value)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
final String[] split = StringUtils.split(value, Constants.LIST_SEPARATOR_CHAR);
|
final String[] split = StringUtils.split(value, Constants.LIST_SEPARATOR_CHAR);
|
||||||
for (int i = 0; i < split.length; i++) {
|
for (int i = 0; i < split.length; i++) {
|
||||||
if (StringUtils.isBlank(split[i])) {
|
appendFormUrlEncodedSingleValue(buffer, name, split[i], true);
|
||||||
continue;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void appendFormUrlEncodedSingleValue(
|
||||||
|
final StringBuffer buffer,
|
||||||
|
final String name,
|
||||||
|
final String value,
|
||||||
|
final boolean checkMultiValue) {
|
||||||
|
|
||||||
|
if (StringUtils.isBlank(value)) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (buffer.length() > 0) {
|
if (buffer.length() > 0) {
|
||||||
|
@ -263,22 +297,22 @@ public final class Form implements FormBinding {
|
||||||
|
|
||||||
// check of the string value is a name-value pair. If true, use the specified name an value
|
// check of the string value is a name-value pair. If true, use the specified name an value
|
||||||
// otherwise use the general name given within this method call and
|
// otherwise use the general name given within this method call and
|
||||||
if (split[i].contains(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)) {
|
if (checkMultiValue && value.contains(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)) {
|
||||||
final String[] nameValue = StringUtils.split(split[i], Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR);
|
final String[] nameValue = StringUtils.split(value, Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR);
|
||||||
buffer.append(nameValue[0])
|
buffer.append(nameValue[0])
|
||||||
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
|
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
|
||||||
.append(Utils.encodeFormURL_UTF_8(nameValue[1]));
|
.append(Utils.encodeFormURL_UTF_8(nameValue[1]));
|
||||||
} else {
|
} else {
|
||||||
buffer.append(name)
|
buffer.append(name)
|
||||||
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
|
.append(Constants.FORM_URL_ENCODED_NAME_VALUE_SEPARATOR)
|
||||||
.append(Utils.encodeFormURL_UTF_8(split[i]));
|
.append(Utils.encodeFormURL_UTF_8(value));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final void adaptCommaSeparatedStringToJsonArray(
|
private static final void adaptCommaSeparatedStringToJsonArray(
|
||||||
final Tuple<String> tuple,
|
final Tuple<String> tuple,
|
||||||
final ObjectNode jsonNode) {
|
final ObjectNode jsonNode) {
|
||||||
|
|
||||||
if (StringUtils.isNoneBlank(tuple._2)) {
|
if (StringUtils.isNoneBlank(tuple._2)) {
|
||||||
final ArrayNode arrayNode = jsonNode.putArray(tuple._1);
|
final ArrayNode arrayNode = jsonNode.putArray(tuple._1);
|
||||||
final String[] split = StringUtils.split(tuple._2, Constants.LIST_SEPARATOR);
|
final String[] split = StringUtils.split(tuple._2, Constants.LIST_SEPARATOR);
|
||||||
|
@ -294,15 +328,17 @@ public final class Form implements FormBinding {
|
||||||
public final Control control;
|
public final Control control;
|
||||||
private final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter;
|
private final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter;
|
||||||
private boolean hasError;
|
private boolean hasError;
|
||||||
|
private final boolean listValue;
|
||||||
|
|
||||||
FormFieldAccessor(final Label label, final Control control) {
|
FormFieldAccessor(final Label label, final Control control) {
|
||||||
this(label, control, null);
|
this(label, control, null, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
FormFieldAccessor(
|
FormFieldAccessor(
|
||||||
final Label label,
|
final Label label,
|
||||||
final Control control,
|
final Control control,
|
||||||
final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter) {
|
final BiConsumer<Tuple<String>, ObjectNode> jsonValueAdapter,
|
||||||
|
final boolean listValue) {
|
||||||
|
|
||||||
this.label = label;
|
this.label = label;
|
||||||
this.control = control;
|
this.control = control;
|
||||||
|
@ -315,6 +351,7 @@ public final class Form implements FormBinding {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
this.listValue = listValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract String getStringValue();
|
public abstract String getStringValue();
|
||||||
|
|
Loading…
Reference in a new issue