[CLAMP-1] Initial ONAP CLAMP seed code commit
[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 com.fasterxml.jackson.databind.JsonNode;
27
28 import java.util.HashMap;
29 import java.util.Iterator;
30 import java.util.List;
31 import java.util.Map;
32 import java.util.logging.Logger;
33
34 /**
35  * Parse serviceConfigurations from StringMatch json properties.
36  * <p>
37  * Example json: "StringMatch_0c2cy0c":[[{"name":"topicPublishes","value":"DCAE-CL-EVENT"}],{"serviceConfigurations":[[{"name":"aaiMatchingFields","value":["VMID"]},{"name":"aaiSendFields","value":["VNFNAME","LOCID"]},{"name":"vnf","value":["aSBG"]},{"name":"timeWindow","value":["0"]},{"name":"ageLimit","value":["1600"]},{"name":"createClosedLoopEventId","value":["Initial"]},{"name":"outputEventName","value":["OnSet"]},{"stringSet":[{"name":"alarmCondition","value":["authenticationFailure"]},{"name":"eventSeverity","value":["NORMAL"]},{"name":"eventSourceType","value":["f5BigIP"]}]}],[{"name":"aaiMatchingFields","value":["VMID"]},{"name":"aaiSendFields","value":["VMID","Identiy","VNFNAME"]},{"name":"vnf","value":["aSBG"]},{"name":"timeWindow","value":["0"]},{"name":"ageLimit","value":["1600"]},{"name":"createClosedLoopEventId","value":["Close"]},{"name":"outputEventName","value":["Abatement"]},{"stringSet":[{"name":"alarmCondition","value":["authenticationFailure"]},{"name":"eventSeverity","value":["NORMAL"]},{"name":"eventSourceType","value":["f5BigIP"]}]}]]}]
38  */
39 public class ServiceConfiguration {
40
41     private static final Logger logger = Logger.getLogger(ServiceConfiguration.class.getName());
42
43     private final List<String> aaiMatchingFields;
44     private final List<String> aaiSendFields;
45     private final String groupNumber;
46     private final List<String> resourceVf;
47     private final List<String> resourceVfc;
48     private final String timeWindow;
49     private final String ageLimit;
50     private final String createClosedLoopEventId;
51     private final String outputEventName;
52     private final Map<String, String> stringSet;
53
54     /**
55      * Parse serviceConfigurations given json node.
56      *
57      * @param node
58      */
59     public ServiceConfiguration(JsonNode node) {
60         aaiMatchingFields = ModelElement.getValuesByName(node, "aaiMatchingFields");
61         aaiSendFields = ModelElement.getValuesByName(node, "aaiSendFields");
62         groupNumber = ModelElement.getValueByName(node, "groupNumber");
63         resourceVf = ModelElement.getValuesByName(node, "vf");
64         resourceVfc = ModelElement.getValuesByName(node, "vfc");
65         timeWindow = ModelElement.getValueByName(node, "timeWindow");
66         ageLimit = ModelElement.getValueByName(node, "ageLimit");
67         createClosedLoopEventId = ModelElement.getValueByName(node, "createClosedLoopEventId");
68         outputEventName = ModelElement.getValueByName(node, "outputEventName");
69
70         // process the stringSet fields
71         JsonNode ssNodes = node.findPath("stringSet");
72         Iterator<JsonNode> itr = ssNodes.elements();
73         stringSet = new HashMap<>();
74         while (itr.hasNext()) {
75             JsonNode ssNode = itr.next();
76             String key = ssNode.path("name").asText();
77             String value = ssNode.path("value").path(0).asText();
78             if (key.length() != 0 && value.length() != 0) {
79                 // only add string set field if not null
80                 logger.fine("stringSet: " + key + "=" + value);
81                 stringSet.put(key, value);
82             }
83         }
84     }
85
86     /**
87      * @return the aaiMatchingFields
88      */
89     public List<String> getaaiMatchingFields() {
90         return aaiMatchingFields;
91     }
92
93     /**
94      * @return the aaiSendFields
95      */
96     public List<String> getaaiSendFields() {
97         return aaiSendFields;
98     }
99
100     /**
101      * @return the groupNumber
102      */
103     public String getGroupNumber() {
104         return groupNumber;
105     }
106
107     /**
108      * @return the resourceVf
109      */
110     public List<String> getResourceVf() {
111         return resourceVf;
112     }
113
114     /**
115      * @return the resourceVfc
116      */
117     public List<String> getResourceVfc() {
118         return resourceVfc;
119     }
120
121     /**
122      * @return the timeWindow
123      */
124     public String getTimeWindow() {
125         return timeWindow;
126     }
127
128     /**
129      * @return the ageLimit
130      */
131     public String getAgeLimit() {
132         return ageLimit;
133     }
134
135     /**
136      * @return the createClosedLoopEventId
137      */
138     public String getCreateClosedLoopEventId() {
139         return createClosedLoopEventId;
140     }
141
142     /**
143      * @return the outputEventName
144      */
145     public String getOutputEventName() {
146         return outputEventName;
147     }
148
149     /**
150      * @return the stringSet
151      */
152     public Map<String, String> getStringSet() {
153         return stringSet;
154     }
155
156 }