2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
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.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.models.provider;
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;
33 * Class to hold all the plugin handler parameters.
35 * <p>The following parameters are defined:
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,
44 * <li>persistenceUnit: The persistence unit refined in META-INF/persistence.xml to use for connecting
45 * to the database, mandatory.
48 * @author Liam Fallon (liam.fallon@est.tech)
53 public class PolicyModelsProviderParameters implements ParameterGroup {
54 private static final String DEFAULT_IMPLEMENTATION = DatabasePolicyModelsProviderImpl.class.getCanonicalName();
57 private String implementation = DEFAULT_IMPLEMENTATION;
58 private String databaseUrl;
59 private String databaseUser;
60 private String databasePassword;
61 private String persistenceUnit;
64 * Validate the model provider parameters.
68 public GroupValidationResult validate() {
69 final GroupValidationResult validationResult = new GroupValidationResult(this);
71 if (!ParameterValidationUtils.validateStringParameter(implementation)) {
72 validationResult.setResult("implementation", ValidationStatus.INVALID,
73 "a PolicyModelsProvider implementation must be specified");
76 if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
77 validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
78 "a URL must be specified for the JDBC connection to the database");
81 if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
82 validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
83 "a persistence unit must be specified for connecting to the database");
86 return validationResult;