diff --git a/src/main/java/alfio/manager/system/ConfigurationManager.java b/src/main/java/alfio/manager/system/ConfigurationManager.java index 2379c1021a..a69c924b83 100644 --- a/src/main/java/alfio/manager/system/ConfigurationManager.java +++ b/src/main/java/alfio/manager/system/ConfigurationManager.java @@ -214,7 +214,7 @@ public Map> loadOrganizat if(!userManager.isOwnerOfOrganization(user, organizationId)) { return Collections.emptyMap(); } - Map> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().collect(groupByCategory()); + Map> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().sorted().collect(groupByCategory()); return groupByCategory(ORGANIZATION_CONFIGURATION, existing); } @@ -225,7 +225,7 @@ public Map> loadEventConf if(!userManager.isOwnerOfOrganization(user, organizationId)) { return Collections.emptyMap(); } - Map> existing = configurationRepository.findEventConfiguration(organizationId, eventId).stream().collect(groupByCategory()); + Map> existing = configurationRepository.findEventConfiguration(organizationId, eventId).stream().sorted().collect(groupByCategory()); return groupByCategory(EVENT_CONFIGURATION, existing); } @@ -236,14 +236,14 @@ public Map> loadCategoryC if(!userManager.isOwnerOfOrganization(user, organizationId)) { return Collections.emptyMap(); } - Map> existing = configurationRepository.findCategoryConfiguration(organizationId, eventId, categoryId).stream().collect(groupByCategory()); + Map> existing = configurationRepository.findCategoryConfiguration(organizationId, eventId, categoryId).stream().sorted().collect(groupByCategory()); return groupByCategory(EVENT_CONFIGURATION, existing); } private Map> groupByCategory(Map> all, Map> existing) { return all.entrySet().stream() .map(e -> { - Set entries = new LinkedHashSet<>(); + Set entries = new TreeSet<>(); ConfigurationKeys.SettingCategory key = e.getKey(); entries.addAll(e.getValue()); if(existing.containsKey(key)) { @@ -270,7 +270,7 @@ public Map> loadAllSystem .collect(Collectors.toList()); List result = new LinkedList<>(existing); result.addAll(missing); - return result.stream().collect(groupByCategory()); + return result.stream().sorted().collect(groupByCategory()); } private static Collector>> groupByCategory() { @@ -301,6 +301,7 @@ private static Map> colle return ConfigurationKeys.byPathLevel(pathLevel) .stream() .map(mapEmptyKeys(pathLevel)) + .sorted() .collect(groupByCategory()); } } diff --git a/src/main/java/alfio/model/system/Configuration.java b/src/main/java/alfio/model/system/Configuration.java index 27cfc5c0d2..1001082799 100644 --- a/src/main/java/alfio/model/system/Configuration.java +++ b/src/main/java/alfio/model/system/Configuration.java @@ -22,11 +22,12 @@ import lombok.EqualsAndHashCode; import lombok.Getter; import org.apache.commons.lang3.Validate; +import org.apache.commons.lang3.builder.CompareToBuilder; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; @Getter -public class Configuration { +public class Configuration implements Comparable { private final int id; private final String key; @@ -55,6 +56,30 @@ public ComponentType getComponentType() { return configurationKey.getComponentType(); } + @Override + public int compareTo(Configuration o) { + return new CompareToBuilder().append(configurationKey.ordinal(), o.configurationKey.ordinal()).toComparison(); + } + + @Override + public boolean equals(Object obj) { + if (obj == null) { + return false; + } + if (obj == this) { + return true; + } + if (obj.getClass() != getClass()) { + return false; + } + Configuration o = (Configuration) obj; + return new EqualsBuilder().append(configurationKey, o.configurationKey).append(configurationPathLevel, configurationPathLevel).isEquals(); + } + + @Override + public int hashCode() { + return new HashCodeBuilder().append(configurationKey).append(configurationPathLevel).toHashCode(); + } public interface ConfigurationPath { ConfigurationPathLevel pathLevel(); @@ -336,25 +361,4 @@ public static ConfigurationPathKey waitingQueueReservationTimeout(Event event) { return new ConfigurationPathKey(event(event), ConfigurationKeys.WAITING_QUEUE_RESERVATION_TIMEOUT); } - @Override - public boolean equals(Object o) { - if (this == o) return true; - - if (o == null || getClass() != o.getClass()) return false; - - Configuration that = (Configuration) o; - - return new EqualsBuilder() - .append(key, that.key) - .append(configurationKey, that.configurationKey) - .isEquals(); - } - - @Override - public int hashCode() { - return new HashCodeBuilder(17, 37) - .append(key) - .append(configurationKey) - .toHashCode(); - } } diff --git a/src/main/java/alfio/repository/plugin/PluginConfigurationRepository.java b/src/main/java/alfio/repository/plugin/PluginConfigurationRepository.java index 940c2f5d6e..096671ebd8 100644 --- a/src/main/java/alfio/repository/plugin/PluginConfigurationRepository.java +++ b/src/main/java/alfio/repository/plugin/PluginConfigurationRepository.java @@ -43,7 +43,7 @@ public interface PluginConfigurationRepository { @Query("update plugin_configuration set conf_value = :value where plugin_id = :pluginId and event_id = :eventId and conf_name = :name") int update(@Bind("pluginId") String pluginId, @Bind("eventId") int eventId, @Bind("name") String name, @Bind("value") String value); - @Query("select * from plugin_configuration where event_id = :eventId") + @Query("select * from plugin_configuration where event_id = :eventId order by id") List loadByEventId(@Bind("eventId") int eventId); } diff --git a/src/main/webapp/resources/js/admin/feature/configuration/configuration.js b/src/main/webapp/resources/js/admin/feature/configuration/configuration.js index f043342e00..9118d2a92f 100644 --- a/src/main/webapp/resources/js/admin/feature/configuration/configuration.js +++ b/src/main/webapp/resources/js/admin/feature/configuration/configuration.js @@ -221,7 +221,7 @@ return; } eventConf.loading = true; - ConfigurationService.updateEventConfig(eventConf.organizationId, eventConf.eventId, eventConf.settings).then(function() { + $q.all([ConfigurationService.updateEventConfig(eventConf.organizationId, eventConf.eventId, eventConf.settings), ConfigurationService.bulkUpdatePlugins(eventConf.eventId, eventConf.pluginSettings)]).then(function() { load(); }, function(e) { alert(e.data);