Catalog alignment
[sdc.git] / catalog-be / src / main / java / org / openecomp / sdc / be / components / impl / utils / DirectivesUtils.java
1 /*
2  * Copyright © 2016-2018 European Support Limited
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
17 package org.openecomp.sdc.be.components.impl.utils;
18
19 import com.google.common.collect.Sets;
20 import org.apache.commons.collections.CollectionUtils;
21 import org.apache.commons.lang.StringUtils;
22
23 import java.util.List;
24 import java.util.Optional;
25
26 public class DirectivesUtils {
27
28     public static final String SUBSTITUTABLE = "substitutable";
29     public static final String SELECTABLE = "selectable";
30     public enum DIRECTIVE {
31
32         SUBSTITUTABLE(DirectivesUtils.SUBSTITUTABLE), SELECTABLE(DirectivesUtils.SELECTABLE);
33
34         private final String value;
35
36         DIRECTIVE(String value) {
37             this.value = value;
38         }
39
40         @Override
41         public String toString() {
42             return value;
43         }
44
45     }
46
47     public static Optional<DIRECTIVE> getDirective(String inDirective) {
48         if (StringUtils.isEmpty(inDirective)) {
49             return Optional.empty();
50         }
51
52         return Sets.newHashSet(DIRECTIVE.values()).stream()
53                    .filter(directive -> directive.toString().equals(inDirective)).findAny();
54     }
55
56     public static boolean isValid(List<String> inDirectives){
57         if (CollectionUtils.isEmpty(inDirectives)){
58             return true;
59         }
60         return inDirectives.stream().allMatch(directive -> getDirective(directive).isPresent());
61     }
62
63 }