Fix checkstyle violations in sdc/jtosca
[sdc/sdc-tosca.git] / src / main / java / org / onap / sdc / toscaparser / api / parameters / Annotation.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdc.toscaparser.api.parameters;
22
23 import org.onap.sdc.toscaparser.api.Property;
24 import org.onap.sdc.toscaparser.api.elements.enums.ToscaElementNames;
25
26 import java.util.ArrayList;
27 import java.util.Map;
28 import java.util.Optional;
29 import java.util.stream.Collectors;
30
31 public class Annotation {
32
33     private static final String HEAT = "HEAT";
34     private String name;
35     private String type;
36     private ArrayList<Property> properties;
37
38
39     public Annotation() {
40     }
41
42     @SuppressWarnings("unchecked")
43     public Annotation(Map.Entry<String, Object> annotationEntry) {
44         if (annotationEntry != null) {
45             name = annotationEntry.getKey();
46             Map<String, Object> annValue = (Map<String, Object>) annotationEntry.getValue();
47             type = (String) annValue.get(ToscaElementNames.TYPE.getName());
48             properties = fetchProperties((Map<String, Object>) annValue.get(ToscaElementNames.PROPERTIES.getName()));
49         }
50     }
51
52     public String getName() {
53         return name;
54     }
55
56     public void setName(String name) {
57         this.name = name;
58     }
59
60     public String getType() {
61         return type;
62     }
63
64     public void setType(String type) {
65         this.type = type;
66     }
67
68     public ArrayList<Property> getProperties() {
69         return properties;
70     }
71
72     public void setProperties(ArrayList<Property> properties) {
73         this.properties = properties;
74     }
75
76     private ArrayList<Property> fetchProperties(Map<String, Object> properties) {
77         if (properties != null) {
78             return (ArrayList<Property>) properties.entrySet().stream()
79                     .map(Property::new)
80                     .collect(Collectors.toList());
81         }
82         return null;
83     }
84
85     public boolean isHeatSourceType() {
86         if (properties == null) {
87             return false;
88         }
89         Optional<Property> sourceType = properties.stream()
90                 .filter(p -> p.getName().equals(ToscaElementNames.SOURCE_TYPE.getName()))
91                 .findFirst();
92         if (!sourceType.isPresent()) {
93             return false;
94         }
95         return sourceType.get().getValue() != null && ((String) sourceType.get().getValue()).equals(HEAT);
96     }
97
98 }