a86576eed735665b37c858382903ccc243edad67
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 Nordix Foundation.
4  * ================================================================================
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.participant.policy.client;
22
23 import javax.ws.rs.client.Entity;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import org.onap.policy.clamp.acm.participant.policy.main.parameters.ParticipantPolicyParameters;
27 import org.onap.policy.models.base.PfModelException;
28 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
29 import org.springframework.stereotype.Component;
30
31 @Component
32 public class PolicyApiHttpClient extends AbstractHttpClient {
33
34     private static final String POLICY_URI = "/policy/api/v1/";
35
36     /**
37      * Constructor.
38      *
39      * @param parameters the policy participant parameters
40      */
41     public PolicyApiHttpClient(ParticipantPolicyParameters parameters) {
42         super(parameters.getPolicyApiParameters());
43     }
44
45     /**
46      * Create Policy Types.
47      *
48      * @param toscaServiceTemplate the whole ToscaServiceTemplate
49      * @return Response
50      * @throws PfModelException on errors creating the policy type
51      */
52     public Response createPolicyType(ToscaServiceTemplate toscaServiceTemplate) throws PfModelException {
53         return executePost(POLICY_URI + "policytypes", Entity.entity(toscaServiceTemplate, MediaType.APPLICATION_JSON));
54     }
55
56     /**
57      * Create Policies.
58      *
59      * @param toscaServiceTemplate the whole ToscaServiceTemplate
60      * @return Response
61      */
62     public Response createPolicy(final ToscaServiceTemplate toscaServiceTemplate) {
63         return executePost(POLICY_URI + "policies", Entity.entity(toscaServiceTemplate, MediaType.APPLICATION_JSON));
64     }
65
66     /**
67      * Delete Policies.
68      *
69      * @param policyName the name of the policy to be deleted
70      * @param policyVersion the version of the policy to be deleted
71      * @return Response
72      */
73     public Response deletePolicy(final String policyName, final String policyVersion) {
74         return executeDelete(POLICY_URI + "policies/" + policyName + "/versions/" + policyVersion);
75     }
76
77     /**
78      * Delete Policy types.
79      *
80      * @param policyTypeName the name of the policy to be deleted
81      * @param policyTypeVersion the version of the policy to be deleted
82      * @return Response
83      */
84     public Response deletePolicyType(final String policyTypeName, final String policyTypeVersion) {
85         return executeDelete(POLICY_URI + "policytypes/" + policyTypeName + "/versions/" + policyTypeVersion);
86     }
87 }