Removing jackson to mitigate cve-2017-4995
[vfc/nfvo/driver/vnfm/svnfm.git] / nokiav2 / driver / src / main / java / org / onap / vfc / nfvo / driver / vnfm / svnfm / nokia / spring / Conditions.java
1 /*
2  * Copyright 2016-2017, Nokia Corporation
3  *
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  *
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.
15  */
16 package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.spring;
17
18 import com.google.common.collect.Sets;
19 import java.util.HashSet;
20 import java.util.Set;
21 import org.springframework.context.annotation.Condition;
22 import org.springframework.context.annotation.ConditionContext;
23 import org.springframework.core.type.AnnotatedTypeMetadata;
24
25 import static com.google.common.collect.Sets.newHashSet;
26
27 /**
28  * Collects the possibilities of sources
29  */
30 public class Conditions {
31     private static final String USE_DIRECT_INTEGRATION = "direct";
32
33     private Conditions() {
34         //use static way
35     }
36
37     /**
38      * Represents the condition for using VF-C
39      */
40     public static class UseForVfc implements Condition {
41         private static Set<Condition> getAllSources() {
42             return newHashSet(new UseForVfc(), new UseForDirect());
43         }
44
45         @Override
46         public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
47             boolean anyOtherSourceAvailable = false;
48             for (Condition condition : UseForVfc.getAllSources()) {
49                 if (!(condition instanceof UseForVfc) && condition.matches(conditionContext, annotatedTypeMetadata)) {
50                     anyOtherSourceAvailable = true;
51                 }
52             }
53             return !anyOtherSourceAvailable;
54         }
55     }
56
57     /**
58      * Represents the condition for using ONAP components directly
59      */
60     public static class UseForDirect implements Condition {
61         @Override
62         public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) {
63             HashSet<String> activeProfiles = Sets.newHashSet(conditionContext.getEnvironment().getActiveProfiles());
64             return activeProfiles.contains(USE_DIRECT_INTEGRATION);
65         }
66     }
67 }