2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019-2020 AT&T Intellectual Property. All rights reserved.
6 * Modifications Copyright (C) 2020 Nordix Foundation.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
20 * SPDX-License-Identifier: Apache-2.0
21 * ============LICENSE_END=========================================================
24 package org.onap.policy.api.main.rest.provider;
26 import java.util.ArrayList;
27 import java.util.List;
29 import org.apache.commons.lang3.tuple.Pair;
30 import org.onap.policy.models.base.PfConceptKey;
31 import org.onap.policy.models.base.PfModelException;
32 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
35 * Class to provide all kinds of legacy operational policy operations.
37 * @author Chenfei Gao (cgao@research.att.com)
39 public class LegacyOperationalPolicyProvider extends CommonModelProvider {
41 private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
42 new PfConceptKey("onap.policies.controlloop.Operational", "1.0.0");
45 * Default constructor.
47 public LegacyOperationalPolicyProvider() throws PfModelException {
52 * Retrieves a list of operational policies matching specified ID and version.
54 * @param policyId the ID of policy
55 * @param policyVersion the version of policy
57 * @return the LegacyOperationalPolicy object
59 public LegacyOperationalPolicy fetchOperationalPolicy(String policyId, String policyVersion)
60 throws PfModelException {
62 return modelsProvider.getOperationalPolicy(policyId, policyVersion);
66 * Retrieves a list of deployed operational policies in each pdp group.
68 * @param policyId the ID of the policy
70 * @return a list of deployed policies in each pdp group
72 * @throws PfModelException the PfModel parsing exception
74 public Map<Pair<String, String>, List<LegacyOperationalPolicy>> fetchDeployedOperationalPolicies(String policyId)
75 throws PfModelException {
77 return collectDeployedPolicies(policyId, LEGACY_OPERATIONAL_TYPE, modelsProvider::getOperationalPolicy,
78 List::add, new ArrayList<>(5));
82 * Creates a new operational policy.
84 * @param body the entity body of policy
86 * @return the LegacyOperationalPolicy object
88 public LegacyOperationalPolicy createOperationalPolicy(LegacyOperationalPolicy body) throws PfModelException {
90 return modelsProvider.createOperationalPolicy(body);
94 * Deletes the operational policies matching specified ID and version.
96 * @param policyId the ID of policy
97 * @param policyVersion the version of policy
99 * @return the LegacyOperationalPolicy object
101 public LegacyOperationalPolicy deleteOperationalPolicy(String policyId, String policyVersion)
102 throws PfModelException {
104 return modelsProvider.deleteOperationalPolicy(policyId, policyVersion);