checkstyle: enable JavadocTagContinuationIndentation
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVPNIPSECPoliciesNorthbound.java
1 /*
2  * Copyright (c) 2015 IBM Corporation and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.neutron.northbound.api;
10
11 import java.net.HttpURLConnection;
12 import java.util.ArrayList;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.codehaus.enunciate.jaxrs.TypeHint;
28 import org.opendaylight.neutron.spi.INeutronVPNIPSECPolicyCRUD;
29 import org.opendaylight.neutron.spi.NeutronVPNIPSECPolicy;
30
31 /**
32  * Neutron Northbound REST APIs for VPN IPSEC Policy.<br>
33  * This class provides REST APIs for managing neutron VPN IPSEC Policies
34  *
35  * <br>
36  * <br>
37  * Authentication scheme : <b>HTTP Basic</b><br>
38  * Authentication realm : <b>opendaylight</b><br>
39  * Transport : <b>HTTP and HTTPS</b><br>
40  * <br>
41  * HTTPS Authentication is disabled by default. Administrator can enable it in
42  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43  * trusted authority.<br>
44  * More info :
45  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
46  *
47  */
48
49 @Path("/vpn/ipsecpolicies")
50 public final class NeutronVPNIPSECPoliciesNorthbound extends
51         AbstractNeutronNorthbound<NeutronVPNIPSECPolicy, NeutronVPNIPSECPolicyRequest, INeutronVPNIPSECPolicyCRUD> {
52
53     private static final String RESOURCE_NAME = "VPNIPSECPolicy";
54
55     @Override
56     protected String getResourceName() {
57         return RESOURCE_NAME;
58     }
59
60     /**
61      * Returns a list of all VPN IPSEC Policies */
62
63     @GET
64     @Produces({ MediaType.APPLICATION_JSON })
65     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
66             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
67             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
68             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
69     public Response listVPNIPSECPolicies(
70             // return fields
71             @QueryParam("fields") List<String> fields,
72             // filter fields
73             @QueryParam("id") String queryID,
74             @QueryParam("tenant_id") String queryTenantID,
75             @QueryParam("name") String queryName,
76             @QueryParam("transform_protocol") String queryTransformProtocol,
77             @QueryParam("encapsulation_mode") String queryEncapsulationMode,
78             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
79             @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
80             @QueryParam("pfs") String queryPFS
81     // pagination and sorting are TODO
82     ) {
83         INeutronVPNIPSECPolicyCRUD policyInterface = getNeutronCRUD();
84         List<NeutronVPNIPSECPolicy> allNeutronVPNIPSECPolicies = policyInterface.getAll();
85         List<NeutronVPNIPSECPolicy> ans = new ArrayList<>();
86         for (NeutronVPNIPSECPolicy policy : allNeutronVPNIPSECPolicies) {
87             if ((queryID == null || queryID.equals(policy.getID()))
88                     && (queryName == null || queryName.equals(policy.getName()))
89                     && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
90                     && (queryEncryptionAlgorithm == null
91                             || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
92                     && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
93                     && (queryTransformProtocol == null || queryTransformProtocol.equals(policy.getTransformProtocol()))
94                     && (queryEncapsulationMode == null || queryEncapsulationMode.equals(policy.getEncapsulationMode()))
95                     && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
96                 if (fields.size() > 0) {
97                     ans.add(policy.extractFields(fields));
98                 } else {
99                     ans.add(policy);
100                 }
101             }
102         }
103         //TODO: apply pagination to results
104         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVPNIPSECPolicyRequest(ans)).build();
105     }
106
107     /**
108      * Returns a specific VPN IPSEC Policy */
109
110     @Path("{policyID}")
111     @GET
112     @Produces({ MediaType.APPLICATION_JSON })
113     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
114             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
115             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
116             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
117             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
118             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
119     public Response showVPNIPSECPolicy(@PathParam("policyID") String policyUUID,
120             // return fields
121             @QueryParam("fields") List<String> fields) {
122         return show(policyUUID, fields);
123     }
124
125     /**
126      * Creates new VPN IPSEC Policy */
127     @POST
128     @Produces({ MediaType.APPLICATION_JSON })
129     @Consumes({ MediaType.APPLICATION_JSON })
130     @TypeHint(NeutronVPNIPSECPolicy.class)
131     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
132             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133     public Response createVPNIPSECPolicy(final NeutronVPNIPSECPolicyRequest input) {
134         return create(input);
135     }
136
137     /**
138      * Updates a VPN IPSEC Policy */
139     @Path("{policyID}")
140     @PUT
141     @Produces({ MediaType.APPLICATION_JSON })
142     @Consumes({ MediaType.APPLICATION_JSON })
143     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
144             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
145             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146     public Response updateVPNIPSECPolicy(@PathParam("policyID") String policyUUID,
147             final NeutronVPNIPSECPolicyRequest input) {
148         return update(policyUUID, input);
149     }
150
151     /**
152      * Deletes a VPN IPSEC Policy */
153
154     @Path("{policyID}")
155     @DELETE
156     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
157             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159     public Response deleteVPNIPSECPolicy(@PathParam("policyID") String policyUUID) {
160         return delete(policyUUID);
161     }
162 }