Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-plugins / src / main / java / org / onap / dcae / apod / analytics / cdap / plugins / domain / config / filter / JsonPathFilterPluginConfig.java
1 /*
2  * ===============================LICENSE_START======================================
3  *  dcae-analytics
4  * ================================================================================
5  *    Copyright © 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
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.dcae.apod.analytics.cdap.plugins.domain.config.filter;
22
23 import co.cask.cdap.api.annotation.Description;
24 import co.cask.cdap.api.annotation.Macro;
25 import co.cask.cdap.api.annotation.Name;
26 import com.google.common.base.Objects;
27 import org.onap.dcae.apod.analytics.cdap.common.settings.CDAPBasePluginConfig;
28
29 /**
30  * Configuration for Json Path Filter Plugin
31  *
32  * @author Rajiv Singla . Creation Date: 3/2/2017.
33  */
34 public class JsonPathFilterPluginConfig extends CDAPBasePluginConfig {
35
36     private static final long serialVersionUID = 1L;
37
38     @Name("incomingJsonFieldName")
39     @Description("Input schema field name that contain JSON used for filtering")
40     @Macro
41     protected String incomingJsonFieldName;
42
43
44     @Name("outputSchemaFieldName")
45     @Description("Name of the nullable boolean schema field name that will contain result of the filter matching")
46     @Macro
47     protected String outputSchemaFieldName;
48
49
50     @Name("jsonFilterMappings")
51     @Macro
52     @Description("Filters incoming JSON based on given filter mappings - in terms of JSON path and expected values." +
53             "Right hand side contains JSON path. Left hand side contains semicolon (';') separated expected values " +
54             "for that JSON Path. If all provided JSON Path mappings and corresponding values matches - " +
55             "output schema field will be marked as true")
56     protected String jsonFilterMappings;
57
58
59     @Name("schema")
60     @Description("Output Schema")
61     protected String schema;
62
63
64     public JsonPathFilterPluginConfig(final String referenceName, final String incomingJsonFieldName,
65                                       final String outputSchemaFieldName, final String jsonFilterMappings,
66                                       final String schema) {
67         this.referenceName = referenceName;
68         this.incomingJsonFieldName = incomingJsonFieldName;
69         this.outputSchemaFieldName = outputSchemaFieldName;
70         this.jsonFilterMappings = jsonFilterMappings;
71         this.schema = schema;
72     }
73
74     /**
75      * Provides incoming plugin schema field name which contains json used to apply filter
76      *
77      * @return  name of incoming schema field containing JSON to be filtered
78      */
79     public String getIncomingJsonFieldName() {
80         return incomingJsonFieldName;
81     }
82
83     /**
84      * Provides plugin output schema filed name that will contain result of filter application
85      * It must be nullable and boolean type
86      *
87      * @return name of outgoing schema filed name that will contain filtering result
88      */
89     public String getOutputSchemaFieldName() {
90         return outputSchemaFieldName;
91     }
92
93     /**
94      * Provides JSON filter mappings. LHS contains JSON path value and RHS contains expected
95      * values separated by semicolon
96      *
97      *
98      * @return String for JSON filter mappings
99      */
100     public String getJsonFilterMappings() {
101         return jsonFilterMappings;
102     }
103
104     /**
105      * Output Schema
106      *
107      * @return output schema string
108      */
109     public String getSchema() {
110         return schema;
111     }
112
113
114     @Override
115     public String toString() {
116         return Objects.toStringHelper(this)
117                 .add("referenceName", referenceName)
118                 .add("incomingJsonFieldName", incomingJsonFieldName)
119                 .add("outputSchemaFieldName", outputSchemaFieldName)
120                 .add("jsonFilterMappings", jsonFilterMappings)
121                 .add("schema", schema)
122                 .toString();
123     }
124
125 }