[CLAMP-1] Initial ONAP CLAMP seed code commit
[clamp.git] / src / main / java / org / onap / clamp / clds / client / req / DcaeReq.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.client.req;
25
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;
33
34 import java.io.IOException;
35 import java.util.List;
36 import java.util.logging.Logger;
37
38
39 /**
40  * Construct a DCAE request given CLDS objects.
41  */
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());
45
46     /**
47      * Format DCAE request.
48      *
49      * @param refProp
50      * @param prop
51      * @return
52      * @throws IOException
53      * @throws JsonMappingException
54      * @throws JsonParseException
55      */
56     public static String format(RefProp refProp, ModelProperties prop) throws IOException {
57         Global globalProp = prop.getGlobal();
58         String service = globalProp.getService();
59
60         StringMatch smProp = prop.getStringMatch();
61         prop.setCurrentModelElementId(smProp.getId());
62
63         ObjectNode rootNode = (ObjectNode) refProp.getJsonTemplate("dcae.template");
64
65         //   "properties":{
66         ObjectNode properties = rootNode.with("properties");
67         //     "service_name":
68         properties.put("service_name", globalProp.getService());
69         //     "service_ids":[
70         List<String> service_ids = refProp.decodeToList("dcae.decode.service_ids", globalProp.getService());
71         JsonUtil.addArrayField(properties, "service_ids", service_ids);
72         //     "vnf_ids":[
73         JsonUtil.addArrayField(properties, "vnf_ids", globalProp.getResourceVf());
74         //     "location_ids":[
75         JsonUtil.addArrayField(properties, "location_ids", globalProp.getLocation());
76
77         //   "template":{
78         ObjectNode template = rootNode.with("template");
79         //     "string_matching":{
80         ObjectNode string_matching = template.with("string_matching");
81         //       "dcae":{
82         ObjectNode dcae = string_matching.with("dcae");
83
84         dcae.put("inputTopic", smProp.getTopicSubscribes());
85         dcae.put("outputTopic", smProp.getTopicPublishes());
86         dcae.put("closedLoopControlName", prop.getControlName());
87         dcae.put("policyName", prop.getCurrentPolicyScopeAndPolicyName());
88
89         //         "serviceConfigurations":[
90         StringMatchPolicyReq.appendServiceConfigurations(refProp, service, dcae, smProp);
91
92         String dcaeReq = rootNode.toString();
93         logger.info("dcaeReq=" + dcaeReq);
94         return dcaeReq;
95     }
96
97 }