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