2 * ============LICENSE_START=======================================================
\r
4 * ================================================================================
\r
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
\r
6 * Modifications Copyright (C) 2020-2021 Nordix Foundation.
\r
7 * Modifications Copyright (C) 2022 Bell Canada. All rights reserved.
\r
8 * ================================================================================
\r
9 * Licensed under the Apache License, Version 2.0 (the "License");
\r
10 * you may not use this file except in compliance with the License.
\r
11 * You may obtain a copy of the License at
\r
13 * http://www.apache.org/licenses/LICENSE-2.0
\r
15 * Unless required by applicable law or agreed to in writing, software
\r
16 * distributed under the License is distributed on an "AS IS" BASIS,
\r
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
18 * See the License for the specific language governing permissions and
\r
19 * limitations under the License.
\r
21 * SPDX-License-Identifier: Apache-2.0
\r
22 * ============LICENSE_END=========================================================
\r
25 package org.onap.policy.api.main.rest.provider;
\r
27 import org.onap.policy.models.base.PfModelException;
\r
28 import org.onap.policy.models.provider.PolicyModelsProvider;
\r
29 import org.onap.policy.models.tosca.authorative.concepts.ToscaEntityFilter;
\r
30 import org.onap.policy.models.tosca.authorative.concepts.ToscaPolicyType;
\r
31 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
32 import org.springframework.beans.factory.annotation.Autowired;
\r
33 import org.springframework.stereotype.Service;
\r
36 * Class to provide all kinds of policy type operations.
\r
38 * @author Chenfei Gao (cgao@research.att.com)
\r
41 public class PolicyTypeProvider extends CommonModelProvider {
\r
44 * Default constructor.
\r
47 public PolicyTypeProvider(PolicyModelsProvider modelsProvider) throws PfModelException {
\r
48 super(modelsProvider);
\r
52 * Retrieves a list of policy types matching specified policy type ID and version.
\r
54 * @param policyTypeId the ID of policy type
\r
55 * @param policyTypeVersion the version of policy type
\r
57 * @return the ToscaServiceTemplate object
\r
59 * @throws PfModelException the PfModel parsing exception
\r
61 public ToscaServiceTemplate fetchPolicyTypes(String policyTypeId, String policyTypeVersion)
\r
62 throws PfModelException {
\r
64 return getFilteredPolicyTypes(policyTypeId, policyTypeVersion);
\r
68 * Retrieves a list of policy types with the latest versions.
\r
70 * @param policyTypeId the ID of policy type
\r
72 * @return the ToscaServiceTemplate object
\r
74 * @throws PfModelException the PfModel parsing exception
\r
76 public ToscaServiceTemplate fetchLatestPolicyTypes(String policyTypeId) throws PfModelException {
\r
78 return getFilteredPolicyTypes(policyTypeId, ToscaEntityFilter.LATEST_VERSION);
\r
82 * Creates a new policy type.
\r
84 * @param body the entity body of policy type
\r
86 * @return the ToscaServiceTemplate object
\r
87 * @throws PfModelException the PfModel parsing exception
\r
89 public ToscaServiceTemplate createPolicyType(ToscaServiceTemplate body) throws PfModelException {
\r
91 return modelsProvider.createPolicyTypes(body);
\r
95 * Delete the policy type matching specified policy type ID and version.
\r
97 * @param policyTypeId the ID of policy type
\r
98 * @param policyTypeVersion the version of policy type
\r
100 * @return the ToscaServiceTemplate object
\r
102 * @throws PfModelException the PfModel parsing exception
\r
104 public ToscaServiceTemplate deletePolicyType(String policyTypeId, String policyTypeVersion)
\r
105 throws PfModelException {
\r
107 return modelsProvider.deletePolicyType(policyTypeId, policyTypeVersion);
\r
111 * Retrieves the specified version of the policy type.
\r
113 * @param policyTypeName the name of the policy type
\r
114 * @param policyTypeVersion the version of the policy type
\r
116 * @return the TOSCA service template containing the specified version of the policy type
\r
118 * @throws PfModelException the PfModel parsing exception
\r
120 private ToscaServiceTemplate getFilteredPolicyTypes(String policyTypeName, String policyTypeVersion)
\r
121 throws PfModelException {
\r
123 ToscaEntityFilter<ToscaPolicyType> policyTypeFilter =
\r
124 ToscaEntityFilter.<ToscaPolicyType>builder().name(policyTypeName).version(policyTypeVersion).build();
\r
125 return modelsProvider.getFilteredPolicyTypes(policyTypeFilter);
\r