Sonar Critical Fix
[dcaegen2/analytics/tca.git] / dcae-analytics-cdap-tca / src / main / java / org / openecomp / dcae / apod / analytics / cdap / tca / validator / TCAPreferencesValidator.java
1 /*\r
2  * ===============================LICENSE_START======================================\r
3  *  dcae-analytics\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
10  *\r
11  *          http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 \r
21 package org.openecomp.dcae.apod.analytics.cdap.tca.validator;\r
22 \r
23 import org.openecomp.dcae.apod.analytics.cdap.common.validation.CDAPAppSettingsValidator;\r
24 import org.openecomp.dcae.apod.analytics.cdap.tca.settings.TCAAppPreferences;\r
25 import org.openecomp.dcae.apod.analytics.common.validation.GenericValidationResponse;\r
26 \r
27 import static org.openecomp.dcae.apod.analytics.cdap.common.utils.ValidationUtils.isEmpty;\r
28 \r
29 /**\r
30  *\r
31  * @author Rajiv Singla . Creation Date: 11/3/2016.\r
32  */\r
33 public class TCAPreferencesValidator implements CDAPAppSettingsValidator<TCAAppPreferences,\r
34         GenericValidationResponse<TCAAppPreferences>> {\r
35 \r
36     private static final long serialVersionUID = 1L;\r
37 \r
38     @Override\r
39     public GenericValidationResponse<TCAAppPreferences> validateAppSettings(TCAAppPreferences appPreferences) {\r
40 \r
41         final GenericValidationResponse<TCAAppPreferences> validationResponse = new GenericValidationResponse<>();\r
42 \r
43         // subscriber validations\r
44         final String subscriberHostName = appPreferences.getSubscriberHostName();\r
45         if (isEmpty(subscriberHostName)) {\r
46             validationResponse.addErrorMessage("subscriberHostName", "Subscriber host name must be present");\r
47         }\r
48         final String subscriberTopicName = appPreferences.getSubscriberTopicName();\r
49         if (isEmpty(subscriberTopicName)) {\r
50             validationResponse.addErrorMessage("subscriberTopicName", "Subscriber topic name must be present");\r
51         }\r
52 \r
53         // publisher validations\r
54         final String publisherHostName = appPreferences.getPublisherHostName();\r
55         if (isEmpty(publisherHostName)) {\r
56             validationResponse.addErrorMessage("publisherHostName", "Publisher host name must be present");\r
57         }\r
58         final String publisherTopicName = appPreferences.getPublisherTopicName();\r
59         if (isEmpty(publisherTopicName)) {\r
60             validationResponse.addErrorMessage("publisherTopicName", "Publisher topic name must be present");\r
61         }\r
62 \r
63         final Boolean enableAAIEnrichment = appPreferences.getEnableAAIEnrichment();\r
64 \r
65         // if aai enrichment is enabled then do some aai validations\r
66         if (enableAAIEnrichment) {\r
67             final String aaiEnrichmentHost = appPreferences.getAaiEnrichmentHost();\r
68             if (isEmpty(aaiEnrichmentHost)) {\r
69                 validationResponse.addErrorMessage("aaiEnrichmentHost", "AAI Enrichment Host must be present");\r
70             }\r
71             final String aaiVMEnrichmentAPIPath = appPreferences.getAaiVMEnrichmentAPIPath();\r
72             if (isEmpty(aaiVMEnrichmentAPIPath)) {\r
73                 validationResponse.addErrorMessage("aaiVMEnrichmentAPIPath", "AAI VM Enrichment path must be present");\r
74             }\r
75             final String aaiVNFEnrichmentAPIPath = appPreferences.getAaiVNFEnrichmentAPIPath();\r
76             if (isEmpty(aaiVNFEnrichmentAPIPath)) {\r
77                 validationResponse.addErrorMessage("aaiVNFEnrichmentAPIPath", "AAI VNF Enrichment path must be " +\r
78                         "present");\r
79             }\r
80         }\r
81 \r
82         return validationResponse;\r
83     }\r
84 }\r