password input field and fixed compile error

This commit is contained in:
anhefti 2019-05-02 15:43:03 +02:00
parent f4af098a6f
commit 7bf8edaa54
19 changed files with 304 additions and 121 deletions

View file

@ -10,8 +10,6 @@ package ch.ethz.seb.sebserver.gui.service.examconfig;
import java.util.Collection; import java.util.Collection;
import org.eclipse.swt.widgets.Control;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
@ -24,8 +22,6 @@ public interface InputField {
void initValue(Collection<ConfigurationValue> values); void initValue(Collection<ConfigurationValue> values);
Control getControl();
void showError(String errorMessage); void showError(String errorMessage);
void clearError(); void clearError();

View file

@ -8,12 +8,17 @@
package ch.ethz.seb.sebserver.gui.service.examconfig; package ch.ethz.seb.sebserver.gui.service.examconfig;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.widget.WidgetFactory.CustomVariant;
public interface InputFieldBuilder { public interface InputFieldBuilder {
@ -28,8 +33,31 @@ public interface InputFieldBuilder {
final ConfigurationAttribute attribute, final ConfigurationAttribute attribute,
final ViewContext viewContext); final ViewContext viewContext);
static LocTextKey createResourceBundleKey(final String paramName, final String value) { static Composite createInnerGrid(
return new LocTextKey(RES_BUNDLE_KEY_PREFIX + paramName + "." + value); final Composite parent,
final Orientation orientation) {
final Composite comp = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 0;
gridLayout.marginHeight = 1;
comp.setLayout(gridLayout);
final GridData gridData = new GridData(
SWT.FILL, SWT.FILL,
true, false,
(orientation != null) ? orientation.width() : 1,
(orientation != null) ? orientation.height() : 1);
comp.setLayoutData(gridData);
return comp;
}
static Label createErrorLabel(final Composite innerGrid) {
final Label errorLabel = new Label(innerGrid, SWT.NONE);
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
errorLabel.setVisible(false);
errorLabel.setData(RWT.CUSTOM_VARIANT, CustomVariant.ERROR.key);
return errorLabel;
} }
} }

View file

@ -18,14 +18,17 @@ import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; import ch.ethz.seb.sebserver.gui.service.examconfig.InputField;
public abstract class ControlFieldAdapter<T extends Control> implements InputField { public abstract class AbstractInputField<T extends Control> implements InputField {
protected final ConfigurationAttribute attribute; protected final ConfigurationAttribute attribute;
protected final Orientation orientation; protected final Orientation orientation;
protected final T control; protected final T control;
protected final Label errorLabel; protected final Label errorLabel;
ControlFieldAdapter( protected String initValue = "";
protected int listIndex = 0;
AbstractInputField(
final ConfigurationAttribute attribute, final ConfigurationAttribute attribute,
final Orientation orientation, final Orientation orientation,
final T control, final T control,
@ -42,11 +45,6 @@ public abstract class ControlFieldAdapter<T extends Control> implements InputFie
return this.attribute; return this.attribute;
} }
@Override
public final Control getControl() {
return this.control;
}
@Override @Override
public void disable() { public void disable() {
if (this.control.isEnabled()) { if (this.control.isEnabled()) {
@ -89,7 +87,15 @@ public abstract class ControlFieldAdapter<T extends Control> implements InputFie
@Override @Override
public void initValue(final Collection<ConfigurationValue> values) { public void initValue(final Collection<ConfigurationValue> values) {
// Does Nothing for default values.stream()
.filter(a -> this.attribute.id.equals(a.attributeId))
.findFirst()
.map(v -> {
this.initValue = v.value;
this.listIndex = (v.listIndex != null) ? v.listIndex : 0;
setDefaultValue();
return this.initValue;
});
} }
protected abstract void setDefaultValue(); protected abstract void setDefaultValue();

View file

@ -8,7 +8,6 @@
package ch.ethz.seb.sebserver.gui.service.examconfig.impl; package ch.ethz.seb.sebserver.gui.service.examconfig.impl;
import java.util.Collection;
import java.util.Objects; import java.util.Objects;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
@ -19,7 +18,6 @@ import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; import ch.ethz.seb.sebserver.gui.service.examconfig.InputField;
@ -72,9 +70,7 @@ public class CheckBoxBuilder implements InputFieldBuilder {
checkbox); checkbox);
} }
static final class CheckboxField extends ControlFieldAdapter<Button> { static final class CheckboxField extends AbstractInputField<Button> {
private boolean initValue = false;
CheckboxField( CheckboxField(
final ConfigurationAttribute attribute, final ConfigurationAttribute attribute,
@ -84,21 +80,9 @@ public class CheckBoxBuilder implements InputFieldBuilder {
super(attribute, orientation, control, null); super(attribute, orientation, control, null);
} }
@Override
public void initValue(final Collection<ConfigurationValue> values) {
values.stream()
.filter(v -> this.attribute.id.equals(v.attributeId))
.findFirst()
.map(v -> {
this.initValue = Boolean.valueOf(v.value);
this.control.setSelection(this.initValue);
return this.initValue;
});
}
@Override @Override
protected void setDefaultValue() { protected void setDefaultValue() {
this.control.setSelection(this.initValue); this.control.setSelection(Boolean.valueOf(this.initValue));
} }
} }

View file

@ -25,6 +25,8 @@ import org.springframework.stereotype.Service;
import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.Constants;
import ch.ethz.seb.sebserver.gbl.api.API; import ch.ethz.seb.sebserver.gbl.api.API;
import ch.ethz.seb.sebserver.gbl.api.APIMessage;
import ch.ethz.seb.sebserver.gbl.api.APIMessage.ErrorMessage;
import ch.ethz.seb.sebserver.gbl.api.JSONMapper; import ch.ethz.seb.sebserver.gbl.api.JSONMapper;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
@ -39,7 +41,10 @@ import ch.ethz.seb.sebserver.gui.service.examconfig.ExamConfigurationService;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder; import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder;
import ch.ethz.seb.sebserver.gui.service.examconfig.ValueChangeListener; import ch.ethz.seb.sebserver.gui.service.examconfig.ValueChangeListener;
import ch.ethz.seb.sebserver.gui.service.examconfig.ValueChangeRule; import ch.ethz.seb.sebserver.gui.service.examconfig.ValueChangeRule;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
import ch.ethz.seb.sebserver.gui.service.page.FieldValidationError;
import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageContext;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestCallError;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigAttributes; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigAttributes;
import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationValues; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurationValues;
@ -162,9 +167,7 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
public Composite createViewGrid(final Composite parent, final ViewContext viewContext) { public Composite createViewGrid(final Composite parent, final ViewContext viewContext) {
final Composite composite = new Composite(parent, SWT.NONE); final Composite composite = new Composite(parent, SWT.NONE);
final GridLayout gridLayout = new GridLayout(viewContext.columns, true); final GridLayout gridLayout = new GridLayout(viewContext.columns, true);
gridLayout.marginTop = 10; gridLayout.verticalSpacing = 0;
gridLayout.verticalSpacing = 5;
gridLayout.horizontalSpacing = 10;
composite.setLayout(gridLayout); composite.setLayout(gridLayout);
composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
@ -208,6 +211,8 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
private static final class ValueChangeListenerImpl implements ValueChangeListener { private static final class ValueChangeListenerImpl implements ValueChangeListener {
public static final String VALIDATION_ERROR_KEY_PREFIX = "sebserver.examconfig.props.validation.";
private final PageContext pageContext; private final PageContext pageContext;
private final RestService restService; private final RestService restService;
private final JSONMapper jsonMapper; private final JSONMapper jsonMapper;
@ -267,8 +272,25 @@ public class ExamConfigurationServiceImpl implements ExamConfigurationService {
} }
private String verifyErrorMessage(final Throwable error) { private String verifyErrorMessage(final Throwable error) {
// TODO Auto-generated method stub if (error instanceof RestCallError) {
return "TODO"; final List<APIMessage> errorMessages = ((RestCallError) error).getErrorMessages();
if (errorMessages.isEmpty()) {
return "";
}
final APIMessage apiMessage = errorMessages.get(0);
if (!ErrorMessage.FIELD_VALIDATION.isOf(apiMessage)) {
return "";
}
final FieldValidationError fieldValidationError = new FieldValidationError(apiMessage);
return this.pageContext.getI18nSupport().getText(new LocTextKey(
VALIDATION_ERROR_KEY_PREFIX + fieldValidationError.errorType,
(Object[]) fieldValidationError.getAttributes()));
}
log.warn("Unexpected error happened while trying to set SEB configuration value: ", error);
return VALIDATION_ERROR_KEY_PREFIX + "unexpected";
} }
} }

View file

@ -59,7 +59,7 @@ public class LabelBuilder implements InputFieldBuilder {
label); label);
} }
static final class LabelField extends ControlFieldAdapter<Label> { static final class LabelField extends AbstractInputField<Label> {
LabelField( LabelField(
final ConfigurationAttribute attribute, final ConfigurationAttribute attribute,

View file

@ -0,0 +1,117 @@
/*
* 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.service.examconfig.impl;
import org.apache.commons.lang3.StringUtils;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputField;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder;
public class PassworFieldBuilder implements InputFieldBuilder {
@Override
public boolean builderFor(
final ConfigurationAttribute attribute,
final Orientation orientation) {
if (attribute == null) {
return false;
}
return AttributeType.PASSWORD_FIELD == attribute.type;
}
@Override
public InputField createInputField(
final Composite parent,
final ConfigurationAttribute attribute,
final ViewContext viewContext) {
final Orientation orientation = viewContext.attributeMapping
.getOrientation(attribute.id);
final Composite innerGrid = InputFieldBuilder
.createInnerGrid(parent, orientation);
final Text passwordInput = new Text(innerGrid, SWT.LEFT | SWT.BORDER | SWT.PASSWORD);
passwordInput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final Text confirmInput = new Text(innerGrid, SWT.LEFT | SWT.BORDER | SWT.PASSWORD);
confirmInput.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final PasswordInputField passwordInputField = new PasswordInputField(
attribute,
orientation,
passwordInput,
confirmInput,
InputFieldBuilder.createErrorLabel(innerGrid));
final Listener valueChangeEventListener = event -> {
final String pwd = passwordInput.getText();
final String confirm = confirmInput.getText();
if (StringUtils.isBlank(pwd) && StringUtils.isBlank(confirm)) {
return;
}
if (!pwd.equals(confirm)) {
passwordInputField.showError("TODO confirm password message");
return;
}
// TODO hash password
passwordInputField.clearError();
viewContext.getValueChangeListener().valueChanged(
viewContext,
attribute,
pwd,
passwordInputField.listIndex);
};
passwordInput.addListener(SWT.FocusOut, valueChangeEventListener);
passwordInput.addListener(SWT.Traverse, valueChangeEventListener);
confirmInput.addListener(SWT.FocusOut, valueChangeEventListener);
confirmInput.addListener(SWT.Traverse, valueChangeEventListener);
return passwordInputField;
}
static final class PasswordInputField extends AbstractInputField<Text> {
private final Text confirm;
PasswordInputField(
final ConfigurationAttribute attribute,
final Orientation orientation,
final Text control,
final Text confirm,
final Label errorLabel) {
super(attribute, orientation, control, errorLabel);
this.confirm = confirm;
}
@Override
protected void setDefaultValue() {
// TODO clarify setting some "fake" input when a password is set (like in config tool)
this.control.setText(this.initValue);
this.confirm.setText(this.initValue);
}
}
}

View file

@ -8,26 +8,21 @@
package ch.ethz.seb.sebserver.gui.service.examconfig.impl; package ch.ethz.seb.sebserver.gui.service.examconfig.impl;
import java.util.Collection;
import org.eclipse.rap.rwt.RWT;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType; import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation; import ch.ethz.seb.sebserver.gbl.model.sebconfig.Orientation;
import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputField; import ch.ethz.seb.sebserver.gui.service.examconfig.InputField;
import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder; import ch.ethz.seb.sebserver.gui.service.examconfig.InputFieldBuilder;
import ch.ethz.seb.sebserver.gui.service.examconfig.ValueChangeListener;
@Lazy @Lazy
@Component @Component
@ -57,53 +52,40 @@ public class TextFieldBuilder implements InputFieldBuilder {
final Orientation orientation = viewContext.attributeMapping final Orientation orientation = viewContext.attributeMapping
.getOrientation(attribute.id); .getOrientation(attribute.id);
final Composite innerGrid = InputFieldBuilder
final Composite comp = new Composite(parent, SWT.NONE); .createInnerGrid(parent, orientation);
final GridLayout gridLayout = new GridLayout();
gridLayout.verticalSpacing = 0;
comp.setLayout(gridLayout);
final GridData gridData = new GridData(
SWT.FILL, SWT.FILL,
true, false,
(orientation != null) ? orientation.width() : 1,
(orientation != null) ? orientation.height() : 1);
comp.setLayoutData(gridData);
final Text text; final Text text;
if (attribute.type == AttributeType.INTEGER || if (attribute.type == AttributeType.INTEGER ||
attribute.type == AttributeType.DECIMAL) { attribute.type == AttributeType.DECIMAL) {
text = new Text(comp, SWT.RIGHT | SWT.BORDER); text = new Text(innerGrid, SWT.RIGHT | SWT.BORDER);
} else { } else {
text = new Text(comp, SWT.LEFT | SWT.BORDER); text = new Text(innerGrid, SWT.LEFT | SWT.BORDER);
} }
text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
final Label errorLabel = new Label(comp, SWT.NONE); final TextInputField textInputField = new TextInputField(
errorLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); attribute,
errorLabel.setVisible(false); orientation,
errorLabel.setData(RWT.CUSTOM_VARIANT, "error"); text,
InputFieldBuilder.createErrorLabel(innerGrid));
final TextInputField textInputField = new TextInputField(attribute, orientation, text, errorLabel); final Listener valueChangeEventListener = event -> {
final ValueChangeListener valueListener = viewContext.getValueChangeListener(); textInputField.clearError();
text.addListener( viewContext.getValueChangeListener().valueChanged(
SWT.FocusOut, viewContext,
event -> { attribute,
textInputField.clearError(); String.valueOf(text.getText()),
valueListener.valueChanged( textInputField.listIndex);
viewContext, };
attribute,
String.valueOf(text.getText()),
textInputField.listIndex);
});
text.addListener(SWT.FocusOut, valueChangeEventListener);
text.addListener(SWT.Traverse, valueChangeEventListener);
return textInputField; return textInputField;
} }
static final class TextInputField extends ControlFieldAdapter<Text> { static final class TextInputField extends AbstractInputField<Text> {
private String initValue = "";
private int listIndex = 0;
TextInputField( TextInputField(
final ConfigurationAttribute attribute, final ConfigurationAttribute attribute,
@ -114,19 +96,6 @@ public class TextFieldBuilder implements InputFieldBuilder {
super(attribute, orientation, control, errorLabel); super(attribute, orientation, control, errorLabel);
} }
@Override
public void initValue(final Collection<ConfigurationValue> values) {
values.stream()
.filter(a -> this.attribute.id.equals(a.attributeId))
.findFirst()
.map(v -> {
this.initValue = v.value;
this.listIndex = (v.listIndex != null) ? v.listIndex : 0;
setDefaultValue();
return this.initValue;
});
}
@Override @Override
protected void setDefaultValue() { protected void setDefaultValue() {
this.control.setText(this.initValue); this.control.setText(this.initValue);

View file

@ -46,8 +46,6 @@ public class ViewGridBuilder {
this.viewContext = viewContext; this.viewContext = viewContext;
this.grid = new CellFieldBuilderAdapter[viewContext.rows][viewContext.columns]; this.grid = new CellFieldBuilderAdapter[viewContext.rows][viewContext.columns];
this.registeredGroups = new HashSet<>(); this.registeredGroups = new HashSet<>();
fillDummy(0, 0, viewContext.columns, viewContext.rows);
} }
ViewGridBuilder add(final ConfigurationAttribute attribute) { ViewGridBuilder add(final ConfigurationAttribute attribute) {
@ -78,6 +76,10 @@ public class ViewGridBuilder {
final int xpos = orientation.xpos(); final int xpos = orientation.xpos();
final int ypos = orientation.ypos(); final int ypos = orientation.ypos();
if (orientation.width > 1 || orientation.height > 1) {
fillDummy(xpos, ypos, orientation.width, orientation.height);
}
final InputFieldBuilder inputFieldBuilder = this.examConfigurationService.getInputFieldBuilder( final InputFieldBuilder inputFieldBuilder = this.examConfigurationService.getInputFieldBuilder(
attribute, attribute,
orientation); orientation);
@ -114,7 +116,8 @@ public class ViewGridBuilder {
for (int x = 0; x < this.grid[y].length; x++) { for (int x = 0; x < this.grid[y].length; x++) {
if (this.grid[y][x] == null) { if (this.grid[y][x] == null) {
final Label empty = new Label(this.parent, SWT.LEFT); final Label empty = new Label(this.parent, SWT.LEFT);
empty.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); final GridData gridData = new GridData(SWT.FILL, SWT.FILL, true, false);
empty.setLayoutData(gridData);
empty.setText(""); empty.setText("");
} else { } else {
this.grid[y][x].createCell(this); this.grid[y][x].createCell(this);
@ -149,10 +152,6 @@ public class ViewGridBuilder {
attribute, attribute,
ViewGridBuilder.this.viewContext); ViewGridBuilder.this.viewContext);
// final Orientation orientation =
// ViewGridBuilder.this.viewContext.attributeMapping.getOrientation(attribute.id);
//
// //inputField.setSpan(orientation.width, orientation.height);
ViewGridBuilder.this.viewContext.registerInputField(inputField); ViewGridBuilder.this.viewContext.registerInputField(inputField);
} }
}; };
@ -257,13 +256,6 @@ public class ViewGridBuilder {
attr, attr,
this.builder.viewContext); this.builder.viewContext);
final GridData gridData = new GridData(
SWT.FILL, SWT.FILL,
true, false,
orientation.width(), orientation.height());
inputField.getControl().setLayoutData(gridData);
inputField.getControl().setToolTipText(attr.name);
this.builder.viewContext.registerInputField(inputField); this.builder.viewContext.registerInputField(inputField);
} }
} }

View file

@ -16,6 +16,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.EntityKey;
import ch.ethz.seb.sebserver.gui.service.i18n.I18nSupport;
import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey;
/** Holds a page-context and defines some convenient functionality for page handling */ /** Holds a page-context and defines some convenient functionality for page handling */
@ -39,6 +40,11 @@ public interface PageContext {
} }
/** Get the I18nSupport service
*
* @return the I18nSupport service */
I18nSupport getI18nSupport();
/** Use this to get the ComposerService used by this PageContext /** Use this to get the ComposerService used by this PageContext
* *
* @return the ComposerService used by this PageContext */ * @return the ComposerService used by this PageContext */

View file

@ -59,6 +59,11 @@ public class PageContextImpl implements PageContext {
this.attributes = Utils.immutableMapOf(attributes); this.attributes = Utils.immutableMapOf(attributes);
} }
@Override
public I18nSupport getI18nSupport() {
return this.i18nSupport;
}
@Override @Override
public Shell getShell() { public Shell getShell() {
if (this.root == null) { if (this.root == null) {
@ -328,5 +333,4 @@ public class PageContextImpl implements PageContext {
this.onOK.accept(false); this.onOK.accept(false);
} }
} }
} }

View file

@ -117,7 +117,8 @@ public class WidgetFactory {
FOOTER("footer"), FOOTER("footer"),
TITLE_LABEL("head"), TITLE_LABEL("head"),
MESSAGE("message") MESSAGE("message"),
ERROR("error")
; ;

View file

@ -12,8 +12,6 @@ import java.io.UnsupportedEncodingException;
import java.security.SecureRandom; import java.security.SecureRandom;
import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.RandomStringUtils;
import org.cryptonode.jncryptor.AES256JNCryptor;
import org.cryptonode.jncryptor.JNCryptor;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Lazy; import org.springframework.context.annotation.Lazy;
@ -36,9 +34,6 @@ public class ClientCredentialServiceImpl implements ClientCredentialService {
private final Environment environment; private final Environment environment;
// TODO try to integrate with JNCryptor since this is also used by SEB
private final JNCryptor cryptor = new AES256JNCryptor();
protected ClientCredentialServiceImpl(final Environment environment) { protected ClientCredentialServiceImpl(final Environment environment) {
this.environment = environment; this.environment = environment;
} }

View file

@ -35,7 +35,13 @@ public interface ConfigurationValueValidator {
final ConfigurationValue value, final ConfigurationValue value,
final ConfigurationAttribute attribute) { final ConfigurationAttribute attribute) {
return "examConfigValue:" + attribute.name + ":" + name() + ":" + value.listIndex; return new StringBuffer("examConfigValue:")
.append(attribute.name)
.append(":")
.append(name())
.append(":")
.append(value.listIndex)
.toString();
} }
} }

View file

@ -0,0 +1,55 @@
/*
* 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.webservice.servicelayer.sebconfig.impl;
import org.apache.commons.lang3.StringUtils;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.AttributeType;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute;
import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue;
import ch.ethz.seb.sebserver.gbl.profile.WebServiceProfile;
import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConfigurationValueValidator;
@Lazy
@Component
@WebServiceProfile
public class DecimalTypeValidator implements ConfigurationValueValidator {
@Override
public String name() {
return AttributeType.DECIMAL.name();
}
@Override
public boolean validate(
final ConfigurationValue value,
final ConfigurationAttribute attribute) {
// if value is not an integer type or another specific validation is defined --> skip
if (attribute.type != AttributeType.DECIMAL ||
StringUtils.isNoneBlank(attribute.validator)) {
return true;
}
if (StringUtils.isBlank(value.value)) {
return true;
}
try {
Double.parseDouble(value.value);
return true;
} catch (final NumberFormatException nfe) {
return false;
}
}
}

View file

@ -21,7 +21,7 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.sebconfig.ConfigurationValu
@Lazy @Lazy
@Component @Component
@WebServiceProfile @WebServiceProfile
public class IntegerTypeValueValidator implements ConfigurationValueValidator { public class IntegerTypeValidator implements ConfigurationValueValidator {
@Override @Override
public String name() { public String name() {

View file

@ -154,7 +154,8 @@ public final class SebConfigEncryptionServiceImpl implements SebConfigEncryption
input.get(b); input.get(b);
return ByteBuffer.wrap(b).asReadOnlyBuffer(); return ByteBuffer.wrap(b).asReadOnlyBuffer();
} else { } else {
return input.clear().asReadOnlyBuffer(); input.clear();
return input.asReadOnlyBuffer();
} }
} }

View file

@ -31,7 +31,6 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.PaginationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService; import ch.ethz.seb.sebserver.webservice.servicelayer.authorization.AuthorizationService;
import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService; import ch.ethz.seb.sebserver.webservice.servicelayer.bulkaction.BulkActionService;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.ConfigurationNodeDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO; import ch.ethz.seb.sebserver.webservice.servicelayer.dao.UserActivityLogDAO;
import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService; import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationService;
@ -41,7 +40,6 @@ import ch.ethz.seb.sebserver.webservice.servicelayer.validation.BeanValidationSe
public class ConfigurationController extends EntityController<Configuration, Configuration> { public class ConfigurationController extends EntityController<Configuration, Configuration> {
private final ConfigurationDAO configurationDAO; private final ConfigurationDAO configurationDAO;
private final ConfigurationNodeDAO configurationNodeDAO;
protected ConfigurationController( protected ConfigurationController(
final AuthorizationService authorization, final AuthorizationService authorization,
@ -49,8 +47,7 @@ public class ConfigurationController extends EntityController<Configuration, Con
final ConfigurationDAO entityDAO, final ConfigurationDAO entityDAO,
final UserActivityLogDAO userActivityLogDAO, final UserActivityLogDAO userActivityLogDAO,
final PaginationService paginationService, final PaginationService paginationService,
final BeanValidationService beanValidationService, final BeanValidationService beanValidationService) {
final ConfigurationNodeDAO configurationNodeDAO) {
super(authorization, super(authorization,
bulkActionService, bulkActionService,
@ -60,7 +57,6 @@ public class ConfigurationController extends EntityController<Configuration, Con
beanValidationService); beanValidationService);
this.configurationDAO = entityDAO; this.configurationDAO = entityDAO;
this.configurationNodeDAO = configurationNodeDAO;
} }
@RequestMapping( @RequestMapping(

View file

@ -374,4 +374,9 @@ sebserver.examconfig.props.form.views.testView=Test View
sebserver.examconfig.props.form.views.testView.tooltip=This is a test View sebserver.examconfig.props.form.views.testView.tooltip=This is a test View
sebserver.examconfig.props.action.list.modify=Edit Properties sebserver.examconfig.props.action.list.modify=Edit Properties
sebserver.examconfig.props.label.testNumber=Test Number sebserver.examconfig.props.label.testNumber1=Test Number 1
sebserver.examconfig.props.label.testNumber2=Test Number 2
sebserver.examconfig.props.validation.unexpected=Unexpected error happened. Value was not set correctly
sebserver.examconfig.props.validation.INTEGER=Invalid number
sebserver.examconfig.props.validation.DECIMAL=Invalid decimal number