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.onap.dcae.apod.analytics.cdap.plugins.validator;
23 import co.cask.cdap.api.data.schema.Schema;
24 import org.onap.dcae.apod.analytics.cdap.common.utils.ValidationUtils;
25 import org.onap.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;
26 import org.onap.dcae.apod.analytics.cdap.plugins.domain.config.tca.SimpleTCAPluginConfig;
27 import org.onap.dcae.apod.analytics.cdap.plugins.utils.CDAPPluginUtils;
28 import org.onap.dcae.apod.analytics.common.validation.GenericValidationResponse;
31 * Validator that validate {@link SimpleTCAPluginConfig}
33 * @author Rajiv Singla . Creation Date: 2/21/2017.
35 public class SimpleTCAPluginConfigValidator implements CDAPAppSettingsValidator<SimpleTCAPluginConfig,
36 GenericValidationResponse<SimpleTCAPluginConfig>> {
38 private static final long serialVersionUID = 1L;
41 public GenericValidationResponse<SimpleTCAPluginConfig> validateAppSettings(
42 final SimpleTCAPluginConfig tcaPluginConfig) {
44 final GenericValidationResponse<SimpleTCAPluginConfig> validationResponse = new GenericValidationResponse<>();
46 if (ValidationUtils.isEmpty(tcaPluginConfig.getVesMessageFieldName())) {
47 validationResponse.addErrorMessage("vesMessageFieldName",
48 "Missing VES Message Field Name from plugin incoming schema");
51 if (ValidationUtils.isEmpty(tcaPluginConfig.getPolicyJson())) {
52 validationResponse.addErrorMessage("policyJson",
53 "Missing tca Policy Json");
56 final String alertFieldValue = tcaPluginConfig.getAlertFieldName();
57 final String alertFieldName = "alertFieldName";
58 if (ValidationUtils.isEmpty(alertFieldValue)) {
59 validationResponse.addErrorMessage(alertFieldName,
60 "Missing alert Field Name that will be placed in plugin outgoing schema");
63 if (ValidationUtils.isEmpty(tcaPluginConfig.getMessageTypeFieldName())) {
64 validationResponse.addErrorMessage("messageTypeField",
65 "Missing message Type Field Name that will be placed in plugin outgoing schema");
69 final String outputSchemaJson = tcaPluginConfig.getSchema();
70 if (ValidationUtils.isEmpty(outputSchemaJson)) {
71 validationResponse.addErrorMessage("output schema", "Output schema is not present");
73 // validate output schema - alert field name is of type string
74 if (alertFieldValue != null &&
75 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, alertFieldValue, Schema.Type.STRING)) {
76 validationResponse.addErrorMessage(alertFieldName,
78 "Alert Field Name: %s must be String type", alertFieldValue));
80 // validate output schema - alert field name is nullable
81 if (alertFieldValue != null &&
82 !CDAPPluginUtils.validateSchemaFieldType(outputSchemaJson, alertFieldValue, Schema.Type.NULL)) {
83 validationResponse.addErrorMessage(alertFieldName,
85 "Alert Field Name: %s must be marked as nullable type", alertFieldValue));
89 return validationResponse;