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
10 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.policy.models.provider;
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;
34 * Class to hold all the plugin handler parameters.
36 * <p>The following parameters are defined:
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,
45 * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
46 * to the database, mandatory.
49 * @author Liam Fallon (liam.fallon@est.tech)
54 public class PolicyModelsProviderParameters implements ParameterGroup {
55 private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getName();
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;
66 * Validate the model provider parameters.
70 public GroupValidationResult validate() {
71 final GroupValidationResult validationResult = new GroupValidationResult(this);
73 if (!ParameterValidationUtils.validateStringParameter(implementation)) {
74 validationResult.setResult("implementation", ValidationStatus.INVALID,
75 "a PolicyModelsProvider implementation must be specified");
78 if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
79 validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
80 "a driver must be specified for the JDBC connection to the database");
83 if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
84 validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
85 "a URL must be specified for the JDBC connection to the database");
88 if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
89 validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
90 "a persistence unit must be specified for connecting to the database");
93 return validationResult;