2 * ===============================LICENSE_START======================================
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
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.dcae.apod.analytics.cdap.plugins.validator;
23 import co.cask.cdap.api.data.schema.Schema;
24 import org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils;
25 import org.openecomp.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;
26 import org.openecomp.dcae.apod.analytics.cdap.plugins.domain.config.filter.JsonPathFilterPluginConfig;
27 import org.openecomp.dcae.apod.analytics.cdap.plugins.utils.CDAPPluginUtils;
28 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;
31 * Validator to validate {@link JsonPathFilterPluginConfig}
33 * @author Rajiv Singla . Creation Date: 3/2/2017.
35 public class JsonPathFilterPluginConfigValidator implements CDAPAppSettingsValidator<JsonPathFilterPluginConfig,
36 GenericValidationResponse<JsonPathFilterPluginConfig>> {
38 private static final long serialVersionUID = 1L;
41 public GenericValidationResponse<JsonPathFilterPluginConfig> validateAppSettings(
42 final JsonPathFilterPluginConfig jsonPathFilterPluginConfig) {
44 final GenericValidationResponse<JsonPathFilterPluginConfig> validationResponse =
45 new GenericValidationResponse<>();
47 final String jsonFilterMappings = jsonPathFilterPluginConfig.getJsonFilterMappings();
48 if (ValidationUtils.isEmpty(jsonFilterMappings)) {
50 validationResponse.addErrorMessage("JsonFilterMappings", "Json Filter Mappings must be present");
54 final String matchedField = jsonPathFilterPluginConfig.getOutputSchemaFieldName();
55 final String outputSchemaJson = jsonPathFilterPluginConfig.getSchema();
57 if (ValidationUtils.isEmpty(outputSchemaJson)) {
59 validationResponse.addErrorMessage("output schema", "Output schema is not present");
63 // validate matched output field type is boolean
64 if (matchedField != null &&
65 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, matchedField, Schema.Type.BOOLEAN)) {
66 validationResponse.addErrorMessage("OutputSchemaFieldName",
68 "OutputSchemaFieldName: %s must be marked as boolean type", matchedField));
71 // validate matched output field type is nullable
72 if (matchedField != null &&
73 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, matchedField, Schema.Type.NULL)) {
74 validationResponse.addErrorMessage("OutputSchemaFieldName",
76 "OutputSchemaFieldName: %s must be marked as nullable type", matchedField));
81 return validationResponse;