2 * Copyright 2016-2017, Nokia Corporation
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
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
18 import com.google.common.collect.Sets;
19 import org.springframework.context.annotation.Condition;
20 import org.springframework.context.annotation.ConditionContext;
21 import org.springframework.core.type.AnnotatedTypeMetadata;
23 import java.util.HashSet;
26 import static com.google.common.collect.Sets.newHashSet;
29 * Collects the possibilities of sources
31 public class Conditions {
32 private static final String USE_DIRECT_INTEGRATION = "direct";
34 private Conditions() {
39 * Represents the condition for using VF-C
41 public static class UseForVfc implements Condition {
42 private static Set<Condition> getAllSources() {
43 return newHashSet(new UseForVfc(), new UseForDirect());
47 public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
48 boolean anyOtherSourceAvailable = false;
49 for (Condition condition : UseForVfc.getAllSources()) {
50 if (!(condition instanceof UseForVfc) && condition.matches(conditionContext, annotatedTypeMetadata)) {
51 anyOtherSourceAvailable = true;
54 return !anyOtherSourceAvailable;
59 * Represents the condition for using ONAP components directly
61 public static class UseForDirect implements Condition {
63 public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
64 HashSet<String> activeProfiles = Sets.newHashSet(conditionContext.getEnvironment().getActiveProfiles());
65 return activeProfiles.contains(USE_DIRECT_INTEGRATION);