Skip to content

Commit

Permalink
get event api: avoid calling message override twice
Browse files Browse the repository at this point in the history
  • Loading branch information
syjer committed Aug 20, 2019
1 parent 3b26a66 commit 295999a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,10 @@ public ResponseEntity<List<BasicEventInfo>> listEvents() {
public ResponseEntity<EventWithAdditionalInfo> getEvent(@PathVariable("eventName") String eventName, HttpSession session) {
return eventRepository.findOptionalByShortName(eventName).filter(e -> e.getStatus() != Event.Status.DISABLED)//
.map(event -> {

var messageSource = messageSourceManager.getMessageSourceForEvent(event);
//
var messageSourceAndOverride = messageSourceManager.getMessageSourceForEventAndOverride(event);
var messageSource = messageSourceAndOverride.getLeft();
var i18nOverride = messageSourceAndOverride.getRight();

var descriptions = applyCommonMark(eventDescriptionRepository.findDescriptionByEventIdAsMap(event.getId()));

Expand Down Expand Up @@ -234,10 +236,6 @@ public ResponseEntity<EventWithAdditionalInfo> getEvent(@PathVariable("eventName
var analyticsConf = AnalyticsConfiguration.build(configurationsValues, session);
//

//
var i18nOverride = messageSourceManager.getEventMessageSourceOverride(event);
//

return new ResponseEntity<>(new EventWithAdditionalInfo(event, ld.getMapUrl(), organization, descriptions, availablePaymentMethods,
bankAccount, bankAccountOwner,
formattedBeginDate, formattedBeginTime,
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/alfio/manager/i18n/MessageSourceManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import alfio.model.EventAndOrganizationId;
import alfio.repository.system.ConfigurationRepository;
import alfio.util.CustomResourceBundleMessageSource;
import org.apache.commons.lang3.tuple.Pair;
import org.springframework.context.MessageSource;
import org.springframework.context.support.AbstractMessageSource;

Expand All @@ -27,7 +28,6 @@
import java.util.Map;
import java.util.Set;


public class MessageSourceManager {

private final CustomResourceBundleMessageSource messageSource;
Expand All @@ -43,9 +43,13 @@ public Set<String> getKeys(String basename, Locale locale) {
return messageSource.getKeys(basename, locale);
}

public Pair<MessageSource, Map<String, Map<String, String>>> getMessageSourceForEventAndOverride(EventAndOrganizationId eventAndOrganizationId) {
var override = configurationRepository.getEventOverrideMessages(eventAndOrganizationId.getOrganizationId(), eventAndOrganizationId.getId());
return Pair.of(new MessageSourceWithOverride(messageSource, override), override);
}

public MessageSource getMessageSourceForEvent(EventAndOrganizationId eventAndOrganizationId) {
var res = getEventMessageSourceOverride(eventAndOrganizationId);
return new MessageSourceWithOverride(messageSource, res);
return getMessageSourceForEventAndOverride(eventAndOrganizationId).getLeft();
}

public MessageSource getRootMessageSource() {
Expand All @@ -60,11 +64,7 @@ public MessageSource getRootMessageSource(boolean withSystemOverride) {
}
}

public Map<String, Map<String, String>> getEventMessageSourceOverride(EventAndOrganizationId eventAndOrganizationId) {
return configurationRepository.getEventOverrideMessages(eventAndOrganizationId.getOrganizationId(), eventAndOrganizationId.getId());
}

private static final class MessageSourceWithOverride extends AbstractMessageSource {
private static class MessageSourceWithOverride extends AbstractMessageSource {

private final CustomResourceBundleMessageSource messageSource;
private final Map<String, Map<String, String>> override;
Expand Down

0 comments on commit 295999a

Please sign in to comment.