Add abstract properties node tree
[ccsdk/sli/plugins.git] / restconf-client / provider / src / main / java / org / onap / ccsdk / sli / plugins / yangserializers / pnserializer / PropertiesNodeSerializer.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - CCSDK
4  * ================================================================================
5  * Copyright (C) 2018 Huawei Technologies Co., Ltd. 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.ccsdk.sli.plugins.yangserializers.pnserializer;
22
23 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
24
25 import java.util.Map;
26
27 /**
28  * Abstraction of an entity to enable encoding and decoding of properties
29  * to an abstract properties node tree using YANG based schema.
30  * This serializer will be used by other data format serializers and will keep
31  * them abstract from properties nuances thereby enabling quick addition of any
32  * new data format serializer.
33  *
34  * @param <T> type of schema node
35  * @param <P> schema context of the model
36  */
37 public abstract class PropertiesNodeSerializer<T, P> {
38
39     /**
40      * Schema node from which the property is made.
41      */
42     private T schemaNode;
43
44     /**
45      * Schema context of the model.
46      */
47     private P schemaCtx;
48
49     /**
50      * URL pointing to the schema node.
51      */
52     private String uri;
53
54     /**
55      * Creates the properties node serializer.
56      *
57      * @param schemaNode schema node.
58      * @param schemaCtx schema context
59      * @param uri URL of the request
60      */
61     public PropertiesNodeSerializer(T schemaNode, P schemaCtx, String uri) {
62         this.schemaNode = schemaNode;
63         this.schemaCtx = schemaCtx;
64         this.uri = uri;
65     }
66
67     /**
68      * Encodes from properties to properties-node tree.
69      *
70      * @param paramMap parameter map
71      * @throws SvcLogicException fails to encode properties to properties node
72      * @return properties node
73      */
74     public abstract PropertiesNode encode(Map<String, String> paramMap) throws SvcLogicException;
75
76     /**
77      * Decodes from properties-node to properties map.
78      *
79      * @param propertiesNode properties-node
80      * @throws SvcLogicException fails to decode properties node to properties
81      * @return parameter map
82      */
83     public abstract Map<String, String> decode(PropertiesNode propertiesNode) throws SvcLogicException;
84
85     /**
86      * Returns the schema node of the property
87      *
88      * @return schema node
89      */
90     public T schemaNode(){
91         return schemaNode;
92     }
93
94     /**
95      * Returns the schema context
96      *
97      * @return schema node
98      */
99     public P schemaCtx() {
100         return schemaCtx;
101     }
102
103     /**
104      * Returns the URI.
105      *
106      * @return uri
107      */
108     public String uri() {
109         return uri;
110     }
111 }