2 * ===============================LICENSE_START======================================
\r
4 * ================================================================================
\r
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * ================================================================================
\r
7 * Licensed under the Apache License, Version 2.0 (the "License");
\r
8 * you may not use this file except in compliance with the License.
\r
9 * You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing, software
\r
14 * distributed under the License is distributed on an "AS IS" BASIS,
\r
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
16 * See the License for the specific language governing permissions and
\r
17 * limitations under the License.
\r
18 * ============================LICENSE_END===========================================
\r
21 package org.openecomp.dcae.apod.analytics.cdap.plugins.validator;
\r
23 import co.cask.cdap.api.data.schema.Schema;
\r
24 import org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils;
\r
25 import org.openecomp.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;
\r
26 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.filter.JsonPathFilterPluginConfig;
\r
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.utils.CDAPPluginUtils;
\r
28 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
\r
31 * Validator to validate {@link JsonPathFilterPluginConfig}
\r
33 * @author Rajiv Singla . Creation Date: 3/2/2017.
\r
35 public class JsonPathFilterPluginConfigValidator implements CDAPAppSettingsValidator<JsonPathFilterPluginConfig,
\r
36 GenericValidationResponse<JsonPathFilterPluginConfig>> {
\r
38 private static final long serialVersionUID = 1L;
\r
41 public GenericValidationResponse<JsonPathFilterPluginConfig> validateAppSettings(
\r
42 final JsonPathFilterPluginConfig jsonPathFilterPluginConfig) {
\r
44 final GenericValidationResponse<JsonPathFilterPluginConfig> validationResponse =
\r
45 new GenericValidationResponse<>();
\r
47 final String jsonFilterMappings = jsonPathFilterPluginConfig.getJsonFilterMappings();
\r
48 if (ValidationUtils.isEmpty(jsonFilterMappings)) {
\r
50 validationResponse.addErrorMessage("JsonFilterMappings", "Json Filter Mappings must be present");
\r
54 final String matchedField = jsonPathFilterPluginConfig.getOutputSchemaFieldName();
\r
55 final String outputSchemaJson = jsonPathFilterPluginConfig.getSchema();
\r
57 if (ValidationUtils.isEmpty(outputSchemaJson)) {
\r
59 validationResponse.addErrorMessage("output schema", "Output schema is not present");
\r
63 // validate matched output field type is boolean
\r
64 if (matchedField != null &&
\r
65 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, matchedField, Schema.Type.BOOLEAN)) {
\r
66 validationResponse.addErrorMessage("OutputSchemaFieldName",
\r
68 "OutputSchemaFieldName: %s must be marked as boolean type", matchedField));
\r
71 // validate matched output field type is nullable
\r
72 if (matchedField != null &&
\r
73 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, matchedField, Schema.Type.NULL)) {
\r
74 validationResponse.addErrorMessage("OutputSchemaFieldName",
\r
76 "OutputSchemaFieldName: %s must be marked as nullable type", matchedField));
\r
81 return validationResponse;
\r