checkstyle: enable JavadocTagContinuationIndentation
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVPNIKEPoliciesNorthbound.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.INeutronVPNIKEPolicyCRUD;
29 import org.opendaylight.neutron.spi.NeutronVPNIKEPolicy;
30
31 /**
32  * Neutron Northbound REST APIs for VPN IKE Policy.<br>
33  * This class provides REST APIs for managing neutron VPN IKE 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/ikepolicies")
50 public final class NeutronVPNIKEPoliciesNorthbound
51         extends AbstractNeutronNorthbound<NeutronVPNIKEPolicy, NeutronVPNIKEPolicyRequest, INeutronVPNIKEPolicyCRUD> {
52     private static final String RESOURCE_NAME = "VPNIKEPolicy";
53
54     @Override
55     protected String getResourceName() {
56         return RESOURCE_NAME;
57     }
58
59     /**
60      * Returns a list of all VPN IKE Policies */
61
62     @GET
63     @Produces({ MediaType.APPLICATION_JSON })
64     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
65             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
66             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
67             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
68     public Response listVPNIKEPolicies(
69             // return fields
70             @QueryParam("fields") List<String> fields,
71             // filter fields
72             @QueryParam("id") String queryID,
73             @QueryParam("name") String queryName,
74             @QueryParam("tenant_id") String queryTenantID,
75             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
76             @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
77             @QueryParam("phase1_negotiation_mode") String queryPhase1NegotiationMode,
78             @QueryParam("pfs") String queryPFS,
79             @QueryParam("ike_version") String queryIKEVersion
80     // pagination and sorting are TODO
81     ) {
82         INeutronVPNIKEPolicyCRUD labelInterface = getNeutronCRUD();
83         List<NeutronVPNIKEPolicy> allNeutronVPNIKEPolicy = labelInterface.getAll();
84         List<NeutronVPNIKEPolicy> ans = new ArrayList<>();
85         for (NeutronVPNIKEPolicy policy : allNeutronVPNIKEPolicy) {
86             if ((queryID == null || queryID.equals(policy.getID()))
87                     && (queryName == null || queryName.equals(policy.getName()))
88                     && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
89                     && (queryEncryptionAlgorithm == null
90                             || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
91                     && (queryPhase1NegotiationMode == null
92                             || queryPhase1NegotiationMode.equals(policy.getPhase1NegotiationMode()))
93                     && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
94                     && (queryIKEVersion == null || queryIKEVersion.equals(policy.getIkeVersion()))
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 NeutronVPNIKEPolicyRequest(ans)).build();
105     }
106
107     /**
108      * Returns a specific VPN IKE 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 showVPNIKEPolicy(@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 IKE Policy */
127     @POST
128     @Produces({ MediaType.APPLICATION_JSON })
129     @Consumes({ MediaType.APPLICATION_JSON })
130     @TypeHint(NeutronVPNIKEPolicy.class)
131     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
132             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133     public Response createVPNIKEPolicy(final NeutronVPNIKEPolicyRequest input) {
134         return create(input);
135     }
136
137     /**
138      * Updates a VPN IKE 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 updateVPNIKEPolicy(@PathParam("policyID") String policyUUID,
147             final NeutronVPNIKEPolicyRequest input) {
148         return update(policyUUID, input);
149     }
150
151     /**
152      * Deletes a VPN IKE 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 deleteVPNIKEPolicy(@PathParam("policyID") String policyUUID) {
160         return delete(policyUUID);
161     }
162 }