From 8bbf515717e6c377ce6bcf24d38db898fa9c18c3 Mon Sep 17 00:00:00 2001 From: anhefti Date: Tue, 30 Apr 2019 17:09:08 +0200 Subject: [PATCH] created exam config properties from --- .../ch/ethz/seb/sebserver/gbl/api/API.java | 2 + .../seb/sebserver/gbl/api/EntityType.java | 3 +- .../ethz/seb/sebserver/gbl/model/Domain.java | 16 +- .../gbl/model/sebconfig/AttributeType.java | 3 + .../model/sebconfig/ConfigurationNode.java | 58 ++-- .../model/sebconfig/ConfigurationValue.java | 5 +- .../gbl/model/sebconfig/Orientation.java | 53 ++-- .../sebserver/gbl/model/sebconfig/View.java | 89 ++++++ .../ethz/seb/sebserver/gbl/util/Result.java | 2 +- .../ch/ethz/seb/sebserver/gbl/util/Utils.java | 4 + .../seb/sebserver/gui/content/ExamForm.java | 2 +- .../seb/sebserver/gui/content/ExamList.java | 10 +- .../sebserver/gui/content/IndicatorForm.java | 3 +- .../gui/content/InstitutionList.java | 4 +- .../sebserver/gui/content/LmsSetupForm.java | 2 +- .../sebserver/gui/content/LmsSetupList.java | 6 +- .../gui/content/QuizDiscoveryList.java | 4 +- .../gui/content/SebClientConfigList.java | 4 +- .../gui/content/SebExamConfigForm.java | 23 +- .../gui/content/SebExamConfigList.java | 31 +- .../content/SebExamConfigPropertiesForm.java | 105 ++++++- .../gui/content/UserAccountList.java | 4 +- .../gui/content/action/ActionDefinition.java | 14 +- .../content/activity/PageStateDefinition.java | 1 - .../seb/sebserver/gui/form/FormHandle.java | 2 +- .../gui/service/ResourceService.java | 23 +- .../examconfig/ExamConfigurationService.java | 56 ++-- .../service/examconfig/ValueChangeRule.java | 11 +- .../examconfig/impl/AttributeMapping.java | 60 +++- .../examconfig/impl/CheckBoxBuilder.java | 105 +++++++ .../examconfig/impl/ControlFieldAdapter.java | 97 ++++++ .../impl/ExamConfigurationServiceImpl.java | 243 ++++++++++++--- .../service/examconfig/impl/LabelBuilder.java | 79 +++++ .../examconfig/impl/TextFieldBuilder.java | 170 +++++++++++ .../service/examconfig/impl/ViewContext.java | 63 +++- .../examconfig/impl/ViewGridBuilder.java | 281 ++++++++++++++++++ .../gui/service/i18n/I18nSupport.java | 25 +- .../gui/service/i18n/PolyglotPageService.java | 4 +- .../service/i18n/impl/I18nSupportImpl.java | 16 - .../gui/service/page/PageService.java | 2 +- .../webservice/api/PageToListCallAdapter.java | 75 +++++ .../remote/webservice/api/RestCall.java | 4 + .../exam/{GetExams.java => GetExamPage.java} | 4 +- ...titutions.java => GetInstitutionPage.java} | 4 +- ...GetLmsSetups.java => GetLmsSetupPage.java} | 4 +- .../{GetQuizzes.java => GetQuizPage.java} | 4 +- ...tConfigs.java => GetClientConfigPage.java} | 4 +- .../seb/examconfig/GetConfigurationPage.java | 41 +++ .../examconfig/GetConfigurationValuePage.java | 41 +++ .../examconfig/GetConfigurationValues.java | 38 +++ .../api/seb/examconfig/GetConfigurations.java | 19 +- ...gNodes.java => GetExamConfigNodePage.java} | 4 +- .../seb/examconfig/GetOrientationPage.java | 41 +++ .../api/seb/examconfig/GetOrientations.java | 85 +----- .../api/seb/examconfig/GetViewList.java | 42 +++ .../seb/examconfig/SaveExamConfigValue.java | 40 +++ ...rAccounts.java => GetUserAccountPage.java} | 4 +- .../seb/sebserver/gui/table/EntityTable.java | 2 +- .../sebserver/gui/widget/WidgetFactory.java | 79 ++++- .../datalayer/batis/JodaTimeTypeResolver.java | 4 + ...AdditionalAttributesDynamicSqlSupport.java | 14 +- .../mapper/AdditionalAttributesMapper.java | 36 +-- ...ientConnectionRecordDynamicSqlSupport.java | 20 +- .../mapper/ClientConnectionRecordMapper.java | 36 +-- .../ClientEventRecordDynamicSqlSupport.java | 18 +- .../batis/mapper/ClientEventRecordMapper.java | 36 +-- ...ationAttributeRecordDynamicSqlSupport.java | 20 +- .../ConfigurationAttributeRecordMapper.java | 36 +-- ...figurationNodeRecordDynamicSqlSupport.java | 24 +- .../mapper/ConfigurationNodeRecordMapper.java | 58 ++-- .../ConfigurationRecordDynamicSqlSupport.java | 16 +- .../mapper/ConfigurationRecordMapper.java | 36 +-- ...igurationValueRecordDynamicSqlSupport.java | 18 +- .../ConfigurationValueRecordMapper.java | 36 +-- ...nfigurationMapRecordDynamicSqlSupport.java | 14 +- .../ExamConfigurationMapRecordMapper.java | 36 +-- .../mapper/ExamRecordDynamicSqlSupport.java | 22 +- .../batis/mapper/ExamRecordMapper.java | 36 +-- .../IndicatorRecordDynamicSqlSupport.java | 14 +- .../batis/mapper/IndicatorRecordMapper.java | 36 +-- .../InstitutionRecordDynamicSqlSupport.java | 16 +- .../batis/mapper/InstitutionRecordMapper.java | 36 +-- .../LmsSetupRecordDynamicSqlSupport.java | 22 +- .../batis/mapper/LmsSetupRecordMapper.java | 36 +-- .../OrientationRecordDynamicSqlSupport.java | 32 +- .../batis/mapper/OrientationRecordMapper.java | 74 ++--- .../mapper/RoleRecordDynamicSqlSupport.java | 10 +- .../batis/mapper/RoleRecordMapper.java | 36 +-- ...ebClientConfigRecordDynamicSqlSupport.java | 20 +- .../mapper/SebClientConfigRecordMapper.java | 36 +-- .../ThresholdRecordDynamicSqlSupport.java | 12 +- .../batis/mapper/ThresholdRecordMapper.java | 36 +-- ...serActivityLogRecordDynamicSqlSupport.java | 18 +- .../mapper/UserActivityLogRecordMapper.java | 36 +-- .../mapper/UserRecordDynamicSqlSupport.java | 24 +- .../batis/mapper/UserRecordMapper.java | 36 +-- .../mapper/ViewRecordDynamicSqlSupport.java | 33 ++ .../batis/mapper/ViewRecordMapper.java | 173 +++++++++++ .../batis/model/AdditionalAttributes.java | 28 +- .../batis/model/ClientConnectionRecord.java | 40 +-- .../batis/model/ClientEventRecord.java | 36 +-- .../model/ConfigurationAttributeRecord.java | 40 +-- .../batis/model/ConfigurationNodeRecord.java | 56 ++-- .../batis/model/ConfigurationRecord.java | 32 +- .../batis/model/ConfigurationValueRecord.java | 36 +-- .../model/ExamConfigurationMapRecord.java | 28 +- .../datalayer/batis/model/ExamRecord.java | 44 +-- .../batis/model/IndicatorRecord.java | 28 +- .../batis/model/InstitutionRecord.java | 32 +- .../datalayer/batis/model/LmsSetupRecord.java | 44 +-- .../batis/model/OrientationRecord.java | 78 ++--- .../datalayer/batis/model/RoleRecord.java | 20 +- .../batis/model/SebClientConfigRecord.java | 40 +-- .../batis/model/ThresholdRecord.java | 24 +- .../batis/model/UserActivityLogRecord.java | 36 +-- .../datalayer/batis/model/UserRecord.java | 48 +-- .../datalayer/batis/model/ViewRecord.java | 94 ++++++ .../AuthorizationServiceImpl.java | 24 +- .../bulkaction/BulkActionService.java | 8 +- .../dao/ConfigurationNodeDAO.java | 2 +- .../servicelayer/dao/DAOLoggingSupport.java | 2 +- .../servicelayer/dao/FilterMap.java | 12 +- .../webservice/servicelayer/dao/ViewDAO.java | 15 + .../impl/ConfigurationAttributeDAOImpl.java | 4 +- .../dao/impl/ConfigurationDAOImpl.java | 6 +- .../dao/impl/ConfigurationNodeDAOImpl.java | 108 +------ .../dao/impl/ConfigurationValueDAOImpl.java | 36 ++- .../dao/impl/ExamConfigurationMapDAOImpl.java | 4 +- .../servicelayer/dao/impl/ExamDAOImpl.java | 4 +- .../dao/impl/IndicatorDAOImpl.java | 4 +- .../dao/impl/InstitutionDAOImpl.java | 4 +- .../dao/impl/LmsSetupDAOImpl.java | 4 +- .../dao/impl/OrientationDAOImpl.java | 22 +- .../dao/impl/SebClientConfigDAOImpl.java | 4 +- .../dao/impl/UserActivityLogDAOImpl.java | 4 +- .../servicelayer/dao/impl/UserDAOImpl.java | 6 +- .../servicelayer/dao/impl/ViewDAOImpl.java | 168 +++++++++++ .../sebconfig/SebClientConfigService.java | 13 +- .../impl/SebClientConfigServiceImpl.java | 4 +- .../api/ConfigurationAttributeController.java | 3 +- .../weblayer/api/ConfigurationController.java | 16 - .../api/ConfigurationValueController.java | 45 ++- .../weblayer/api/ViewController.java | 72 +++++ src/main/resources/NewFile.xml | 32 ++ src/main/resources/messages.properties | 18 +- src/main/resources/schema-demo.sql | 27 +- src/main/resources/schema-dev.sql | 27 +- src/main/resources/static/css/sebserver.css | 5 + src/test/resources/schema-test.sql | 27 +- 149 files changed, 3584 insertions(+), 1402 deletions(-) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/View.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ControlFieldAdapter.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/LabelBuilder.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/TextFieldBuilder.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/ViewGridBuilder.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/PageToListCallAdapter.java rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/exam/{GetExams.java => GetExamPage.java} (90%) rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/institution/{GetInstitutions.java => GetInstitutionPage.java} (89%) rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/lmssetup/{GetLmsSetups.java => GetLmsSetupPage.java} (90%) rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/quiz/{GetQuizzes.java => GetQuizPage.java} (90%) rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/clientconfig/{GetClientConfigs.java => GetClientConfigPage.java} (89%) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationPage.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationValuePage.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetConfigurationValues.java rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/{GetExamConfigNodes.java => GetExamConfigNodePage.java} (89%) create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetOrientationPage.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/GetViewList.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/seb/examconfig/SaveExamConfigValue.java rename src/main/java/ch/ethz/seb/sebserver/gui/service/remote/webservice/api/useraccount/{GetUserAccounts.java => GetUserAccountPage.java} (89%) create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/mapper/ViewRecordDynamicSqlSupport.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/mapper/ViewRecordMapper.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/datalayer/batis/model/ViewRecord.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/ViewDAO.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/servicelayer/dao/impl/ViewDAOImpl.java create mode 100644 src/main/java/ch/ethz/seb/sebserver/webservice/weblayer/api/ViewController.java create mode 100644 src/main/resources/NewFile.xml diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java index 10be3d5e..660c3526 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/API.java @@ -80,6 +80,8 @@ public final class API { public static final String ORIENTATION_ENDPOINT = "/orientation"; + public static final String VIEW_ENDPOINT = ORIENTATION_ENDPOINT + "/view"; + public static final String EXAM_CONFIGURATION_MAP_ENDPOINT = "/exam_configuration_map"; public static final String USER_ACTIVITY_LOG_ENDPOINT = "/useractivity"; diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/api/EntityType.java b/src/main/java/ch/ethz/seb/sebserver/gbl/api/EntityType.java index cc75208e..c35d8470 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/api/EntityType.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/api/EntityType.java @@ -2,10 +2,11 @@ package ch.ethz.seb.sebserver.gbl.api; import javax.annotation.Generated; -@Generated(value="org.mybatis.generator.api.MyBatisGenerator",comments="ch.ethz.seb.sebserver.gen.DomainModelNameReferencePlugin",date="2019-04-23T15:30:54.700+02:00") +@Generated(value="org.mybatis.generator.api.MyBatisGenerator",comments="ch.ethz.seb.sebserver.gen.DomainModelNameReferencePlugin",date="2019-04-30T14:19:48.997+02:00") public enum EntityType { CONFIGURATION_ATTRIBUTE, CONFIGURATION_VALUE, + VIEW, ORIENTATION, CONFIGURATION, CONFIGURATION_NODE, diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/Domain.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Domain.java index dfeef77a..99b97513 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/Domain.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/Domain.java @@ -5,7 +5,7 @@ import javax.annotation.Generated; /** Defines the global names of the domain model and domain model fields. * This shall be used as a static overall domain model names reference within SEB Server Web-Service as well as within the integrated GUI * This file is generated by the org.eth.demo.sebserver.gen.DomainModelNameReferencePlugin and must not be edited manually.**/ -@Generated(value="org.mybatis.generator.api.MyBatisGenerator",comments="ch.ethz.seb.sebserver.gen.DomainModelNameReferencePlugin",date="2019-04-23T15:30:54.599+02:00") +@Generated(value="org.mybatis.generator.api.MyBatisGenerator",comments="ch.ethz.seb.sebserver.gen.DomainModelNameReferencePlugin",date="2019-04-30T14:19:48.912+02:00") public interface Domain { interface CONFIGURATION_ATTRIBUTE { @@ -33,14 +33,22 @@ public interface Domain { String ATTR_TEXT = "text"; } + interface VIEW { + String TYPE_NAME = "View"; + String REFERENCE_NAME = "views"; + String ATTR_ID = "id"; + String ATTR_NAME = "name"; + String ATTR_POSITION = "position"; + } + interface ORIENTATION { String TYPE_NAME = "Orientation"; String REFERENCE_NAME = "orientations"; String ATTR_ID = "id"; String ATTR_CONFIG_ATTRIBUTE_ID = "configAttributeId"; String ATTR_TEMPLATE_ID = "templateId"; - String ATTR_VIEW = "view"; - String ATTR_GROUP = "group"; + String ATTR_VIEW_ID = "viewId"; + String ATTR_GROUP_ID = "groupId"; String ATTR_X_POSITION = "xPosition"; String ATTR_Y_POSITION = "yPosition"; String ATTR_WIDTH = "width"; @@ -69,7 +77,7 @@ public interface Domain { String ATTR_NAME = "name"; String ATTR_DESCRIPTION = "description"; String ATTR_TYPE = "type"; - String ATTR_ACTIVE = "active"; + String ATTR_STATUS = "status"; } interface EXAM_CONFIGURATION_MAP { diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java index bf032075..c3d902a7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/AttributeType.java @@ -16,6 +16,9 @@ public enum AttributeType { LABEL(NONE), /** Single lined text value */ TEXT_FIELD(TEXT), + /** Password (Base 16 encoded SHA256) + * Displayed as two text input fields (confirm) */ + PASSWORD_FIELD(TEXT), /** Multiple lined text value */ TEXT_AREA(TEXT), /** Check Box or boolean type */ diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationNode.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationNode.java index 89bca4c0..3df24445 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationNode.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationNode.java @@ -17,23 +17,31 @@ import com.fasterxml.jackson.annotation.JsonProperty; import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.api.POSTMapper; -import ch.ethz.seb.sebserver.gbl.model.Activatable; import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.Domain.CONFIGURATION_NODE; import ch.ethz.seb.sebserver.gbl.model.GrantEntity; @JsonIgnoreProperties(ignoreUnknown = true) -public final class ConfigurationNode implements GrantEntity, Activatable { +public final class ConfigurationNode implements GrantEntity { + + public static final Long DEFAULT_TEMPLATE_ID = 0L; public static final String FILTER_ATTR_TEMPLATE_ID = "templateId"; public static final String FILTER_ATTR_DESCRIPTION = "description"; public static final String FILTER_ATTR_TYPE = "type"; + public static final String FILTER_ATTR_STATUS = "status"; public enum ConfigurationType { TEMPLATE, EXAM_CONFIG } + public enum ConfigurationStatus { + CONSTRUCTION, + READY_TO_USE, + IN_USE + } + @JsonProperty(CONFIGURATION_NODE.ATTR_ID) public final Long id; @@ -59,9 +67,8 @@ public final class ConfigurationNode implements GrantEntity, Activatable { @JsonProperty(CONFIGURATION_NODE.ATTR_OWNER) public final String owner; - /** Indicates whether this Configuration is active or not */ - @JsonProperty(CONFIGURATION_NODE.ATTR_ACTIVE) - public final Boolean active; + @JsonProperty(CONFIGURATION_NODE.ATTR_STATUS) + public final ConfigurationStatus status; @JsonCreator public ConfigurationNode( @@ -72,27 +79,34 @@ public final class ConfigurationNode implements GrantEntity, Activatable { @JsonProperty(CONFIGURATION_NODE.ATTR_DESCRIPTION) final String description, @JsonProperty(CONFIGURATION_NODE.ATTR_TYPE) final ConfigurationType type, @JsonProperty(CONFIGURATION_NODE.ATTR_OWNER) final String owner, - @JsonProperty(CONFIGURATION_NODE.ATTR_ACTIVE) final Boolean active) { + @JsonProperty(CONFIGURATION_NODE.ATTR_STATUS) final ConfigurationStatus status) { this.id = id; this.institutionId = institutionId; - this.templateId = templateId; + this.templateId = (templateId != null) ? templateId : DEFAULT_TEMPLATE_ID; this.name = name; this.description = description; this.type = type; this.owner = owner; - this.active = active; + this.status = status; } public ConfigurationNode(final Long institutionId, final POSTMapper postParams) { this.id = null; this.institutionId = institutionId; - this.templateId = postParams.getLong(Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID); + final Long tplId = postParams.getLong(Domain.CONFIGURATION_NODE.ATTR_TEMPLATE_ID); + this.templateId = (tplId != null) ? tplId : DEFAULT_TEMPLATE_ID; this.name = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_NAME); this.description = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION); - this.type = postParams.getEnum(Domain.CONFIGURATION_NODE.ATTR_TYPE, ConfigurationType.class); + this.type = postParams.getEnum( + Domain.CONFIGURATION_NODE.ATTR_TYPE, + ConfigurationType.class, + ConfigurationType.EXAM_CONFIG); this.owner = postParams.getString(Domain.CONFIGURATION_NODE.ATTR_OWNER); - this.active = postParams.getBoolean(Domain.CONFIGURATION_NODE.ATTR_ACTIVE); + this.status = postParams.getEnum( + Domain.CONFIGURATION_NODE.ATTR_STATUS, + ConfigurationStatus.class, + ConfigurationStatus.CONSTRUCTION); } @Override @@ -138,22 +152,8 @@ public final class ConfigurationNode implements GrantEntity, Activatable { return this.templateId; } - public Boolean getActive() { - return this.active; - } - - @Override - public boolean isActive() { - return this.active; - } - - @Override - public String toString() { - return "ConfigurationNode [id=" + this.id + ", institutionId=" + this.institutionId + ", templateId=" - + this.templateId - + ", name=" + this.name + ", description=" + this.description + ", type=" + this.type + ", owner=" - + this.owner - + ", active=" + this.active + "]"; + public ConfigurationStatus getStatus() { + return this.status; } public static ConfigurationNode createNewExamConfig(final Long institutionId) { @@ -165,7 +165,7 @@ public final class ConfigurationNode implements GrantEntity, Activatable { null, ConfigurationType.EXAM_CONFIG, null, - false); + ConfigurationStatus.CONSTRUCTION); } public static ConfigurationNode createNewTemplate(final Long institutionId) { @@ -177,7 +177,7 @@ public final class ConfigurationNode implements GrantEntity, Activatable { null, ConfigurationType.TEMPLATE, null, - false); + ConfigurationStatus.CONSTRUCTION); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationValue.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationValue.java index b9d119d3..44adee77 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationValue.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/ConfigurationValue.java @@ -8,8 +8,6 @@ package ch.ethz.seb.sebserver.gbl.model.sebconfig; -import javax.validation.constraints.NotNull; - import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; @@ -29,7 +27,6 @@ public final class ConfigurationValue implements GrantEntity { @JsonProperty(CONFIGURATION_VALUE.ATTR_ID) public final Long id; - @NotNull @JsonProperty(CONFIGURATION_VALUE.ATTR_INSTITUTION_ID) public final Long institutionId; @@ -37,7 +34,7 @@ public final class ConfigurationValue implements GrantEntity { public final Long configurationId; @JsonProperty(CONFIGURATION_VALUE.ATTR_CONFIGURATION_ATTRIBUTE_ID) - public final long attributeId; + public final Long attributeId; @JsonProperty(CONFIGURATION_VALUE.ATTR_LIST_INDEX) public final Integer listIndex; diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/Orientation.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/Orientation.java index f819ca4a..e90535cd 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/Orientation.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/Orientation.java @@ -24,8 +24,8 @@ import ch.ethz.seb.sebserver.gbl.model.Entity; public final class Orientation implements Entity { public static final String FILTER_ATTR_TEMPLATE_ID = "templateId"; - public static final String FILTER_ATTR_VIEW = "view"; - public static final String FILTER_ATTR_GROUP = "group"; + public static final String FILTER_ATTR_VIEW_ID = "viewId"; + public static final String FILTER_ATTR_GROUP_ID = "groupId"; @JsonProperty(ORIENTATION.ATTR_ID) public final Long id; @@ -37,11 +37,11 @@ public final class Orientation implements Entity { @JsonProperty(ORIENTATION.ATTR_TEMPLATE_ID) public final Long templateId; - @JsonProperty(ORIENTATION.ATTR_VIEW) - public final String view; + @JsonProperty(ORIENTATION.ATTR_VIEW_ID) + public final Long viewId; - @JsonProperty(ORIENTATION.ATTR_GROUP) - public final String group; + @JsonProperty(ORIENTATION.ATTR_GROUP_ID) + public final String groupId; @JsonProperty(ORIENTATION.ATTR_X_POSITION) public final Integer xPosition; @@ -63,8 +63,8 @@ public final class Orientation implements Entity { @JsonProperty(ORIENTATION.ATTR_ID) final Long id, @JsonProperty(ORIENTATION.ATTR_CONFIG_ATTRIBUTE_ID) final Long attributeId, @JsonProperty(ORIENTATION.ATTR_TEMPLATE_ID) final Long templateId, - @JsonProperty(ORIENTATION.ATTR_VIEW) final String view, - @JsonProperty(ORIENTATION.ATTR_GROUP) final String group, + @JsonProperty(ORIENTATION.ATTR_VIEW_ID) final Long viewId, + @JsonProperty(ORIENTATION.ATTR_GROUP_ID) final String groupId, @JsonProperty(ORIENTATION.ATTR_X_POSITION) final Integer xPosition, @JsonProperty(ORIENTATION.ATTR_Y_POSITION) final Integer yPosition, @JsonProperty(ORIENTATION.ATTR_WIDTH) final Integer width, @@ -74,8 +74,8 @@ public final class Orientation implements Entity { this.id = id; this.attributeId = attributeId; this.templateId = templateId; - this.view = view; - this.group = group; + this.viewId = viewId; + this.groupId = groupId; this.xPosition = xPosition; this.yPosition = yPosition; this.width = width; @@ -87,8 +87,8 @@ public final class Orientation implements Entity { this.id = null; this.attributeId = attr.id; this.templateId = postParams.getLong(Domain.ORIENTATION.ATTR_TEMPLATE_ID); - this.view = postParams.getString(Domain.ORIENTATION.ATTR_VIEW); - this.group = postParams.getString(Domain.ORIENTATION.ATTR_GROUP); + this.viewId = postParams.getLong(Domain.ORIENTATION.ATTR_VIEW_ID); + this.groupId = postParams.getString(Domain.ORIENTATION.ATTR_GROUP_ID); this.xPosition = postParams.getInteger(Domain.ORIENTATION.ATTR_X_POSITION); this.yPosition = postParams.getInteger(Domain.ORIENTATION.ATTR_Y_POSITION); this.width = postParams.getInteger(Domain.ORIENTATION.ATTR_WIDTH); @@ -128,12 +128,12 @@ public final class Orientation implements Entity { return this.templateId; } - public String getView() { - return this.view; + public Long getViewId() { + return this.viewId; } - public String getGroup() { - return this.group; + public String getGroupId() { + return this.groupId; } public Integer getXPosition() { @@ -156,13 +156,28 @@ public final class Orientation implements Entity { return this.title; } + public int xpos() { + return this.xPosition != null ? this.xPosition.intValue() : -1; + } + + public int ypos() { + return this.yPosition != null ? this.yPosition.intValue() : -1; + } + + public int width() { + return this.width != null ? this.width.intValue() : -1; + } + + public int height() { + return this.height != null ? this.height.intValue() : -1; + } + @Override public String toString() { return "Orientation [id=" + this.id + ", attributeId=" + this.attributeId + ", templateId=" + this.templateId - + ", view=" - + this.view + ", group=" + this.group + ", xPosition=" + this.xPosition + ", yPosition=" + + ", viewId=" + + this.viewId + ", groupId=" + this.groupId + ", xPosition=" + this.xPosition + ", yPosition=" + this.yPosition + ", width=" + this.width + ", height=" + this.height + ", title=" + this.title + "]"; } - } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/View.java b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/View.java new file mode 100644 index 00000000..322f0014 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/model/sebconfig/View.java @@ -0,0 +1,89 @@ +/* + * 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.gbl.model.sebconfig; + +import javax.validation.constraints.NotNull; + +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import com.fasterxml.jackson.annotation.JsonProperty; + +import ch.ethz.seb.sebserver.gbl.api.EntityType; +import ch.ethz.seb.sebserver.gbl.api.POSTMapper; +import ch.ethz.seb.sebserver.gbl.model.Domain; +import ch.ethz.seb.sebserver.gbl.model.Domain.VIEW; +import ch.ethz.seb.sebserver.gbl.model.Entity; + +@JsonIgnoreProperties(ignoreUnknown = true) +public class View implements Entity { + + @JsonProperty(VIEW.ATTR_ID) + public final Long id; + + @JsonProperty(VIEW.ATTR_NAME) + public final String name; + + @NotNull + @JsonProperty(VIEW.ATTR_POSITION) + public final Integer position; + + public View( + @JsonProperty(VIEW.ATTR_ID) final Long id, + @JsonProperty(VIEW.ATTR_NAME) final String name, + @JsonProperty(VIEW.ATTR_POSITION) final Integer position) { + + this.id = id; + this.name = name; + this.position = position; + } + + public View(final POSTMapper postParams) { + this.id = null; + this.name = postParams.getString(Domain.VIEW.ATTR_NAME); + this.position = postParams.getInteger(Domain.VIEW.ATTR_POSITION); + } + + public Integer getPosition() { + return this.position; + } + + public Long getId() { + return this.id; + } + + @Override + public String getModelId() { + return (this.id != null) + ? String.valueOf(this.id) + : null; + } + + @Override + public EntityType entityType() { + return EntityType.VIEW; + } + + @Override + public String getName() { + return this.name; + } + + @Override + public String toString() { + final StringBuilder builder = new StringBuilder(); + builder.append("View [id="); + builder.append(this.id); + builder.append(", name="); + builder.append(this.name); + builder.append(", position="); + builder.append(this.position); + builder.append("]"); + return builder.toString(); + } + +} diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java index e39f092e..65a1586f 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Result.java @@ -230,7 +230,7 @@ public final class Result { * * @param errorHandler the error handler * @return self reference */ - public Result onErrorDo(final Consumer errorHandler) { + public Result onError(final Consumer errorHandler) { if (this.error != null) { errorHandler.accept(this.error); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java index 9a460b59..efe9b465 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java +++ b/src/main/java/ch/ethz/seb/sebserver/gbl/util/Utils.java @@ -62,6 +62,10 @@ public final class Utils { }); } + public static T toSingleton(final Collection collection) { + return collection.stream().collect(toSingleton()); + } + /** Get an immutable List from a Collection of elements * * @param collection Collection of elements diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java index 90c3a20d..5dc34f8b 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamForm.java @@ -332,7 +332,7 @@ public class ExamForm implements TemplateComposer { } return this.resourceService.getI18nSupport() - .getText("sebserver.exam.indicator.type." + indicator.type.name()); + .getText(ResourceService.EXAM_INDICATOR_TYPE_PREFIX + indicator.type.name()); } private static String thresholdsValue(final Indicator indicator) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamList.java index bc4fff82..38089bba 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/ExamList.java @@ -35,7 +35,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExams; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.exam.GetExamPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -63,6 +63,8 @@ public class ExamList implements TemplateComposer { new LocTextKey("sebserver.exam.list.column.type"); private final static LocTextKey noModifyOfOutDatedExams = new LocTextKey("sebserver.exam.list.modify.out.dated"); + private final static LocTextKey emptyListTextKey = + new LocTextKey("sebserver.exam.list.empty"); private final TableFilterAttribute lmsFilter; private final TableFilterAttribute nameFilter = @@ -102,8 +104,8 @@ public class ExamList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(restService.getRestCall(GetExams.class)) - .withEmptyMessage(new LocTextKey("sebserver.exam.list.empty")) + this.pageService.entityTableBuilder(restService.getRestCall(GetExamPage.class)) + .withEmptyMessage(emptyListTextKey) .withPaging(this.pageSize) .withColumn(new ColumnDefinition<>( Domain.EXAM.ATTR_LMS_SETUP_ID, @@ -179,7 +181,7 @@ public class ExamList implements TemplateComposer { } return this.resourceService.getI18nSupport() - .getText("sebserver.exam.type." + exam.type.name()); + .getText(ResourceService.EXAM_TYPE_PREFIX + exam.type.name()); } } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java index b8afe09a..5d431863 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/IndicatorForm.java @@ -19,6 +19,7 @@ import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.EntityKey; import ch.ethz.seb.sebserver.gbl.model.exam.Exam; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator; +import ch.ethz.seb.sebserver.gbl.model.exam.QuizData; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; import ch.ethz.seb.sebserver.gui.form.FormBuilder; @@ -120,7 +121,7 @@ public class IndicatorForm implements TemplateComposer { Domain.INDICATOR.ATTR_EXAM_ID, parentEntityKey.getModelId()) .addField(FormBuilder.text( - "examName", + QuizData.QUIZ_ATTR_NAME, FORM_EXAM_TEXT_KEY, exam.name) .readonly(true)) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/InstitutionList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/InstitutionList.java index 8584e54c..2862ee9c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/InstitutionList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/InstitutionList.java @@ -24,7 +24,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutions; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.institution.GetInstitutionPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -73,7 +73,7 @@ public class InstitutionList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(this.restService.getRestCall(GetInstitutions.class)) + this.pageService.entityTableBuilder(this.restService.getRestCall(GetInstitutionPage.class)) .withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withPaging(3) .withColumn(new ColumnDefinition<>( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java index f7bcb214..33ca1830 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupForm.java @@ -246,7 +246,7 @@ public class LmsSetupForm implements TemplateComposer { API.PARAM_MODEL_ID, action.pageContext().getAttribute(AttributeKeys.ENTITY_ID)) .call() - .onErrorDo(t -> action.pageContext().notifyError(t)); + .onError(t -> action.pageContext().notifyError(t)); return testLmsSetup; } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupList.java index 44329e77..3c706c14 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/LmsSetupList.java @@ -31,7 +31,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.lmssetup.GetLmsSetups; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.lmssetup.GetLmsSetupPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -105,7 +105,7 @@ public class LmsSetupList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(restService.getRestCall(GetLmsSetups.class)) + this.pageService.entityTableBuilder(restService.getRestCall(GetLmsSetupPage.class)) .withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withPaging(this.pageSize) .withColumnIf( @@ -161,7 +161,7 @@ public class LmsSetupList implements TemplateComposer { } return this.resourceService.getI18nSupport() - .getText("sebserver.lmssetup.type." + lmsSetup.lmsType.name()); + .getText(ResourceService.LMSSETUP_TYPE_PREFIX + lmsSetup.lmsType.name()); } private static Function lmsSetupInstitutionNameFunction(final ResourceService resourceService) { diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizDiscoveryList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizDiscoveryList.java index 7257224f..83c9b2b4 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizDiscoveryList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/QuizDiscoveryList.java @@ -36,7 +36,7 @@ import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.ModalInputDialog; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.quiz.GetQuizzes; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.quiz.GetQuizPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -122,7 +122,7 @@ public class QuizDiscoveryList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(restService.getRestCall(GetQuizzes.class)) + this.pageService.entityTableBuilder(restService.getRestCall(GetQuizPage.class)) .withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withPaging(this.pageSize) .withColumn(new ColumnDefinition<>( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigList.java index ea1cb191..6a84ceb8 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebClientConfigList.java @@ -34,7 +34,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfigs; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.clientconfig.GetClientConfigPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -107,7 +107,7 @@ public class SebClientConfigList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(this.restService.getRestCall(GetClientConfigs.class)) + this.pageService.entityTableBuilder(this.restService.getRestCall(GetClientConfigPage.class)) .withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withPaging(this.pageSize) .withColumnIf( diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigForm.java index 2ed8c8b8..9f98fff2 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigForm.java @@ -24,14 +24,12 @@ import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; import ch.ethz.seb.sebserver.gui.content.action.ActionDefinition; import ch.ethz.seb.sebserver.gui.form.FormBuilder; import ch.ethz.seb.sebserver.gui.form.FormHandle; +import ch.ethz.seb.sebserver.gui.service.ResourceService; import ch.ethz.seb.sebserver.gui.service.i18n.LocTextKey; import ch.ethz.seb.sebserver.gui.service.page.PageContext; import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; -import ch.ethz.seb.sebserver.gui.service.page.impl.PageUtils; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.ActivateExamConfig; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.DeactivateExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNode; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.NewExamConfig; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.SaveExamConfig; @@ -54,6 +52,8 @@ public class SebExamConfigForm implements TemplateComposer { new LocTextKey("sebserver.examconfig.form.name"); private static final LocTextKey FORM_DESCRIPTION_TEXT_KEY = new LocTextKey("sebserver.examconfig.form.description"); + private static final LocTextKey FORM_STATUS_TEXT_KEY = + new LocTextKey("sebserver.examconfig.form.status"); private final PageService pageService; private final RestService restService; @@ -72,6 +72,7 @@ public class SebExamConfigForm implements TemplateComposer { @Override public void compose(final PageContext pageContext) { final WidgetFactory widgetFactory = this.pageService.getWidgetFactory(); + final ResourceService resourceService = this.pageService.getResourceService(); final UserInfo user = this.currentUser.get(); final EntityKey entityKey = pageContext.getEntityKey(); @@ -134,6 +135,11 @@ public class SebExamConfigForm implements TemplateComposer { Domain.CONFIGURATION_NODE.ATTR_DESCRIPTION, FORM_DESCRIPTION_TEXT_KEY, examConfig.description).asArea()) + .addField(FormBuilder.singleSelection( + Domain.CONFIGURATION_NODE.ATTR_STATUS, + FORM_STATUS_TEXT_KEY, + examConfig.status.name(), + resourceService::examConfigStatusResources)) .buildFor((isNew) ? this.restService.getRestCall(NewExamConfig.class) : this.restService.getRestCall(SaveExamConfig.class)); @@ -147,17 +153,6 @@ public class SebExamConfigForm implements TemplateComposer { .withEntityKey(entityKey) .publishIf(() -> modifyGrant && isReadonly) - .newAction(ActionDefinition.SEB_EXAM_CONFIG_DEACTIVATE) - .withEntityKey(entityKey) - .withSimpleRestCall(this.restService, DeactivateExamConfig.class) - .withConfirm(PageUtils.confirmDeactivation(examConfig, this.restService)) - .publishIf(() -> writeGrant && isReadonly && examConfig.isActive()) - - .newAction(ActionDefinition.SEB_EXAM_CONFIG_ACTIVATE) - .withEntityKey(entityKey) - .withSimpleRestCall(this.restService, ActivateExamConfig.class) - .publishIf(() -> writeGrant && isReadonly && !examConfig.isActive()) - .newAction(ActionDefinition.SEB_EXAM_CONFIG_SAVE) .withEntityKey(entityKey) .withExec(formHandle::processFormSave) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigList.java index 9c7b1221..16715118 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigList.java @@ -15,6 +15,7 @@ import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import ch.ethz.seb.sebserver.gbl.Constants; import ch.ethz.seb.sebserver.gbl.api.EntityType; import ch.ethz.seb.sebserver.gbl.model.Domain; import ch.ethz.seb.sebserver.gbl.model.Entity; @@ -30,7 +31,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodes; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNodePage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -53,14 +54,15 @@ public class SebExamConfigList implements TemplateComposer { new LocTextKey("sebserver.examconfig.list.column.name"); private static final LocTextKey DESCRIPTION_TEXT_KEY = new LocTextKey("sebserver.examconfig.list.column.description"); - private static final LocTextKey ACTIVE_TEXT_KEY = - new LocTextKey("sebserver.examconfig.list.column.active"); + private static final LocTextKey STATUS_TEXT_KEY = + new LocTextKey("sebserver.examconfig.list.column.status"); private static final LocTextKey EMPTY_SELECTION_TEXT_KEY = new LocTextKey("sebserver.examconfig.info.pleaseSelect"); private final TableFilterAttribute institutionFilter; private final TableFilterAttribute nameFilter = new TableFilterAttribute(CriteriaType.TEXT, Entity.FILTER_ATTR_NAME); + private final TableFilterAttribute statusFilter; private final PageService pageService; private final RestService restService; @@ -84,6 +86,11 @@ public class SebExamConfigList implements TemplateComposer { CriteriaType.SINGLE_SELECTION, Entity.FILTER_ATTR_INSTITUTION, this.resourceService::institutionResource); + + this.statusFilter = new TableFilterAttribute( + CriteriaType.SINGLE_SELECTION, + ConfigurationNode.FILTER_ATTR_STATUS, + this.resourceService::examConfigStatusResources); } @Override @@ -99,7 +106,7 @@ public class SebExamConfigList implements TemplateComposer { // table final EntityTable table = - this.pageService.entityTableBuilder(this.restService.getRestCall(GetExamConfigNodes.class)) + this.pageService.entityTableBuilder(this.restService.getRestCall(GetExamConfigNodePage.class)) .withEmptyMessage(EMPTY_LIST_TEXT_KEY) .withPaging(this.pageSize) .withColumnIf( @@ -123,9 +130,10 @@ public class SebExamConfigList implements TemplateComposer { this.nameFilter, true)) .withColumn(new ColumnDefinition<>( - Domain.CONFIGURATION_NODE.ATTR_ACTIVE, - ACTIVE_TEXT_KEY, - entity -> entity.active, + Domain.CONFIGURATION_NODE.ATTR_STATUS, + STATUS_TEXT_KEY, + this::examConfigStatusName, + this.statusFilter, true)) .withDefaultAction(pageActionBuilder .newAction(ActionDefinition.SEB_EXAM_CONFIG_VIEW_FROM_LIST) @@ -159,4 +167,13 @@ public class SebExamConfigList implements TemplateComposer { .apply(String.valueOf(config.institutionId)); } + private String examConfigStatusName(final ConfigurationNode config) { + if (config.status == null) { + return Constants.EMPTY_NOTE; + } + + return this.resourceService.getI18nSupport() + .getText(ResourceService.EXAMCONFIG_STATUS_PREFIX + config.status.name()); + } + } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropertiesForm.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropertiesForm.java index d739e6e7..8d141037 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropertiesForm.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/SebExamConfigPropertiesForm.java @@ -8,25 +8,124 @@ package ch.ethz.seb.sebserver.gui.content; +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.layout.GridData; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.TabFolder; +import org.eclipse.swt.widgets.TabItem; import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Component; +import ch.ethz.seb.sebserver.gbl.Constants; +import ch.ethz.seb.sebserver.gbl.api.API; +import ch.ethz.seb.sebserver.gbl.model.EntityKey; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.Configuration; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.View; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; +import ch.ethz.seb.sebserver.gbl.util.Utils; +import ch.ethz.seb.sebserver.gui.service.examconfig.ExamConfigurationService; +import ch.ethz.seb.sebserver.gui.service.examconfig.impl.AttributeMapping; +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.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.service.page.PageService; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetConfigurations; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.seb.examconfig.GetExamConfigNode; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; +import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; @Lazy @Component @GuiProfile public class SebExamConfigPropertiesForm implements TemplateComposer { - public SebExamConfigPropertiesForm() { - // TODO Auto-generated constructor stub + private static final String VIEW_TEXT_KEY_PREFIX = "sebserver.examconfig.props.form.views."; + private static final String VIEW_TOOLTIP_TEXT_KEY_PREFIX = "tooltip"; + + private static final LocTextKey TITLE_TEXT_KEY = + new LocTextKey("sebserver.examconfig.props.from.title"); + + private final PageService pageService; + private final RestService restService; + private final CurrentUser currentUser; + private final ExamConfigurationService examConfigurationService; + + protected SebExamConfigPropertiesForm( + final PageService pageService, + final RestService restService, + final CurrentUser currentUser, + final ExamConfigurationService examConfigurationService) { + + this.pageService = pageService; + this.restService = restService; + this.currentUser = currentUser; + this.examConfigurationService = examConfigurationService; } @Override public void compose(final PageContext pageContext) { - // TODO Auto-generated method stub + final WidgetFactory widgetFactory = this.pageService.getWidgetFactory(); + + final EntityKey entityKey = pageContext.getEntityKey(); + final EntityKey parentEntityKey = pageContext.getParentEntityKey(); + + final ConfigurationNode configNode = this.restService.getBuilder(GetExamConfigNode.class) + .withURIVariable(API.PARAM_MODEL_ID, entityKey.modelId) + .call() + .onError(pageContext::notifyError) + .getOrThrow(); + + final Configuration configuration = this.restService.getBuilder(GetConfigurations.class) + .withQueryParam(Configuration.FILTER_ATTR_CONFIGURATION_NODE_ID, configNode.getModelId()) + .withQueryParam(Configuration.FILTER_ATTR_FOLLOWUP, Constants.TRUE_STRING) + .call() + .map(Utils::toSingleton) + .onError(pageContext::notifyError) + .getOrThrow(); + + final Composite content = widgetFactory.defaultPageLayout( + pageContext.getParent(), + TITLE_TEXT_KEY); + + final AttributeMapping attributes = this.examConfigurationService + .getAttributes(configNode.templateId) + .onError(pageContext::notifyError) + .getOrThrow(); + + final List views = this.examConfigurationService.getViews(attributes); + + final TabFolder tabFolder = widgetFactory.tabFolderLocalized(content); + tabFolder.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true)); + + final List viewContexts = new ArrayList<>(); + for (final View view : views) { + final ViewContext viewContext = this.examConfigurationService.createViewContext( + pageContext, + configuration, + view, + attributes, + 4, + 20); + viewContexts.add(viewContext); + + final Composite viewGrid = this.examConfigurationService.createViewGrid( + tabFolder, + viewContext); + + final TabItem tabItem = widgetFactory.tabItemLocalized( + tabFolder, + new LocTextKey(VIEW_TEXT_KEY_PREFIX + view.name), + new LocTextKey(VIEW_TEXT_KEY_PREFIX + view.name + VIEW_TOOLTIP_TEXT_KEY_PREFIX)); + tabItem.setControl(viewGrid); + } + + this.examConfigurationService.initInputFieldValues(configuration.id, viewContexts); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountList.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountList.java index 2b13cda4..c5f230f6 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountList.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/UserAccountList.java @@ -32,7 +32,7 @@ import ch.ethz.seb.sebserver.gui.service.page.PageService.PageActionBuilder; import ch.ethz.seb.sebserver.gui.service.page.TemplateComposer; import ch.ethz.seb.sebserver.gui.service.page.impl.PageAction; import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.RestService; -import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccounts; +import ch.ethz.seb.sebserver.gui.service.remote.webservice.api.useraccount.GetUserAccountPage; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser.GrantCheck; import ch.ethz.seb.sebserver.gui.table.ColumnDefinition; @@ -114,7 +114,7 @@ public class UserAccountList implements TemplateComposer { // table final EntityTable table = this.pageService.entityTableBuilder( - restService.getRestCall(GetUserAccounts.class)) + restService.getRestCall(GetUserAccountPage.class)) .withEmptyMessage(new LocTextKey("sebserver.useraccount.list.empty")) .withPaging(this.pageSize) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java index 993bd37e..3634f038 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/action/ActionDefinition.java @@ -333,21 +333,11 @@ public enum ActionDefinition { ImageIcon.SAVE, PageStateDefinition.SEB_EXAM_CONFIG_VIEW, ActionCategory.FORM), - SEB_EXAM_CONFIG_ACTIVATE( - new LocTextKey("sebserver.examconfig.action.activate"), - ImageIcon.INACTIVE, - PageStateDefinition.SEB_EXAM_CONFIG_VIEW, - ActionCategory.FORM), - SEB_EXAM_CONFIG_DEACTIVATE( - new LocTextKey("sebserver.examconfig.action.deactivate"), - ImageIcon.ACTIVE, - PageStateDefinition.SEB_EXAM_CONFIG_VIEW, - ActionCategory.FORM), SEB_EXAM_CONFIG_MODIFY_PROPERTIES_FROM_LIST( - new LocTextKey("sebserver.examconfig.properties.action.list.modify"), + new LocTextKey("sebserver.examconfig.props.action.list.modify"), ImageIcon.EDIT, - PageStateDefinition.SEB_EXAM_CONFIG_EDIT, + PageStateDefinition.SEB_EXAM_CONFIG_PROPERTIES_EDIT, ActionCategory.SEB_EXAM_CONFIG_LIST), ; diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/content/activity/PageStateDefinition.java b/src/main/java/ch/ethz/seb/sebserver/gui/content/activity/PageStateDefinition.java index 581a85d6..78e70df7 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/content/activity/PageStateDefinition.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/content/activity/PageStateDefinition.java @@ -58,7 +58,6 @@ public enum PageStateDefinition implements PageState { SEB_EXAM_CONFIG_LIST(Type.LIST_VIEW, SebExamConfigList.class, ActivityDefinition.SEB_EXAM_CONFIG), SEB_EXAM_CONFIG_VIEW(Type.FORM_VIEW, SebExamConfigForm.class, ActivityDefinition.SEB_EXAM_CONFIG), SEB_EXAM_CONFIG_EDIT(Type.FORM_EDIT, SebExamConfigForm.class, ActivityDefinition.SEB_EXAM_CONFIG), - SEB_EXAM_CONFIG_PROPERTIES_EDIT(Type.FORM_VIEW, SebExamConfigPropertiesForm.class, ActivityDefinition.SEB_EXAM_CONFIG), diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java index df30484a..d787274a 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/form/FormHandle.java @@ -108,7 +108,7 @@ public class FormHandle { return resultAction; }) - .onErrorDo(this::handleError) + .onError(this::handleError) .getOrThrow(); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java index 4165059b..54873000 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/ResourceService.java @@ -27,6 +27,7 @@ import ch.ethz.seb.sebserver.gbl.model.Entity; import ch.ethz.seb.sebserver.gbl.model.exam.Exam.ExamType; import ch.ethz.seb.sebserver.gbl.model.exam.Indicator.IndicatorType; import ch.ethz.seb.sebserver.gbl.model.institution.LmsSetup.LmsType; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationNode.ConfigurationStatus; import ch.ethz.seb.sebserver.gbl.model.user.UserInfo; import ch.ethz.seb.sebserver.gbl.model.user.UserRole; import ch.ethz.seb.sebserver.gbl.profile.GuiProfile; @@ -46,6 +47,11 @@ import ch.ethz.seb.sebserver.gui.service.remote.webservice.auth.CurrentUser; * combo-box content. */ public class ResourceService { + public static final String EXAMCONFIG_STATUS_PREFIX = "sebserver.examconfig.status."; + public static final String EXAM_TYPE_PREFIX = "sebserver.exam.type."; + public static final String USERACCOUNT_ROLE_PREFIX = "sebserver.useraccount.role."; + public static final String EXAM_INDICATOR_TYPE_PREFIX = "sebserver.exam.indicator.type."; + public static final String LMSSETUP_TYPE_PREFIX = "sebserver.lmssetup.type."; public static final LocTextKey ACTIVE_TEXT_KEY = new LocTextKey("sebserver.overall.status.active"); public static final LocTextKey INACTIVE_TEXT_KEY = new LocTextKey("sebserver.overall.status.inactive"); @@ -86,7 +92,7 @@ public class ResourceService { .stream() .map(lmsType -> new Tuple<>( lmsType.name(), - this.i18nSupport.getText("sebserver.lmssetup.type." + lmsType.name()))) + this.i18nSupport.getText(LMSSETUP_TYPE_PREFIX + lmsType.name()))) .collect(Collectors.toList()); } @@ -95,7 +101,7 @@ public class ResourceService { .stream() .map(type -> new Tuple<>( type.name(), - this.i18nSupport.getText("sebserver.exam.indicator.type." + type.name()))) + this.i18nSupport.getText(EXAM_INDICATOR_TYPE_PREFIX + type.name()))) .collect(Collectors.toList()); } @@ -104,7 +110,7 @@ public class ResourceService { .stream() .map(ur -> new Tuple<>( ur.name(), - this.i18nSupport.getText("sebserver.useraccount.role." + ur.name()))) + this.i18nSupport.getText(USERACCOUNT_ROLE_PREFIX + ur.name()))) .collect(Collectors.toList()); } @@ -198,7 +204,16 @@ public class ResourceService { .stream() .map(type -> new Tuple<>( type.name(), - this.i18nSupport.getText("sebserver.exam.type." + type.name()))) + this.i18nSupport.getText(EXAM_TYPE_PREFIX + type.name()))) + .collect(Collectors.toList()); + } + + public List> examConfigStatusResources() { + return Arrays.asList(ConfigurationStatus.values()) + .stream() + .map(type -> new Tuple<>( + type.name(), + this.i18nSupport.getText(EXAMCONFIG_STATUS_PREFIX + type.name()))) .collect(Collectors.toList()); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ExamConfigurationService.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ExamConfigurationService.java index fa4619de..1f662239 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ExamConfigurationService.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ExamConfigurationService.java @@ -8,40 +8,50 @@ package ch.ethz.seb.sebserver.gui.service.examconfig; +import java.util.Collection; +import java.util.List; + import org.eclipse.swt.widgets.Composite; +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.Orientation; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.View; +import ch.ethz.seb.sebserver.gbl.util.Result; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.AttributeMapping; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext; +import ch.ethz.seb.sebserver.gui.service.page.PageContext; +import ch.ethz.seb.sebserver.gui.widget.WidgetFactory; public interface ExamConfigurationService { - AttributeMapping getAttributes(String template); + public static final String ATTRIBUTE_LABEL_LOC_TEXT_PREFIX = "sebserver.examconfig.props.label."; + public static final String GROUP_LABEL_LOC_TEXT_PREFIX = "sebserver.examconfig.props.group."; - default ViewContext createViewContext( - final String template, - final Composite parent, - final String name, - final String configurationId, - final int columns, - final int rows) { + WidgetFactory getWidgetFactory(); - return createViewContext( - getAttributes(template), - parent, - name, - configurationId, - columns, - rows); - } + InputFieldBuilder getInputFieldBuilder( + ConfigurationAttribute attribute, + Orientation orientation); + + Result getAttributes(Long templateId); + + List getViews(AttributeMapping allAttributes); ViewContext createViewContext( - final AttributeMapping attributeMapping, - final Composite parent, - final String name, - final String configurationId, - final int columns, - final int rows); + PageContext pageContext, + Configuration configuration, + View view, + AttributeMapping attributeMapping, + int columns, + int rows); - ViewContext initInputFieldValues(final ViewContext viewContext); + Composite createViewGrid( + Composite parent, + ViewContext viewContext); + + void initInputFieldValues( + Long configurationId, + Collection viewContexts); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ValueChangeRule.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ValueChangeRule.java index 0114cd83..d2a6750c 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ValueChangeRule.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/ValueChangeRule.java @@ -8,14 +8,17 @@ package ch.ethz.seb.sebserver.gui.service.examconfig; -import java.util.Set; - +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationAttribute; +import ch.ethz.seb.sebserver.gbl.model.sebconfig.ConfigurationValue; import ch.ethz.seb.sebserver.gui.service.examconfig.impl.ViewContext; public interface ValueChangeRule { - Set observedAttributeNames(); + boolean observesAttribute(ConfigurationAttribute attribute); - void applyRule(ViewContext context, String attributeName, String value); + void applyRule( + ViewContext context, + ConfigurationAttribute attribut, + ConfigurationValue value); } diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java index ddd8d802..65985da9 100644 --- a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/AttributeMapping.java @@ -9,8 +9,10 @@ package ch.ethz.seb.sebserver.gui.service.examconfig.impl; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.function.Function; import java.util.stream.Collectors; @@ -22,7 +24,7 @@ import ch.ethz.seb.sebserver.gbl.util.Utils; public class AttributeMapping { - public final String template; + public final Long templateId; public final Map attributeIdMapping; public final Map attributeNameIdMapping; @@ -34,11 +36,15 @@ public class AttributeMapping { public final Map> attributeGroupMapping; AttributeMapping( - final String template, + final Long templateId, final Collection attributes, final Collection orientations) { - this.template = template; + Objects.requireNonNull(templateId); + Objects.requireNonNull(attributes); + Objects.requireNonNull(orientations); + + this.templateId = templateId; this.attributeIdMapping = Utils.immutableMapOf(attributes .stream() .collect(Collectors.toMap( @@ -71,7 +77,7 @@ public class AttributeMapping { this.attributeGroupMapping = Utils.immutableMapOf(orientations .stream() - .map(o -> o.group) + .map(o -> o.groupId) .collect(Collectors.toSet()) .stream() .collect(Collectors.toMap( @@ -79,10 +85,18 @@ public class AttributeMapping { this::getAttributesOfGroup))); } + public Collection getAttributes() { + return Collections.unmodifiableCollection(this.attributeIdMapping.values()); + } + public ConfigurationAttribute getAttribute(final Long attributeId) { return this.attributeIdMapping.get(attributeId); } + public Orientation getOrientation(final Long attributeId) { + return this.orientationAttributeMapping.get(attributeId); + } + public Orientation getOrientation(final String attributeName) { return this.orientationAttributeNameMapping.get(attributeName); } @@ -91,21 +105,21 @@ public class AttributeMapping { return this.attributeIdMapping.get(this.attributeNameIdMapping.get(attributeName)); } - public List getAttributes(final String view) { - if (StringUtils.isBlank(view)) { + public List getAttributes(final Long viewId) { + if (viewId == null) { return Utils.immutableListOf(this.attributeIdMapping.values()); } else { return Utils.immutableListOf(this.attributeIdMapping .values() .stream() .filter(attr -> this.orientationAttributeMapping.containsKey(attr.id) - && view.equals(this.orientationAttributeMapping.get(attr.id).view)) + && viewId.equals(this.orientationAttributeMapping.get(attr.id).viewId)) .collect(Collectors.toList())); } } - public List getAttributeNames(final String view) { - if (StringUtils.isBlank(view)) { + public List getAttributeNames(final Long viewId) { + if (viewId == null) { return Utils.immutableListOf(this.attributeIdMapping .values() .stream() @@ -116,12 +130,36 @@ public class AttributeMapping { .values() .stream() .filter(attr -> this.orientationAttributeMapping.containsKey(attr.id) - && view.equals(this.orientationAttributeMapping.get(attr.id).view)) + && viewId.equals(this.orientationAttributeMapping.get(attr.id).viewId)) .map(attr -> attr.name) .collect(Collectors.toList())); } } + public Collection getViewIds() { + return this.orientationAttributeMapping.values() + .stream() + .map(o -> o.viewId) + .collect(Collectors.toSet()); + } + + public Collection getOrientationsOfGroup(final ConfigurationAttribute attribute) { + final Orientation orientation = this.orientationAttributeMapping.get(attribute.id); + if (orientation == null) { + return Collections.emptyList(); + } + + if (StringUtils.isBlank(orientation.groupId)) { + return Collections.emptyList(); + } + + return Collections.unmodifiableCollection(this.orientationAttributeMapping + .values() + .stream() + .filter(o -> orientation.groupId.equals(o.groupId)) + .collect(Collectors.toList())); + } + private List getChildAttributes(final ConfigurationAttribute attribute) { return this.attributeIdMapping .values() @@ -141,7 +179,7 @@ public class AttributeMapping { return this.orientationAttributeMapping .values() .stream() - .filter(o -> groupName.equals(o.group)) + .filter(o -> groupName.equals(o.groupId)) .sorted((o1, o2) -> (o1.yPosition == o2.yPosition) ? o1.xPosition.compareTo(o2.xPosition) : o1.yPosition.compareTo(o2.yPosition)) diff --git a/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java new file mode 100644 index 00000000..cd9b03d0 --- /dev/null +++ b/src/main/java/ch/ethz/seb/sebserver/gui/service/examconfig/impl/CheckBoxBuilder.java @@ -0,0 +1,105 @@ +/* + * Copyright (c) 2018 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 java.util.Collection; +import java.util.Objects; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.Button; +import org.eclipse.swt.widgets.Composite; +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.model.sebconfig.Orientation; +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.InputFieldBuilder; + +@Lazy +@Component +@GuiProfile +public class CheckBoxBuilder implements InputFieldBuilder { + + @Override + public boolean builderFor( + final ConfigurationAttribute attribute, + final Orientation orientation) { + + if (attribute == null) { + return false; + } + + return attribute.type == AttributeType.CHECK_FIELD || + attribute.type == AttributeType.CHECKBOX; + } + + @Override + public InputField createInputField( + final Composite parent, + final ConfigurationAttribute attribute, + final ViewContext viewContext) { + + Objects.requireNonNull(parent); + Objects.requireNonNull(attribute); + Objects.requireNonNull(viewContext); + + final Button checkbox = new Button(parent, SWT.CHECK); + if (attribute.type == AttributeType.CHECKBOX) { + checkbox.setText(attribute.name); + } + + checkbox.addListener( + SWT.Selection, + event -> viewContext.getValueChangeListener().valueChanged( + viewContext, + attribute, + String.valueOf(checkbox.getSelection()), + 0)); + + return new CheckboxField( + attribute, + viewContext.attributeMapping.getOrientation(attribute.id), + checkbox); + } + + static final class CheckboxField extends ControlFieldAdapter