fa4d663487a70dc7692accca83715577a0cff28a
[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
26 import org.onap.policy.common.parameters.GroupValidationResult;
27 import org.onap.policy.common.parameters.ParameterGroup;
28 import org.onap.policy.common.parameters.ValidationStatus;
29 import org.onap.policy.common.utils.validation.ParameterValidationUtils;
30 import org.onap.policy.models.provider.impl.DatabasePolicyModelsProviderImpl;
31
32 // @formatter:off
33 /**
34  * Class to hold all the plugin handler parameters.
35  *
36  * <p>The following parameters are defined:
37  * <ol>
38  * <li>name: A name for the parameters.
39  * <li>implementation: The implementation of the PolicyModelsProvider to use for writing and reading concepts,
40  * defaults to {@link DatabasePolicyModelsProviderImpl} and may not be null
41  * <li>databaseUrl: The JDBC URL for the database, mandatory.
42  * <li>databaseUser: The user id to use for connecting to the database, optional, defaults to null.
43  * <li>databasePassword: The password to use for connecting to the database encoded in Base64, optional,
44  * defaults to null.
45  * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
46  * to the database, mandatory.
47  * </ol>
48  *
49  * @author Liam Fallon (liam.fallon@est.tech)
50  */
51 //@formatter:on
52
53 @Data
54 public class PolicyModelsProviderParameters implements ParameterGroup {
55     private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getName();
56
57     private String name;
58     private String implementation = DEFAULT_IMPLEMENTATION;
59     private String databaseDriver;
60     private String databaseUrl;
61     private String databaseUser;
62     private String databasePassword;
63     private String persistenceUnit;
64
65     /**
66      * Validate the model provider parameters.
67      *
68      */
69     @Override
70     public GroupValidationResult validate() {
71         final GroupValidationResult validationResult = new GroupValidationResult(this);
72
73         if (!ParameterValidationUtils.validateStringParameter(implementation)) {
74             validationResult.setResult("implementation", ValidationStatus.INVALID,
75                     "a PolicyModelsProvider implementation must be specified");
76         }
77
78         if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
79             validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
80                     "a driver must be specified for the JDBC connection to the database");
81         }
82
83         if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
84             validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
85                     "a URL must be specified for the JDBC connection to the database");
86         }
87
88         if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
89             validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
90                     "a persistence unit must be specified for connecting to the database");
91         }
92
93         return validationResult;
94     }
95 }