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;
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.getName();
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;
65 * Validate the model provider parameters.
69 public GroupValidationResult validate() {
70 final GroupValidationResult validationResult = new GroupValidationResult(this);
72 if (!ParameterValidationUtils.validateStringParameter(implementation)) {
73 validationResult.setResult("implementation", ValidationStatus.INVALID,
74 "a PolicyModelsProvider implementation must be specified");
77 if (!ParameterValidationUtils.validateStringParameter(databaseDriver)) {
78 validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
79 "a driver must be specified for the JDBC connection to the database");
82 if (!ParameterValidationUtils.validateStringParameter(databaseUrl)) {
83 validationResult.setResult("databaseUrl", ValidationStatus.INVALID,
84 "a URL must be specified for the JDBC connection to the database");
87 if (!ParameterValidationUtils.validateStringParameter(persistenceUnit)) {
88 validationResult.setResult("persistenceUnit", ValidationStatus.INVALID,
89 "a persistence unit must be specified for connecting to the database");
92 return validationResult;