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;
30 import org.apache.commons.lang3.tuple.Pair;
31 import org.onap.policy.models.base.PfConceptKey;
32 import org.onap.policy.models.base.PfModelException;
33 import org.onap.policy.models.tosca.legacy.concepts.LegacyOperationalPolicy;
36 * Class to provide all kinds of legacy operational policy operations.
38 * @author Chenfei Gao (cgao@research.att.com)
40 public class LegacyOperationalPolicyProvider extends CommonModelProvider {
42 private static final PfConceptKey LEGACY_OPERATIONAL_TYPE =
43 new PfConceptKey("onap.policies.controlloop.Operational", "1.0.0");
46 * Default constructor.
48 public LegacyOperationalPolicyProvider() throws PfModelException {
53 * Retrieves a list of operational policies matching specified ID and version.
55 * @param policyId the ID of policy
56 * @param policyVersion the version of policy
58 * @return the LegacyOperationalPolicy object
60 public LegacyOperationalPolicy fetchOperationalPolicy(String policyId, String policyVersion)
61 throws PfModelException {
63 return modelsProvider.getOperationalPolicy(policyId, policyVersion);
67 * Retrieves a list of deployed operational policies in each pdp group.
69 * @param policyId the ID of the policy
71 * @return a list of deployed policies in each pdp group
73 * @throws PfModelException the PfModel parsing exception
75 public Map<Pair<String, String>, List<LegacyOperationalPolicy>> fetchDeployedOperationalPolicies(String policyId)
76 throws PfModelException {
78 return collectDeployedPolicies(policyId, LEGACY_OPERATIONAL_TYPE, modelsProvider::getOperationalPolicy,
79 List::add, new ArrayList<>(5));
83 * Creates a new operational policy.
85 * @param body the entity body of policy
87 * @return the LegacyOperationalPolicy object
89 public LegacyOperationalPolicy createOperationalPolicy(LegacyOperationalPolicy body) throws PfModelException {
91 return modelsProvider.createOperationalPolicy(body);
95 * Deletes the operational policies matching specified ID and version.
97 * @param policyId the ID of policy
98 * @param policyVersion the version of policy
100 * @return the LegacyOperationalPolicy object
102 public LegacyOperationalPolicy deleteOperationalPolicy(String policyId, String policyVersion)
103 throws PfModelException {
105 return modelsProvider.deleteOperationalPolicy(policyId, policyVersion);