Skip to content
This repository has been archived by the owner on Feb 22, 2024. It is now read-only.

Commit

Permalink
#102 disable cache during server startup when noconferences is active
Browse files Browse the repository at this point in the history
  • Loading branch information
srose committed Feb 29, 2020
1 parent 536f60c commit 3c8fb28
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,12 @@ class ConferencesConfigurationServiceImpl implements ConferencesConfigurationSer
private String conferencesConfigurationFile
Map<String, Object> configurationProperties = [:]

private boolean readConferences = true

@Inject
ConferencesConfigurationServiceImpl(ConfigurableEnvironment env) {
this.env = env
this.readConferences = !env.getActiveProfiles().contains("noconferences")
}

// TODO Clean up - it is called twice!
Expand All @@ -38,10 +41,15 @@ class ConferencesConfigurationServiceImpl implements ConferencesConfigurationSer
void init() {
this.configurationProperties = getAllKnownConfigurationProperties(env)
conferencesConfigurationFile = configurationProperties["conferences.file"] ?: "conferences-dev.yml"
log.debug ("Loading conferences file '{}'", conferencesConfigurationFile)
configuration.conferences.addAll(
ConferencesConfiguration.fromFile(conferencesConfigurationFile,
configurationProperties)?.conferences)
if (readConferences) {
log.info("Loading conferences enabled, run application with profile 'noconferences' to disable!");
log.debug("Loading conferences file '{}'", conferencesConfigurationFile)
configuration.conferences.addAll(
ConferencesConfiguration.fromFile(conferencesConfigurationFile,
configurationProperties)?.conferences)
} else {
log.info("Loading conferences disabled, run application without profile 'noconferences' to enable!");
}
}

private static Map<String, Object> getAllKnownConfigurationProperties(ConfigurableEnvironment env) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,13 @@
import org.dukecon.services.ConferenceService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.stereotype.Service;
import org.springframework.web.context.ServletContextAware;

import javax.inject.Inject;
import javax.servlet.ServletContext;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.*;
import java.util.stream.Collectors;

/**
Expand All @@ -44,15 +40,12 @@ public class ConferenceServiceImpl implements ConferenceService, ServletContextA

private Map<String, Conference> conferences;

@Value("${conferences.read:true}")
// TODO check for the explicit default value!
// This should be covered by the default in the annotation.
// For some reason this does not work when running the test isolated in the IDE, e.g., IntelliJ
private boolean readConferences = true;
private boolean readConferences;

@Inject
public ConferenceServiceImpl(ConferencesConfigurationService conferenceConfigurationService, List<ConferenceDataProvider> talkProviders) {
this.conferenceConfigurationService = conferenceConfigurationService;
public ConferenceServiceImpl(ConferencesConfigurationService conferenceConfigurationService, List<ConferenceDataProvider> talkProviders, ConfigurableEnvironment env) {
this.conferenceConfigurationService = conferenceConfigurationService;
this.readConferences = !(Arrays.asList(env.getActiveProfiles()).contains("noconferences"));
Map<String, Conference> conferences = initializeConferences(talkProviders);
talkProviders.forEach(tp -> {
this.talkProviders.put(tp.getConferenceId(), tp);
Expand Down Expand Up @@ -108,7 +101,7 @@ public boolean refreshConference(String conferenceId) {
private Map<String, Conference> initializeConferences(List<ConferenceDataProvider> talkProviders) {
Map<String, Conference> conferences = new HashMap<>();
if (readConferences) {
log.info("Reading conferences enabled, run application with '--conferences.read=false' to disable!");
log.info("Reading conferences enabled, run application with profile 'noconferences' to disable!");
for (ConferenceDataProvider provider : talkProviders) {
Conference conference = provider.getConference();
if (conference == null) {
Expand All @@ -119,7 +112,7 @@ private Map<String, Conference> initializeConferences(List<ConferenceDataProvide
conferences.put(conference.getId(), conference);
}
} else {
log.info("Reading conferences disabled, run application with '--conferences.read=true' to enable!");
log.info("Reading conferences disabled, run application without profile 'noconferences' to enable!");
}
this.conferences = conferences;
return conferences;
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
conferences.read=true
conferences.read=false

0 comments on commit 3c8fb28

Please sign in to comment.