Changes for Checkstyle 8.32
[policy/models.git] / models-provider / src / main / java / org / onap / policy / models / provider / PolicyModelsProviderParameters.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 Nordix Foundation.
4  *  Modifications Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
5  * ================================================================================
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * SPDX-License-Identifier: Apache-2.0
19  * ============LICENSE_END=========================================================
20  */
21
22 package org.onap.policy.models.provider;
23
24 import lombok.Data;
25 import org.onap.policy.common.parameters.GroupValidationResult;
26 import org.onap.policy.common.parameters.ParameterGroup;
27 import org.onap.policy.common.parameters.ValidationStatus;
28 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
29 import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
30
31 // @formatter:off
32 /**
33  * Class to hold all the plugin handler parameters.
34  *
35  * <p>The following parameters are defined:
36  * <ol>
37  * <li>name: A name for the parameters.
38  * <li>implementation: The implementation of the PolicyModelsProvider to use for writing and reading concepts,
39  * defaults to {@link DatabasePolicyModelsProviderImpl} and may not be null
40  * <li>databaseUrl: The JDBC URL for the database, mandatory.
41  * <li>databaseUser: The user id to use for connecting to the database, optional, defaults to null.
42  * <li>databasePassword: The password to use for connecting to the database encoded in Base64, optional,
43  * defaults to null.
44  * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
45  * to the database, mandatory.
46  * </ol>
47  *
48  * @author Liam Fallon (liam.fallon@est.tech)
49  */
50 //@formatter:on
51
52 @Data
53 public class PolicyModelsProviderParameters implements ParameterGroup {
54     private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getName();
55
56     private String name;
57     private String implementation = DEFAULT_IMPLEMENTATION;
58     private String databaseDriver;
59     private String databaseUrl;
60     private String databaseUser;
61     private String databasePassword;
62     private String persistenceUnit;
63
64     /**
65      * Validate the model provider parameters.
66      *
67      */
68     @Override
69     public GroupValidationResult validate() {
70         final GroupValidationResult validationResult = new GroupValidationResult(this);
71
72         if (!ParameterValidationUtils.validateStringParameter(implementation)) {
73             validationResult.setResult("implementation", ValidationStatus.INVALID,
74                     "a PolicyModelsProvider implementation must be specified");
75         }
76
77         if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
78             validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
79                     "a driver must be specified for the JDBC connection to the database");
80         }
81
82         if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
83             validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
84                     "a URL must be specified for the JDBC connection to the database");
85         }
86
87         if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
88             validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
89                     "a persistence unit must be specified for connecting to the database");
90         }
91
92         return validationResult;
93     }
94 }