Code Improvement
[clamp.git] / src / main / java / org / onap / clamp / clds / model / prop / ServiceConfiguration.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP CLAMP
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights
6  *                             reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END============================================
20  * ===================================================================
21  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23
24 package org.onap.clamp.clds.model.prop;
25
26 import java.util.HashMap;
27 import java.util.Iterator;
28 import java.util.List;
29 import java.util.Map;
30
31 import com.att.eelf.configuration.EELFLogger;
32 import com.att.eelf.configuration.EELFManager;
33 import com.fasterxml.jackson.databind.JsonNode;
34
35 /**
36  * Parse serviceConfigurations from Tca json properties.
37  * <p>
38  * Example json:
39  * {"Tca_0aji7go":{"Group1":[{"name":"rgname","value":"1493749598520"},{
40  * "name":"rgfriendlyname","value":"Group1"},{"name":"policyName","value":
41  * "Policy1"},{"name":"policyId","value":"1"},{"serviceConfigurations":[[{"name"
42  * :"aaiMatchingFields","value":["complex.city","vserver.vserver-name"]},{"name"
43  * :"aaiSendFields","value":["complex.city","vserver.vserver-name"]},{"name":
44  * "eventSeverity","value":["OK"]},{"name":"eventSourceType","value":[""]},{
45  * "name":"timeWindow","value":["100"]},{"name":"ageLimit","value":["100"]},{
46  * "name":"createClosedLoopEventId","value":["Initial"]},{"name":
47  * "outputEventName","value":["ONSET"]}]]}],"Group2":[{"name":"rgname","value":
48  * "1493749665149"},{"name":"rgfriendlyname","value":"Group2"},{"name":
49  * "policyName","value":"Policy2"},{"name":"policyId","value":"2"},{
50  * "serviceConfigurations":[[{"name":"aaiMatchingFields","value":[
51  * "cloud-region.identity-url","vserver.vserver-name"]},{"name":"aaiSendFields",
52  * "value":["cloud-region.identity-url","vserver.vserver-name"]},{"name":
53  * "eventSeverity","value":["NORMAL"]},{"name":"eventSourceType","value":[""]},{
54  * "name":"timeWindow","value":["1000"]},{"name":"ageLimit","value":["1000"]},{
55  * "name":"createClosedLoopEventId","value":["Initial"]},{"name":
56  * "outputEventName","value":["ONSET"]}],[{"name":"aaiMatchingFields","value":[
57  * "generic-vnf.vnf-name","vserver.vserver-name"]},{"name":"aaiSendFields",
58  * "value":["generic-vnf.vnf-name","vserver.vserver-name"]},{"name":
59  * "eventSeverity","value":["CRITICAL"]},{"name":"eventSourceType","value":[""]}
60  * ,{"name":"timeWindow","value":["3000"]},{"name":"ageLimit","value":["3000"]},
61  * {"name":"createClosedLoopEventId","value":["Initial"]},{"name":
62  * "outputEventName","value":["ABATED"]}]]}]}}
63  *
64  */
65 public class ServiceConfiguration {
66
67     protected static final EELFLogger         logger      = EELFManager.getInstance().getLogger(ServiceConfiguration.class);
68     protected static final EELFLogger   auditLogger = EELFManager.getInstance().getAuditLogger();
69
70     private final List<String>        aaiMatchingFields;
71     private final List<String>        aaiSendFields;
72     // private final String groupNumber;
73     private final List<String>        resourceVf;
74     private final List<String>        resourceVfc;
75     private final String              timeWindow;
76     private final String              ageLimit;
77     private final String              createClosedLoopEventId;
78     private final String              outputEventName;
79     private final Map<String, String> stringSet;
80
81     /**
82      * Parse serviceConfigurations given json node.
83      *
84      * @param node
85      */
86     public ServiceConfiguration(JsonNode node) {
87         aaiMatchingFields = AbstractModelElement.getValuesByName(node, "aaiMatchingFields");
88         aaiSendFields = AbstractModelElement.getValuesByName(node, "aaiSendFields");
89         // groupNumber = ModelElement.getValueByName(node, "groupNumber");
90         resourceVf = AbstractModelElement.getValuesByName(node, "vf");
91         resourceVfc = AbstractModelElement.getValuesByName(node, "vfc");
92         timeWindow = AbstractModelElement.getValueByName(node, "timeWindow");
93         ageLimit = AbstractModelElement.getValueByName(node, "ageLimit");
94         createClosedLoopEventId = AbstractModelElement.getValueByName(node, "createClosedLoopEventId");
95         outputEventName = AbstractModelElement.getValueByName(node, "outputEventName");
96
97         // process the stringSet fields
98         JsonNode ssNodes = node.findPath("stringSet");
99         Iterator<JsonNode> itr = ssNodes.elements();
100         stringSet = new HashMap<>();
101         while (itr.hasNext()) {
102             JsonNode ssNode = itr.next();
103             String key = ssNode.path("name").asText();
104             String value = ssNode.path("value").path(0).asText();
105             if (key.length() != 0 && value.length() != 0) {
106                 // only add string set field if not null
107                 logger.debug("stringSet: " + key + "=" + value);
108                 stringSet.put(key, value);
109             }
110         }
111     }
112
113     /**
114      * @return the aaiMatchingFields
115      */
116     public List<String> getaaiMatchingFields() {
117         return aaiMatchingFields;
118     }
119
120     /**
121      * @return the aaiSendFields
122      */
123     public List<String> getaaiSendFields() {
124         return aaiSendFields;
125     }
126
127     /**
128      * @return the groupNumber
129      */ /*
130         * public String getGroupNumber() { return groupNumber; }
131         */
132     /**
133      * @return the resourceVf
134      */
135     public List<String> getResourceVf() {
136         return resourceVf;
137     }
138
139     /**
140      * @return the resourceVfc
141      */
142     public List<String> getResourceVfc() {
143         return resourceVfc;
144     }
145
146     /**
147      * @return the timeWindow
148      */
149     public String getTimeWindow() {
150         return timeWindow;
151     }
152
153     /**
154      * @return the ageLimit
155      */
156     public String getAgeLimit() {
157         return ageLimit;
158     }
159
160     /**
161      * @return the createClosedLoopEventId
162      */
163     public String getCreateClosedLoopEventId() {
164         return createClosedLoopEventId;
165     }
166
167     /**
168      * @return the outputEventName
169      */
170     public String getOutputEventName() {
171         return outputEventName;
172     }
173
174     /**
175      * @return the stringSet
176      */
177     public Map<String, String> getStringSet() {
178         return stringSet;
179     }
180
181 }