From fc1c6182d37973bec5cba9176a4505be26e117fe Mon Sep 17 00:00:00 2001 From: anhefti Date: Thu, 14 Nov 2019 16:42:02 +0100 Subject: [PATCH] config and template fixes --- .../examconfig/impl/TextFieldBuilder.java | 21 ++++++- .../impl/rules/ProxyPasswordRule.java | 8 +++ .../impl/ConfigurationDAOBatchService.java | 59 +++++++++++++------ 3 files changed, 68 insertions(+), 20 deletions(-) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java index 052a6984..79508cc1 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java @@ -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(); diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/ProxyPasswordRule.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/ProxyPasswordRule.java index 4a93bc4d..7148d9d3 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/ProxyPasswordRule.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/rules/ProxyPasswordRule.java @@ -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> 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 diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java index 6e575327..902bf322 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationDAOBatchService.java @@ -674,11 +674,7 @@ class ConfigurationDAOBatchService { return Result.tryCatch(() -> { - // templateValues to override default values if available - final Map 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 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 getTemplateValues(final ConfigurationNode configNode) { + private List 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 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() : "")); } }