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.ToscaPolicyFilter;
\r
28 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
\r
31 * Class to provide all kinds of policy operations.
\r
33 * @author Chenfei Gao (cgao@research.att.com)
\r
35 public class PolicyProvider extends CommonModelProvider {
\r
38 * Default constructor.
\r
40 public PolicyProvider() throws PfModelException {
\r
45 * Retrieves a list of policies matching specified ID and version of both policy type and policy.
\r
47 * @param policyTypeId the ID of policy type
\r
48 * @param policyTypeVersion the version of policy type
\r
49 * @param policyId the ID of policy
\r
50 * @param policyVersion the version of policy
\r
52 * @return the ToscaServiceTemplate object
\r
54 * @throws PfModelException the PfModel parsing exception
\r
56 public ToscaServiceTemplate fetchPolicies(String policyTypeId, String policyTypeVersion, String policyId,
\r
57 String policyVersion) throws PfModelException {
\r
59 return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, policyVersion);
\r
63 * Retrieves a list of policies with the latest versions that match specified policy type id and version.
\r
65 * @param policyTypeId the ID of policy type
\r
66 * @param policyTypeVersion the version of policy type
\r
67 * @param policyId the ID of the policy
\r
69 * @return the ToscaServiceTemplate object
\r
71 * @throws PfModelException the PfModel parsing exception
\r
73 public ToscaServiceTemplate fetchLatestPolicies(String policyTypeId, String policyTypeVersion, String policyId)
\r
74 throws PfModelException {
\r
76 return getFilteredPolicies(policyTypeId, policyTypeVersion, policyId, ToscaPolicyFilter.LATEST_VERSION);
\r
80 * Creates one or more new policies for the same policy type ID and version.
\r
82 * @param policyTypeId the ID of policy type
\r
83 * @param policyTypeVersion the version of policy type
\r
84 * @param body the entity body of polic(ies)
\r
86 * @return the ToscaServiceTemplate object
\r
88 * @throws PfModelException the PfModel parsing exception
\r
90 public ToscaServiceTemplate createPolicy(String policyTypeId, String policyTypeVersion, ToscaServiceTemplate body)
\r
91 throws PfModelException {
\r
93 return modelsProvider.createPolicies(body);
\r
97 * Creates one or more new policies.
\r
99 * @param body the entity body of policy
\r
101 * @return the ToscaServiceTemplate object
\r
103 * @throws PfModelException the PfModel parsing exception
\r
105 public ToscaServiceTemplate createPolicies(ToscaServiceTemplate body) throws PfModelException {
\r
106 return modelsProvider.createPolicies(body);
\r
110 * Deletes the policy matching specified ID and version of both policy type and policy.
\r
112 * @param policyTypeId the ID of policy type
\r
113 * @param policyTypeVersion the version of policy type
\r
114 * @param policyId the ID of policy
\r
115 * @param policyVersion the version of policy
\r
117 * @return the ToscaServiceTemplate object
\r
119 * @throws PfModelException the PfModel parsing exception
\r
121 public ToscaServiceTemplate deletePolicy(String policyTypeId, String policyTypeVersion, String policyId,
\r
122 String policyVersion) throws PfModelException {
\r
124 return modelsProvider.deletePolicy(policyId, policyVersion);
\r
128 * Retrieves the specified version of the policy.
\r
130 * @param policyTypeName the name of the policy type
\r
131 * @param policyTypeVersion the version of the policy type
\r
132 * @param policyName the name of the policy
\r
133 * @param policyVersion the version of the policy
\r
135 * @return the TOSCA service template containing the specified version of the policy
\r
137 * @throws PfModelException the PfModel parsing exception
\r
139 private ToscaServiceTemplate getFilteredPolicies(String policyTypeName, String policyTypeVersion, String policyName,
\r
140 String policyVersion) throws PfModelException {
\r
142 ToscaPolicyFilter policyFilter = ToscaPolicyFilter.builder().name(policyName).version(policyVersion)
\r
143 .type(policyTypeName).typeVersion(policyTypeVersion).build();
\r
144 return modelsProvider.getFilteredPolicies(policyFilter);
\r