From 33c915bd92ae4912ad62b20a2a9e104fb0008468 Mon Sep 17 00:00:00 2001 From: anhefti Date: Mon, 27 Sep 2021 10:35:21 +0200 Subject: [PATCH] SEBSERV-230 removed attributes from GUI --- .../sebserver/gui/widget/WidgetFactory.java | 5 +- .../impl/ConfigurationDAOBatchService.java | 70 ++++++++++--------- .../dao/impl/ConfigurationNodeDAOImpl.java | 70 +++++++++++-------- .../config/sql/base/V11__sebSettings_v1_3.sql | 7 ++ 4 files changed, 89 insertions(+), 63 deletions(-) create mode 100644 src/main/resources/config/sql/base/V11__sebSettings_v1_3.sql diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java index 0dea660c..05733242 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/widget/WidgetFactory.java @@ -1027,7 +1027,10 @@ public class WidgetFactory { } public static void setARIALabel(final Widget widget, final String label) { - setAttribute(widget, ADD_HTML_ATTR_ARIA_LABEL, label); + setAttribute( + widget, + ADD_HTML_ATTR_ARIA_LABEL, + Utils.escapeHTML_XML_EcmaScript(label)); } public static void setAttribute(final Widget widget, final String name, final String value) { 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 c24ee4bd..af4d7658 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 @@ -127,6 +127,9 @@ class ConfigurationDAOBatchService { .where( ConfigurationNodeRecordDynamicSqlSupport.name, isEqualTo(data.name)) + .and( + ConfigurationNodeRecordDynamicSqlSupport.type, + SqlBuilder.isEqualTo(data.type.name())) .and( ConfigurationNodeRecordDynamicSqlSupport.institutionId, SqlBuilder.isEqualTo(data.institutionId)) @@ -355,6 +358,9 @@ class ConfigurationDAOBatchService { .where( ConfigurationNodeRecordDynamicSqlSupport.name, isEqualTo(copyInfo.name)) + .and( + ConfigurationNodeRecordDynamicSqlSupport.type, + SqlBuilder.isEqualTo(copyInfo.configurationType.name())) .and( ConfigurationNodeRecordDynamicSqlSupport.institutionId, isEqualTo(institutionId)) @@ -406,9 +412,9 @@ class ConfigurationDAOBatchService { if (BooleanUtils.toBoolean(copyInfo.withHistory)) { configs.forEach(configRec -> this.copyConfiguration( - configRec.getInstitutionId(), - configRec.getId(), - newNodeRec.getId())); + configRec.getInstitutionId(), + configRec.getId(), + newNodeRec.getId())); } else { configs .stream() @@ -764,37 +770,37 @@ class ConfigurationDAOBatchService { final List templateValues = getTemplateValues(configNode); templateValues.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 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()); + 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); - } - }); + if (existingId != null) { + this.batchConfigurationValueRecordMapper.updateByPrimaryKey(valueRec); + } else { + this.batchConfigurationValueRecordMapper.insert(valueRec); + } + }); this.batchSqlSessionTemplate.flushStatements(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java index c78d2425..489c511b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java +++ b/src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ConfigurationNodeDAOImpl.java @@ -185,38 +185,22 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO { @Override @Transactional public Result save(final ConfigurationNode data) { - return Result.tryCatch(() -> { + return checkUniqueName(data) + .map(_d -> { - final Long count = this.configurationNodeRecordMapper.countByExample() - .where( - ConfigurationNodeRecordDynamicSqlSupport.name, - isEqualTo(data.name)) - .and( - ConfigurationNodeRecordDynamicSqlSupport.id, - isNotEqualTo(data.id)) - .and( - ConfigurationNodeRecordDynamicSqlSupport.institutionId, - isNotEqualTo(data.institutionId)) - .build() - .execute(); + final ConfigurationNodeRecord newRecord = new ConfigurationNodeRecord( + data.id, + null, + null, + null, + data.name, + data.description, + null, + (data.status != null) ? data.status.name() : ConfigurationStatus.CONSTRUCTION.name()); - if (count != null && count > 0) { - throw new FieldValidationException("name", "configurationNode:name:exists"); - } - - final ConfigurationNodeRecord newRecord = new ConfigurationNodeRecord( - data.id, - null, - null, - null, - data.name, - data.description, - null, - (data.status != null) ? data.status.name() : ConfigurationStatus.CONSTRUCTION.name()); - - this.configurationNodeRecordMapper.updateByPrimaryKeySelective(newRecord); - return this.configurationNodeRecordMapper.selectByPrimaryKey(data.id); - }) + this.configurationNodeRecordMapper.updateByPrimaryKeySelective(newRecord); + return this.configurationNodeRecordMapper.selectByPrimaryKey(data.id); + }) .flatMap(ConfigurationNodeDAOImpl::toDomainModel) .onError(TransactionHandler::rollback); } @@ -316,6 +300,32 @@ public class ConfigurationNodeDAOImpl implements ConfigurationNodeDAO { }); } + private Result checkUniqueName(final ConfigurationNode data) { + return Result.tryCatch(() -> { + final Long count = this.configurationNodeRecordMapper.countByExample() + .where( + ConfigurationNodeRecordDynamicSqlSupport.name, + isEqualTo(data.name)) + .and( + ConfigurationNodeRecordDynamicSqlSupport.type, + isNotEqualTo(data.type.name())) + .and( + ConfigurationNodeRecordDynamicSqlSupport.id, + isNotEqualTo(data.id)) + .and( + ConfigurationNodeRecordDynamicSqlSupport.institutionId, + isNotEqualTo(data.institutionId)) + .build() + .execute(); + + if (count != null && count > 0) { + throw new FieldValidationException("name", "configurationNode:name:exists"); + } + + return data; + }); + } + static Result toDomainModel(final ConfigurationNodeRecord record) { return Result.tryCatch(() -> new ConfigurationNode( record.getId(), diff --git a/src/main/resources/config/sql/base/V11__sebSettings_v1_3.sql b/src/main/resources/config/sql/base/V11__sebSettings_v1_3.sql new file mode 100644 index 00000000..a1d71e6c --- /dev/null +++ b/src/main/resources/config/sql/base/V11__sebSettings_v1_3.sql @@ -0,0 +1,7 @@ +-- ----------------------------------------------------- +-- Remove SEB Settings from GUI (and templates too) +-- ----------------------------------------------------- + +DELETE FROM `orientation` WHERE `config_attribute_id`='5'; +DELETE FROM `orientation` WHERE `config_attribute_id`='6'; +DELETE FROM `orientation` WHERE `config_attribute_id`='7';