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.core.JsonParseException;
27 import com.fasterxml.jackson.databind.JsonMappingException;
28 import com.fasterxml.jackson.databind.node.ObjectNode;
29 import org.onap.clamp.clds.model.prop.Global;
30 import org.onap.clamp.clds.model.prop.ModelProperties;
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.List;
36 import java.util.logging.Logger;
40 * Construct a DCAE request given CLDS objects.
42 public class DcaeReq {
43 // currently uses the java.util.logging.Logger like the Camunda engine
44 private static final Logger logger = Logger.getLogger(DcaeReq.class.getName());
47 * Format DCAE request.
53 * @throws JsonMappingException
54 * @throws JsonParseException
56 public static String format(RefProp refProp, ModelProperties prop) throws IOException {
57 Global globalProp = prop.getGlobal();
58 String service = globalProp.getService();
60 StringMatch smProp = prop.getStringMatch();
61 prop.setCurrentModelElementId(smProp.getId());
63 ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("dcae.template");
66 ObjectNode properties = rootNode.with("properties");
68 properties.put("service_name", globalProp.getService());
70 List<String> service_ids = refProp.decodeToList("dcae.decode.service_ids", globalProp.getService());
71 JsonUtil.addArrayField(properties, "service_ids", service_ids);
73 JsonUtil.addArrayField(properties, "vnf_ids", globalProp.getResourceVf());
75 JsonUtil.addArrayField(properties, "location_ids", globalProp.getLocation());
78 ObjectNode template = rootNode.with("template");
79 // "string_matching":{
80 ObjectNode string_matching = template.with("string_matching");
82 ObjectNode dcae = string_matching.with("dcae");
84 dcae.put("inputTopic", smProp.getTopicSubscribes());
85 dcae.put("outputTopic", smProp.getTopicPublishes());
86 dcae.put("closedLoopControlName", prop.getControlName());
87 dcae.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
89 // "serviceConfigurations":[
90 StringMatchPolicyReq.appendServiceConfigurations(refProp, service, dcae, smProp);
92 String dcaeReq = rootNode.toString();
93 logger.info("dcaeReq=" + dcaeReq);