2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
24 package org.onap.clamp.clds.client.req;
26 import com.fasterxml.jackson.databind.node.ArrayNode;
27 import com.fasterxml.jackson.databind.node.ObjectNode;
28 import org.onap.clamp.clds.model.prop.Global;
29 import org.onap.clamp.clds.model.prop.ModelProperties;
30 import org.onap.clamp.clds.model.prop.ServiceConfiguration;
31 import org.onap.clamp.clds.model.prop.StringMatch;
32 import org.onap.clamp.clds.model.refprop.RefProp;
34 import java.io.IOException;
35 import java.util.Iterator;
36 import java.util.Map.Entry;
37 import java.util.logging.Logger;
41 * Construct a Policy for String Match Micro Service request given CLDS objects.
43 public class StringMatchPolicyReq {
44 // currently uses the java.util.logging.Logger like the Camunda engine
45 private static final Logger logger = Logger.getLogger(StringMatchPolicyReq.class.getName());
48 * Format Policy String Match request.
55 public static String format(RefProp refProp, ModelProperties prop) throws IOException {
56 Global global = prop.getGlobal();
57 String service = global.getService();
59 StringMatch sm = prop.getStringMatch();
60 prop.setCurrentModelElementId(sm.getId());
61 ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("sm.template", service);
64 rootNode.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
67 ObjectNode content = rootNode.with("content");
69 // "closedLoopControlName":
70 content.put("closedLoopControlName", prop.getControlName());
72 // "serviceConfigurations":[
73 appendServiceConfigurations(refProp, service, content, sm);
75 String stringMatchPolicyReq = rootNode.toString();
76 logger.info("stringMatchPolicyReq=" + stringMatchPolicyReq);
77 return stringMatchPolicyReq;
81 * Add serviceConfigurations to json
87 public static void appendServiceConfigurations(RefProp refProp, String service, ObjectNode appendToNode, StringMatch sm) throws IOException {
88 // "serviceConfigurations":{
89 ObjectNode scNodes = appendToNode.with("serviceConfigurations");
91 Iterator<ServiceConfiguration> scItr = sm.getServiceConfigurations().iterator();
93 while (scItr.hasNext()) {
94 ServiceConfiguration sc = scItr.next();
98 String keyValue = "Item" + index;
99 ObjectNode scNode = (ObjectNode) refProp.getJsonTemplate("sm.sc.template", service);
100 scNodes.set(keyValue, scNode);
102 // "rulegroup":"abc",
103 String rulegroupInd = refProp.getStringValue("sm.rulegroup", service);
104 String groupNumber = sc.getGroupNumber();
105 if (rulegroupInd != null && rulegroupInd.equalsIgnoreCase("true") && groupNumber != null && groupNumber.length() > 0) {
107 //String rulegroup = (sc.getResourceVf() == null ? "" : String.join(" ", sc.getResourceVf())) + " - " + (sc.getResourceVfc() == null ? "" : String.join(" ", sc.getResourceVfc()));
108 scNode.put("rulegroup", groupNumber);
111 // "aaiMatchingFields" : ["VM_NAME"],
112 JsonUtil.addArrayField(scNode, "aaiMatchingFields", sc.getaaiMatchingFields());
113 // "aaiSendFields" : ["VMID", "TenantID"],
114 JsonUtil.addArrayField(scNode, "aaiSendFields", sc.getaaiSendFields());
117 ArrayNode ssNode = scNode.putArray("stringSet");
118 // ObjectNode ssNode = scNode.with("stringSet");
119 for (Entry<String, String> entry : sc.getStringSet().entrySet()) {
120 // exclude eventSourceType
121 if (!entry.getKey().equals("eventSourceType")) {
122 ssNode.add(entry.getKey());
123 ssNode.add(entry.getValue());
128 scNode.put("timeWindow", sc.getTimeWindow());
129 // "ageLimit": "3600",
130 scNode.put("ageLimit", sc.getAgeLimit());
131 // "createClosedLoopEventId" : "Initial",
132 scNode.put("createClosedLoopEventId", sc.getCreateClosedLoopEventId());
133 // "outputEventName": "OnSet"
134 scNode.put("outputEventName", sc.getOutputEventName());