Skip to content

Commit

Permalink
#62 - sort settings and save plugin settings
Browse files Browse the repository at this point in the history
  • Loading branch information
cbellone committed Oct 8, 2015
1 parent a492643 commit 0e86f65
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 29 deletions.
11 changes: 6 additions & 5 deletions src/main/java/alfio/manager/system/ConfigurationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadOrganizat
if(!userManager.isOwnerOfOrganization(user, organizationId)) {
return Collections.emptyMap();
}
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().collect(groupByCategory());
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findOrganizationConfiguration(organizationId).stream().sorted().collect(groupByCategory());
return groupByCategory(ORGANIZATION_CONFIGURATION, existing);
}

Expand All @@ -225,7 +225,7 @@ public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadEventConf
if(!userManager.isOwnerOfOrganization(user, organizationId)) {
return Collections.emptyMap();
}
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findEventConfiguration(organizationId, eventId).stream().collect(groupByCategory());
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findEventConfiguration(organizationId, eventId).stream().sorted().collect(groupByCategory());
return groupByCategory(EVENT_CONFIGURATION, existing);
}

Expand All @@ -236,14 +236,14 @@ public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadCategoryC
if(!userManager.isOwnerOfOrganization(user, organizationId)) {
return Collections.emptyMap();
}
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findCategoryConfiguration(organizationId, eventId, categoryId).stream().collect(groupByCategory());
Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing = configurationRepository.findCategoryConfiguration(organizationId, eventId, categoryId).stream().sorted().collect(groupByCategory());
return groupByCategory(EVENT_CONFIGURATION, existing);
}

private Map<ConfigurationKeys.SettingCategory, List<Configuration>> groupByCategory(Map<ConfigurationKeys.SettingCategory, List<Configuration>> all, Map<ConfigurationKeys.SettingCategory, List<Configuration>> existing) {
return all.entrySet().stream()
.map(e -> {
Set<Configuration> entries = new LinkedHashSet<>();
Set<Configuration> entries = new TreeSet<>();
ConfigurationKeys.SettingCategory key = e.getKey();
entries.addAll(e.getValue());
if(existing.containsKey(key)) {
Expand All @@ -270,7 +270,7 @@ public Map<ConfigurationKeys.SettingCategory, List<Configuration>> loadAllSystem
.collect(Collectors.toList());
List<Configuration> result = new LinkedList<>(existing);
result.addAll(missing);
return result.stream().collect(groupByCategory());
return result.stream().sorted().collect(groupByCategory());
}

private static Collector<Configuration, ?, Map<ConfigurationKeys.SettingCategory, List<Configuration>>> groupByCategory() {
Expand Down Expand Up @@ -301,6 +301,7 @@ private static Map<ConfigurationKeys.SettingCategory, List<Configuration>> colle
return ConfigurationKeys.byPathLevel(pathLevel)
.stream()
.map(mapEmptyKeys(pathLevel))
.sorted()
.collect(groupByCategory());
}
}
48 changes: 26 additions & 22 deletions src/main/java/alfio/model/system/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<Configuration> {

private final int id;
private final String key;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<PluginConfigOption> loadByEventId(@Bind("eventId") int eventId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 0e86f65

Please sign in to comment.