From 5ed67078d4ea6822fa2d000d27ff8fca0017b6e8 Mon Sep 17 00:00:00 2001 From: gaurav Date: Mon, 23 Jul 2018 23:36:17 +0530 Subject: Adding APIs for YANG serializers Adding APIs for YANG based data format serializers. Change-Id: I8e17c475e636aa9bbf39be52d31583565bae8e92 Issue-ID: CCSDK-375 Signed-off-by: Gaurav Agrawal --- .../sli/plugins/yangserializers/Annotation.java | 59 ++++++++++++++ .../sli/plugins/yangserializers/DataFormat.java | 29 +++++++ .../yangserializers/DataFormatSerializer.java | 82 +++++++++++++++++++ .../DataFormatSerializerContext.java | 74 +++++++++++++++++ .../plugins/yangserializers/JsonSerializer.java | 49 ++++++++++++ .../sli/plugins/yangserializers/Listener.java | 34 ++++++++ .../yangserializers/MdsalSerializerHelper.java | 67 ++++++++++++++++ .../sli/plugins/yangserializers/NodeType.java | 31 ++++++++ .../plugins/yangserializers/SerializerHelper.java | 93 ++++++++++++++++++++++ .../sli/plugins/yangserializers/XmlSerializer.java | 49 ++++++++++++ 10 files changed, 567 insertions(+) create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java create mode 100644 restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java new file mode 100644 index 00000000..13f1c323 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Annotation.java @@ -0,0 +1,59 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +/** + * Representation of an entity that represents annotated attribute. + */ +public class Annotation { + + private String name; + private String value; + + /** + * Creates an instance of annotation. + * + * @param n annotation name + * @param v annotation value + */ + public Annotation(String n, String v) { + name = n; + value = v; + } + + /** + * Returns name of annotation. + * + * @return name of annotation + */ + public String name() { + return name; + } + + /** + * Returns value of annotation. + * + * @return value of annotation + */ + public String value() { + return value; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java new file mode 100644 index 00000000..0d1928b3 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormat.java @@ -0,0 +1,29 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +/** + * Representation of data format. + */ +public enum DataFormat { + XML, + JSON +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java new file mode 100644 index 00000000..bcd5991d --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializer.java @@ -0,0 +1,82 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.List; +import java.util.Map; + +/** + * Abstraction of serializer to encode/decode context memory parameters + * to/from specified data format. + */ +public abstract class DataFormatSerializer { + + private DataFormat dataFormat; + private DataFormatSerializerContext serializerContext; + + /** + * Creates an instance of data format serializer. + * + * @param dataFormat type of data format + * @param serializerContext data format serializer context + */ + protected DataFormatSerializer(DataFormat dataFormat, + DataFormatSerializerContext serializerContext) { + this.dataFormat = dataFormat; + this.serializerContext = serializerContext; + } + + /** + * Encodes context memory parameters to data format. + * + * @param param context memory parameter + * @param annotations annotations + * @return data format body + */ + public abstract String encode(Map param, + Map> annotations); + + /** + * Decodes data format body to context memory parameters. + * + * @param dataFormatBody abstract node + * @return context memory parameters + */ + public abstract Map decode(String dataFormatBody); + + /** + * Returns data format serializer context. + * + * @return data format serializer context + */ + public DataFormatSerializerContext serializerContext() { + return serializerContext; + } + + /** + * Returns supported data format. + * + * @return supported data format + */ + public DataFormat dataFormat() { + return dataFormat; + } +} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java new file mode 100644 index 00000000..50cb2daf --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/DataFormatSerializerContext.java @@ -0,0 +1,74 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.Map; + +/** + * Abstraction of data format serializer context. + */ +public class DataFormatSerializerContext { + + private Listener listener; + private String uri; + private Map protocolAnnotation; + + /** + * Creates an instance of data format serializer context. + * + * @param listener data format listener + * @param uri URI corresponding to instance identifier + * @param protocolAnnotation protocol annotations + */ + public DataFormatSerializerContext(Listener listener, String uri, + Map protocolAnnotation) { + this.listener = listener; + this.uri = uri; + this.protocolAnnotation = protocolAnnotation; + } + + /** + * Retruns data format listener. + * + * @return data format listener + */ + public Listener listener() { + return listener; + } + + /** + * Returns URI. + * + * @return URI + */ + public String uri() { + return uri; + } + + /** + * Returns protocol annotations. + * + * @return protocol annotations + */ + public Map getProtocolAnnotation() { + return protocolAnnotation; + } +} \ No newline at end of file diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java new file mode 100644 index 00000000..072cfb09 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/JsonSerializer.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.List; +import java.util.Map; + +/** + * Representation of JSON serializer. + */ +public class JsonSerializer extends DataFormatSerializer { + + /** + * Creates an instance of data format serializer. + * + * @param serializerContext data format serializer context + */ + protected JsonSerializer(DataFormatSerializerContext serializerContext) { + super(DataFormat.JSON, serializerContext); + } + + @Override + public String encode(Map param, Map> annotations) { + return null; + } + + @Override + public Map decode(String dataFormatBody) { + return null; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java new file mode 100644 index 00000000..a0976822 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/Listener.java @@ -0,0 +1,34 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +/** + * Abstraction of listener. + */ +public interface Listener { + + /** + * Returns serializer helper for this listener. + * + * @return serializer helper + */ + SerializerHelper serializerHelper(); +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java new file mode 100644 index 00000000..c9bda511 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/MdsalSerializerHelper.java @@ -0,0 +1,67 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.Map; +import org.opendaylight.yangtools.yang.model.api.SchemaNode; + +/** + * Representation of MDSAL based schema helper. + */ +public class MdsalSerializerHelper extends SerializerHelper { + + protected MdsalSerializerHelper(SchemaNode node, String uri) { + super(node, uri); + } + + @Override + public SchemaNode getRootContext() { + return null; + } + + @Override + public SchemaNode getCurContext() { + return null; + } + + @Override + public SchemaNode getChildContext(SchemaNode schemaNode, String name, String namespace) { + return null; + } + + @Override + public NodeType getNodeType(SchemaNode schemaNode) { + return null; + } + + @Override + public void addNode(String name, String namespace, String value, String valNamespace, NodeType type) { + } + + @Override + public void exitNode() { + } + + @Override + public Map getProperties() { + return null; + } +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java new file mode 100644 index 00000000..5a63d632 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/NodeType.java @@ -0,0 +1,31 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +/** + * Representation of type of data node. + */ +public enum NodeType { + SINGLE_INSTANCE, + MULTI_INSTANCE, + SINGLE_INSTANCE_LEAF, + MULTI_INSTANCE_LEAF +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java new file mode 100644 index 00000000..a4bbce52 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/SerializerHelper.java @@ -0,0 +1,93 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.Map; + +/** + * Abstraction of an entity which helps the data format serializers to obtain + * schema context details and to build properties from data. + * + * @param type of schema node + */ +public abstract class SerializerHelper { + + private T rootSchema; + private String rootURI; + + protected SerializerHelper(T t, String uri) { + rootSchema = t; + } + + /** + * Returns root schema context node. + * + * @return root schema context node + */ + protected abstract T getRootContext(); + + /** + * Returns current schema context node. + * + * @return current schema context node + */ + protected abstract T getCurContext(); + + /** + * Returns child schema context node. + * + * @return child schema context node + */ + protected abstract T getChildContext(T t, String name, String namespace); + + /** + * Returns type of node + * @param t node + * @return node type + */ + protected abstract NodeType getNodeType(T t); + + /** + * Adds a node to current tree. + * + * @param name name of node + * @param namespace namespace of node, it can be either module name or + * namespace, null indicates parent namespace + * @param value value of node, in case it's leaf/leaf-list node + * @param valNamespace value namespace for identityref, could be module + * name or namespace + * @param type type of node if known like in case of JSON + */ + protected abstract void addNode(String name, String namespace, String value, + String valNamespace, NodeType type); + + /** + * Exits the node, in case if it's leaf node add to properties map. + */ + protected abstract void exitNode(); + + /** + * Returns the properties built corresponding to data. + * + * @return properties map + */ + protected abstract Map getProperties(); +} diff --git a/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java new file mode 100644 index 00000000..ba5d8ed2 --- /dev/null +++ b/restconf-client/provider/src/main/java/org/onap/ccsdk/sli/plugins/yangserializers/XmlSerializer.java @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP - CCSDK + * ================================================================================ + * Copyright (C) 2018 Huawei Technologies Co., Ltd. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + +package org.onap.ccsdk.sli.plugins.yangserializers; + +import java.util.List; +import java.util.Map; + +/** + * Representation of XML serializer. + */ +public class XmlSerializer extends DataFormatSerializer { + + /** + * Creates an instance of XML serializer. + * + * @param serializerContext data format serializer context + */ + protected XmlSerializer(DataFormatSerializerContext serializerContext) { + super(DataFormat.XML, serializerContext); + } + + @Override + public String encode(Map param, Map> annotations) { + return null; + } + + @Override + public Map decode(String dataFormatBody) { + return null; + } +} \ No newline at end of file -- cgit 1.2.3-korg