2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.openecomp.mso.yangDecoder.transform.impl;
23 import com.google.common.base.Charsets;
24 import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
25 import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
26 import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
27 import org.slf4j.Logger;
28 import org.slf4j.LoggerFactory;
30 import javax.ws.rs.core.MediaType;
31 import java.io.ByteArrayInputStream;
32 import java.io.ByteArrayOutputStream;
33 import java.io.IOException;
34 import java.io.InputStream;
35 import java.lang.annotation.Annotation;
38 * Created by Administrator on 2017/3/17.
40 public class YangDataTransformNN2JsonServiceImpl {
41 private static final Logger LOG = LoggerFactory.getLogger(YangDataTransformNN2JsonServiceImpl.class);
42 private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
44 public NormalizedNodeContext transformNNCFromString(String uriPath,String jsonpayload,boolean isPost){
46 InputStream entityStream = new ByteArrayInputStream(jsonpayload.getBytes(Charsets.UTF_8));
47 NormalizedNodeContext normalnodes3 = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, isPost);
50 public String transformNNCToString(NormalizedNodeContext readData) throws IOException {
51 NormalizedNodeJsonBodyWriter writer = new NormalizedNodeJsonBodyWriter();
52 ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
53 //readData.getWriterParameters().isPrettyPrint()
54 writer.writeTo(readData, NormalizedNodeContext.class, null, EMPTY_ANNOTATIONS,
55 MediaType.APPLICATION_JSON_TYPE, null, outputStream );
56 return outputStream.toString(Charsets.UTF_8.name());
58 public NormalizedNodeContext transformRPCNNCFromString(String uriPath,String jsonpayload)
60 return transformNNCFromString(uriPath,jsonpayload,true);
62 public NormalizedNodeContext transformDataObjectNNCFromString(String uriPath,String jsonpayload,boolean ispost)
64 return transformNNCFromString(uriPath,jsonpayload,ispost);
66 public NormalizedNodeContext transformNotficationNNCFromString(String uriPath,String jsonpayload)
68 return transformNNCFromString(uriPath,jsonpayload,true);