f07605f061a39db1a47030d4ff3ab4059f223c1c
[policy/distribution.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019 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.distribution.forwarding.xacml.pdp.testclasses;
22
23 import io.swagger.annotations.ApiParam;
24
25 import javax.ws.rs.Consumes;
26 import javax.ws.rs.POST;
27 import javax.ws.rs.Path;
28 import javax.ws.rs.PathParam;
29 import javax.ws.rs.Produces;
30 import javax.ws.rs.core.MediaType;
31 import javax.ws.rs.core.Response;
32
33 import org.onap.policy.models.pap.concepts.PdpDeployPolicies;
34 import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
35 import org.onap.policy.models.tosca.authorative.concepts.ToscaServiceTemplate;
36
37 /**
38  * Class to provide rest end points for LifecycycleApiSimulator.
39  *
40  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
41  */
42 @Path("/policy")
43 @Produces(MediaType.APPLICATION_JSON)
44 public class LifecycycleApiSimulatorEndpoint {
45
46     /**
47      * Create policy type endpoint.
48      *
49      * @param body the post body
50      * @return the response object
51      */
52     @POST
53     @Path("/api/v1/policytypes")
54     @Consumes(MediaType.APPLICATION_JSON)
55     @Produces(MediaType.APPLICATION_JSON)
56     public Response createPolicyTypes(final ToscaServiceTemplate body) {
57         return Response.status(Response.Status.OK).entity(body).build();
58     }
59
60     /**
61      * Create policy endpoint.
62      *
63      * @param policyTypeId the policy type id
64      * @param policyTypeVersion the policy type version
65      * @param body the post body
66      * @return the response object
67      */
68     @POST
69     @Path("/api/v1/policytypes/{policyTypeId}/versions/{policyTypeVersion}/policies")
70     @Consumes(MediaType.APPLICATION_JSON)
71     @Produces(MediaType.APPLICATION_JSON)
72     public Response createPolicies(@PathParam("policyTypeId") final String policyTypeId,
73             @PathParam("policyTypeVersion") final String policyTypeVersion,
74             @ApiParam(value = "Entity body of policy", required = true) final ToscaServiceTemplate body) {
75         if ("onap.policies.controlloop.operational.ApexFailure".equals(policyTypeId)) {
76             return Response.status(Response.Status.NOT_FOUND).build();
77         } else {
78             return Response.status(Response.Status.OK).entity(body).build();
79         }
80     }
81
82     /**
83      * Deploy policy endpoint.
84      *
85      * @param policies the post body
86      * @return the response object
87      */
88     @POST
89     @Path("/pap/v1/pdps/policies")
90     @Consumes(MediaType.APPLICATION_JSON)
91     @Produces(MediaType.APPLICATION_JSON)
92     public Response deployPolicies(final PdpDeployPolicies policies) {
93         return Response.status(Response.Status.OK).entity(new PdpGroupDeployResponse()).build();
94     }
95 }