|
| 1 | +/* |
| 2 | + Copyright 2019 Ericsson AB. |
| 3 | + For a full list of individual contributors, please see the commit history. |
| 4 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + you may not use this file except in compliance with the License. |
| 6 | + You may obtain a copy of the License at |
| 7 | +
|
| 8 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + Unless required by applicable law or agreed to in writing, software |
| 10 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | + See the License for the specific language governing permissions and |
| 13 | + limitations under the License. |
| 14 | +*/ |
| 15 | +package com.ericsson.eiffel.remrem.generate.config; |
| 16 | + |
| 17 | +import javax.annotation.PostConstruct; |
| 18 | +import org.slf4j.LoggerFactory; |
| 19 | +import org.springframework.beans.factory.annotation.Value; |
| 20 | +import org.springframework.context.annotation.Configuration; |
| 21 | +import org.springframework.context.annotation.Profile; |
| 22 | +import org.springframework.stereotype.Component; |
| 23 | + |
| 24 | +import ch.qos.logback.classic.Logger; |
| 25 | + |
| 26 | +/** |
| 27 | +* This class is used to check whether Event-Repository lookUp is enabled or not based on property |
| 28 | +* event-repository.enabled in property file. |
| 29 | +* |
| 30 | +*/ |
| 31 | + |
| 32 | +@Profile("!integration-test") |
| 33 | +@Configuration |
| 34 | +@Component("event-repository") |
| 35 | +public class ErLookUpConfig { |
| 36 | + |
| 37 | + Logger log = (Logger) LoggerFactory.getLogger(ErLookUpConfig.class); |
| 38 | + |
| 39 | + @Value("${event-repository.url}") |
| 40 | + private String erURL; |
| 41 | + @Value("${event-repository.enabled}") |
| 42 | + private String eventRepositoryEnabled; |
| 43 | + |
| 44 | + private boolean eventRepositoryCheck; |
| 45 | + |
| 46 | + public String getErURL() { |
| 47 | + return erURL; |
| 48 | + } |
| 49 | + |
| 50 | + public void setErURL(String erURL) { |
| 51 | + this.erURL = erURL; |
| 52 | + } |
| 53 | + |
| 54 | + public String getEventRepositoryEnabled() { |
| 55 | + return eventRepositoryEnabled; |
| 56 | + } |
| 57 | + |
| 58 | + public void setEventRepositoryEnabled(String eventRepositoryEnabled) { |
| 59 | + this.eventRepositoryEnabled = eventRepositoryEnabled; |
| 60 | + } |
| 61 | + |
| 62 | + |
| 63 | + /** |
| 64 | + * This method is used to check whether to enable Event-Repository lookup . |
| 65 | + * If event-repository.enabled is false, it didn't perform lookup functionality while fetching events. |
| 66 | + * If event-repository.enabled is true, it sets ER URL for lookup and |
| 67 | + * if event-repository.enabled is not provided or mis-spelt or if event-repository.enabled = true and |
| 68 | + * event-repository.url not provided , then the service gets terminated. |
| 69 | + * |
| 70 | + */ |
| 71 | + @PostConstruct |
| 72 | + public void checkAndLoadEventRepositoryConfiguration() throws InterruptedException { |
| 73 | + if (eventRepositoryEnabled.equalsIgnoreCase("true") || eventRepositoryEnabled.equalsIgnoreCase("false")) { |
| 74 | + eventRepositoryCheck = Boolean.parseBoolean(eventRepositoryEnabled); |
| 75 | + log.info("Checking whether Event Repository configurations for lookup are enabled or not"); |
| 76 | + if (eventRepositoryCheck) { |
| 77 | + if (!erURL.isEmpty()) { |
| 78 | + log.info("Event Repository configurations for lookup are enabled"); |
| 79 | + setErURL(erURL); |
| 80 | + log.info("Configured Event Repository URL for lookup : " + getErURL()); |
| 81 | + } else { |
| 82 | + log.error("Enabled Event Repository configurations for lookUp but not provided Event Repository URL"); |
| 83 | + throw new InterruptedException("Event Repository URL not configured"); |
| 84 | + |
| 85 | + } |
| 86 | + } else { |
| 87 | + log.info("Event Repository configurations for lookup are not enabled"); |
| 88 | + } |
| 89 | + } else { |
| 90 | + log.error("Please check and provide proper value for event-repository.enabled field in configuration file"); |
| 91 | + log.info("Allowed values are either true or false"); |
| 92 | + throw new InterruptedException("Provided incorrect values for lookup configurations"); |
| 93 | + } |
| 94 | + } |
| 95 | +} |
0 commit comments