2 * ================================================================================
3 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 * ============LICENSE_END=========================================================
20 package org.onap.dcae.analytics.tca.web.validation;
23 import org.onap.dcae.analytics.tca.web.TcaAppProperties;
24 import org.onap.dcae.analytics.web.util.ValidationUtils;
25 import org.onap.dcae.analytics.web.validation.AnalyticsValidator;
26 import org.onap.dcae.analytics.web.validation.GenericValidationResponse;
27 import org.springframework.lang.Nullable;
28 import org.springframework.validation.Errors;
31 * @author Rajiv Singla
33 public class ConfigPropertiesAaiValidator implements
34 AnalyticsValidator<TcaAppProperties.Aai, GenericValidationResponse> {
36 private static final long serialVersionUID = 1L;
39 public GenericValidationResponse apply(final TcaAppProperties.Aai aai) {
41 final GenericValidationResponse validationResponse = new GenericValidationResponse();
43 final String genericVnfPath = aai.getGenericVnfPath();
44 if (ValidationUtils.isEmpty(genericVnfPath)) {
45 validationResponse.addErrorMessage("generic_vnf_path", "AAI Generic vnf path must be present");
48 final String nodeQueryPath = aai.getNodeQueryPath();
49 if (ValidationUtils.isEmpty(nodeQueryPath)) {
50 validationResponse.addErrorMessage("node_query_path", "AAI Node Query Path must be present");
54 final String url = aai.getUrl();
55 if (ValidationUtils.isEmpty(url)) {
56 validationResponse.addErrorMessage("url", "AAI url must be present");
59 return validationResponse;
63 public boolean supports(final Class<?> type) {
64 return type == TcaAppProperties.Aai.class;
68 public void validate(@Nullable final Object target, final Errors errors) {
70 // if aai is not present - assuming no aai enrichment is required
74 final TcaAppProperties.Aai aai = (TcaAppProperties.Aai) target;
76 // skip validation if aai enrichment is not enabled
77 if (aai.getEnableEnrichment() == null || !aai.getEnableEnrichment()) {
81 final GenericValidationResponse validationResponse = apply(aai);
83 if (validationResponse.hasErrors()) {
84 errors.rejectValue("aai", validationResponse.getAllErrorMessage());