Reformat the JSON and fix checkstyle issue
[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 java.io.IOException;
27 import java.util.List;
28
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 com.att.eelf.configuration.EELFLogger;
35 import com.att.eelf.configuration.EELFManager;
36 import com.fasterxml.jackson.core.JsonParseException;
37 import com.fasterxml.jackson.databind.JsonMappingException;
38 import com.fasterxml.jackson.databind.node.ObjectNode;
39
40 /**
41  * Construct a DCAE request given CLDS objects.
42  */
43 public class DcaeReq {
44     protected static final EELFLogger logger        = EELFManager.getInstance().getLogger(DcaeReq.class);
45     protected static final EELFLogger metricsLogger = EELFManager.getInstance().getMetricsLogger();
46
47     /**
48      * Format DCAE request.
49      *
50      * @param refProp
51      * @param prop
52      * @return
53      * @throws IOException
54      * @throws JsonMappingException
55      * @throws JsonParseException
56      */
57     public static String format(RefProp refProp, ModelProperties prop) throws IOException {
58         Global globalProp = prop.getGlobal();
59
60         StringMatch smProp = prop.getType(StringMatch.class);
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> serviceIds = refProp.decodeToList("dcae.decode.service_ids", globalProp.getService());
71         JsonUtil.addArrayField(properties, "service_ids", serviceIds);
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 stringMatching = template.with("string_matching");
81         // "dcae":{
82         ObjectNode dcae = stringMatching.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, globalProp.getService(), dcae, smProp, prop);
91
92         String dcaeReq = rootNode.toString();
93         logger.info("dcaeReq=" + dcaeReq);
94         return dcaeReq;
95     }
96
97 }