config and template fixes

This commit is contained in:
anhefti 2019-11-14 16:42:02 +01:00
parent 33bd16d55a
commit fc1c6182d3
3 changed files with 68 additions and 20 deletions

View file

@ -72,7 +72,7 @@ public class TextFieldBuilder implements InputFieldBuilder {
switch (attribute.type) {
case INTEGER:
case DECIMAL: {
text = new Text(innerGrid, SWT.RIGHT | SWT.BORDER);
text = new Text(innerGrid, SWT.RIGHT | SWT.BORDER | SWT.SINGLE);
break;
}
case TEXT_AREA: {
@ -81,7 +81,8 @@ public class TextFieldBuilder implements InputFieldBuilder {
break;
}
default: {
text = new Text(innerGrid, SWT.LEFT | SWT.BORDER);
text = new Text(innerGrid, SWT.LEFT | SWT.BORDER | SWT.SINGLE);
gridData.minimumHeight = WidgetFactory.TEXT_INPUT_MIN_HEIGHT;
break;
}
}
@ -147,6 +148,22 @@ public class TextFieldBuilder implements InputFieldBuilder {
this.control.setText(value);
}
@Override
public void enable(final boolean group) {
this.control.setData(RWT.CUSTOM_VARIANT, null);
this.control.setEditable(true);
}
@Override
public void disable(final boolean group) {
this.control.setData(RWT.CUSTOM_VARIANT, CustomVariant.CONFIG_INPUT_READONLY.key);
this.control.setEditable(false);
final GridData gridData = (GridData) this.control.getLayoutData();
gridData.heightHint = (this.attribute.type == AttributeType.TEXT_AREA)
? WidgetFactory.TEXT_AREA_INPUT_MIN_HEIGHT
: WidgetFactory.TEXT_INPUT_MIN_HEIGHT;
}
@Override
public String getValue() {
return this.control.getText();

View file

@ -28,12 +28,20 @@ import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext;
public class ProxyPasswordRule implements ValueChangeRule {
public static final String KEY_HTTP_PWD_REQUIRED = "HTTPRequiresPassword";
public static final String KEY_HTTPS_PWD_REQUIRED = "HTTPSRequiresPassword";
public static final String KEY_FTP_PWD_REQUIRED = "FTPRequiresPassword";
public static final String KEY_SOCKS_PWD_REQUIRED = "SOCKSRequiresPassword";
public static final String KEY_RTSP_PWD_REQUIRED = "RTSPRequiresPassword";
private final Map<String, Tuple<String>> observed;
public ProxyPasswordRule() {
this.observed = new HashMap<>();
this.observed.put(KEY_HTTP_PWD_REQUIRED, new Tuple<>("HTTPUsername", "HTTPPassword"));
this.observed.put(KEY_HTTPS_PWD_REQUIRED, new Tuple<>("HTTPSUsername", "HTTPSPassword"));
this.observed.put(KEY_FTP_PWD_REQUIRED, new Tuple<>("FTPUsername", "FTPPassword"));
this.observed.put(KEY_SOCKS_PWD_REQUIRED, new Tuple<>("SOCKSUsername", "SOCKSPassword"));
this.observed.put(KEY_RTSP_PWD_REQUIRED, new Tuple<>("RTSPUsername", "RTSPPassword"));
}
@Override

View file

@ -674,11 +674,7 @@ class ConfigurationDAOBatchService {
return Result.tryCatch(() -> {
// templateValues to override default values if available
final Map<Long, String> templateValues = getTemplateValues(configNode);
// go through all configuration attributes and create and store a
// configuration value from either the default value or the value from the template
// go through all configuration attributes and create and store the default value
this.batchConfigurationAttributeRecordMapper
.selectByExample()
.build()
@ -687,17 +683,49 @@ class ConfigurationDAOBatchService {
// filter child attributes of tables. No default value for tables. Use templates for that
.filter(ConfigurationDAOBatchService::filterChildAttribute)
.forEach(attrRec -> {
final String value = templateValues.getOrDefault(
attrRec.getId(),
attrRec.getDefaultValue());
this.batchConfigurationValueRecordMapper.insert(new ConfigurationValueRecord(
null,
configNode.institutionId,
config.getId(),
attrRec.getId(),
0,
value));
attrRec.getDefaultValue()));
});
// override with template values if available
final List<ConfigurationValueRecord> templateValues = getTemplateValues(configNode);
templateValues.stream()
.forEach(templateValue -> {
final Long existingId = this.batchConfigurationValueRecordMapper
.selectIdsByExample()
.where(
ConfigurationValueRecordDynamicSqlSupport.configurationId,
isEqualTo(config.getId()))
.and(
ConfigurationValueRecordDynamicSqlSupport.configurationAttributeId,
isEqualTo(templateValue.getConfigurationAttributeId()))
.and(
ConfigurationValueRecordDynamicSqlSupport.listIndex,
isEqualTo(templateValue.getListIndex()))
.build()
.execute()
.stream()
.findFirst()
.orElse(null);
final ConfigurationValueRecord valueRec = new ConfigurationValueRecord(
existingId,
configNode.institutionId,
config.getId(),
templateValue.getConfigurationAttributeId(),
templateValue.getListIndex(),
templateValue.getValue());
if (existingId != null) {
this.batchConfigurationValueRecordMapper.updateByPrimaryKey(valueRec);
} else {
this.batchConfigurationValueRecordMapper.insert(valueRec);
}
});
this.batchSqlSessionTemplate.flushStatements();
@ -721,9 +749,9 @@ class ConfigurationDAOBatchService {
* Get values from template with configuration attribute id mapped to the value
* returns empty list if no template available
*/
private Map<Long, String> getTemplateValues(final ConfigurationNode configNode) {
private List<ConfigurationValueRecord> getTemplateValues(final ConfigurationNode configNode) {
if (configNode.templateId == null || configNode.templateId.equals(ConfigurationNode.DEFAULT_TEMPLATE_ID)) {
return Collections.emptyMap();
return Collections.emptyList();
}
final Long configurationId = this.batchConfigurationRecordMapper.selectByExample()
@ -735,15 +763,10 @@ class ConfigurationDAOBatchService {
.collect(Utils.toSingleton())
.getId();
final List<ConfigurationValueRecord> values = this.batchConfigurationValueRecordMapper.selectByExample()
return this.batchConfigurationValueRecordMapper.selectByExample()
.where(ConfigurationValueRecordDynamicSqlSupport.configurationId, isEqualTo(configurationId))
.build()
.execute();
return values.stream()
.collect(Collectors.toMap(
valRec -> valRec.getConfigurationAttributeId(),
valRec -> (valRec.getValue() != null) ? valRec.getValue() : ""));
}
}