2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
\r
6 * Modifications Copyright (C) 2020 Nordix Foundation.
\r
7 * ================================================================================
\r
8 * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * you may not use this file except in compliance with the License.
\r
10 * You may obtain a copy of the License at
\r
12 * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * Unless required by applicable law or agreed to in writing, software
\r
15 * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * See the License for the specific language governing permissions and
\r
18 * limitations under the License.
\r
20 * SPDX-License-Identifier: Apache-2.0
\r
21 * ============LICENSE_END=========================================================
\r
24 package org.onap.policy.api.main.rest.provider;
\r
26 import org.onap.policy.models.base.PfModelException;
\r
27 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyTypeFilter;
\r
28 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
31 * Class to provide all kinds of policy type operations.
\r
33 * @author Chenfei Gao (cgao@research.att.com)
\r
35 public class PolicyTypeProvider extends CommonModelProvider {
\r
38 * Default constructor.
\r
40 public PolicyTypeProvider() throws PfModelException {
\r
45 * Retrieves a list of policy types matching specified policy type ID and version.
\r
47 * @param policyTypeId the ID of policy type
\r
48 * @param policyTypeVersion the version of policy type
\r
50 * @return the ToscaServiceTemplate object
\r
52 * @throws PfModelException the PfModel parsing exception
\r
54 public ToscaServiceTemplate fetchPolicyTypes(String policyTypeId, String policyTypeVersion)
\r
55 throws PfModelException {
\r
57 return getFilteredPolicyTypes(policyTypeId, policyTypeVersion);
\r
61 * Retrieves a list of policy types with the latest versions.
\r
63 * @param policyTypeId the ID of policy type
\r
65 * @return the ToscaServiceTemplate object
\r
67 * @throws PfModelException the PfModel parsing exception
\r
69 public ToscaServiceTemplate fetchLatestPolicyTypes(String policyTypeId) throws PfModelException {
\r
71 return getFilteredPolicyTypes(policyTypeId, ToscaPolicyTypeFilter.LATEST_VERSION);
\r
75 * Creates a new policy type.
\r
77 * @param body the entity body of policy type
\r
79 * @return the ToscaServiceTemplate object
\r
80 * @throws PfModelException the PfModel parsing exception
\r
82 public ToscaServiceTemplate createPolicyType(ToscaServiceTemplate body) throws PfModelException {
\r
84 return modelsProvider.createPolicyTypes(body);
\r
88 * Delete the policy type matching specified policy type ID and version.
\r
90 * @param policyTypeId the ID of policy type
\r
91 * @param policyTypeVersion the version of policy type
\r
93 * @return the ToscaServiceTemplate object
\r
95 * @throws PfModelException the PfModel parsing exception
\r
97 public ToscaServiceTemplate deletePolicyType(String policyTypeId, String policyTypeVersion)
\r
98 throws PfModelException {
\r
100 return modelsProvider.deletePolicyType(policyTypeId, policyTypeVersion);
\r
104 * Retrieves the specified version of the policy type.
\r
106 * @param policyTypeName the name of the policy type
\r
107 * @param policyTypeVersion the version of the policy type
\r
109 * @return the TOSCA service template containing the specified version of the policy type
\r
111 * @throws PfModelException the PfModel parsing exception
\r
113 private ToscaServiceTemplate getFilteredPolicyTypes(String policyTypeName, String policyTypeVersion)
\r
114 throws PfModelException {
\r
116 ToscaPolicyTypeFilter policyTypeFilter =
\r
117 ToscaPolicyTypeFilter.builder().name(policyTypeName).version(policyTypeVersion).build();
\r
118 return modelsProvider.getFilteredPolicyTypes(policyTypeFilter);
\r