use of alfio.model.support.CheckInOutputColorConfiguration in project alf.io by alfio-event.
the class EventManager method saveBadgeColorConfiguration.
void saveBadgeColorConfiguration(String badgeColor, Event event, Integer categoryId) {
if (StringUtils.isNotBlank(badgeColor)) {
var chosenColor = badgeColor.toLowerCase();
var colorConfiguration = CheckInManager.getOutputColorConfiguration(event, configurationManager);
boolean existingConfiguration = colorConfiguration != null;
if (!existingConfiguration) {
colorConfiguration = new CheckInOutputColorConfiguration("success", List.of(new ColorConfiguration(chosenColor, List.of(categoryId))));
} else {
var configurationWithoutCategory = colorConfiguration.getConfigurations().stream().map(cc -> new ColorConfiguration(cc.getColorName(), cc.getCategories().stream().filter(c -> !c.equals(categoryId)).collect(toUnmodifiableList()))).filter(cc -> !cc.getCategories().isEmpty()).collect(toList());
boolean colorExists = configurationWithoutCategory.stream().anyMatch(cc -> cc.getColorName().equals(chosenColor));
if (colorExists) {
colorConfiguration = new CheckInOutputColorConfiguration(colorConfiguration.getDefaultColorName(), configurationWithoutCategory.stream().map(cc -> {
if (cc.getColorName().equals(chosenColor)) {
var newList = new ArrayList<>(cc.getCategories());
newList.add(categoryId);
return new ColorConfiguration(chosenColor, newList);
}
return cc;
}).collect(toUnmodifiableList()));
} else {
var newList = new ArrayList<>(configurationWithoutCategory);
newList.add(new ColorConfiguration(chosenColor, List.of(categoryId)));
colorConfiguration = new CheckInOutputColorConfiguration(colorConfiguration.getDefaultColorName(), newList);
}
}
if (existingConfiguration) {
configurationRepository.updateEventLevel(event.getId(), event.getOrganizationId(), CHECK_IN_COLOR_CONFIGURATION.name(), Json.toJson(colorConfiguration));
} else {
configurationRepository.insertEventLevel(event.getOrganizationId(), event.getId(), CHECK_IN_COLOR_CONFIGURATION.name(), Json.toJson(colorConfiguration), null);
}
}
}
Aggregations