Merge "remove redundant methods for compatibility"
[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
13 import java.util.ArrayList;
14 import java.util.Iterator;
15 import java.util.List;
16
17 import javax.ws.rs.Consumes;
18 import javax.ws.rs.DELETE;
19 import javax.ws.rs.GET;
20 import javax.ws.rs.POST;
21 import javax.ws.rs.PUT;
22 import javax.ws.rs.Path;
23 import javax.ws.rs.PathParam;
24 import javax.ws.rs.Produces;
25 import javax.ws.rs.QueryParam;
26 import javax.ws.rs.core.Context;
27 import javax.ws.rs.core.MediaType;
28 import javax.ws.rs.core.Response;
29 import javax.ws.rs.core.UriInfo;
30
31 import org.codehaus.enunciate.jaxrs.ResponseCode;
32 import org.codehaus.enunciate.jaxrs.StatusCodes;
33 import org.codehaus.enunciate.jaxrs.TypeHint;
34 import org.opendaylight.neutron.spi.INeutronVPNIKEPolicyCRUD;
35 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
36 import org.opendaylight.neutron.spi.NeutronVPNIKEPolicy;
37
38 /**
39  * Neutron Northbound REST APIs for VPN IKE Policy.<br>
40  * This class provides REST APIs for managing neutron VPN IKE Policies
41  *
42  * <br>
43  * <br>
44  * Authentication scheme : <b>HTTP Basic</b><br>
45  * Authentication realm : <b>opendaylight</b><br>
46  * Transport : <b>HTTP and HTTPS</b><br>
47  * <br>
48  * HTTPS Authentication is disabled by default. Administrator can enable it in
49  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
50  * trusted authority.<br>
51  * More info :
52  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
53  *
54  */
55
56 @Path("/vpn/ikepolicies")
57 public class NeutronVPNIKEPoliciesNorthbound
58     extends AbstractNeutronNorthbound<NeutronVPNIKEPolicy, NeutronVPNIKEPolicyRequest, INeutronVPNIKEPolicyCRUD> {
59     private static final String RESOURCE_NAME = "VPNIKEPolicy";
60
61     @Override
62     protected String getResourceName() {
63         return RESOURCE_NAME;
64     }
65
66     @Override
67     protected NeutronVPNIKEPolicy extractFields(NeutronVPNIKEPolicy o, List<String> fields) {
68         return o.extractFields(fields);
69     }
70
71     @Override
72     protected INeutronVPNIKEPolicyCRUD getNeutronCRUD() {
73         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronVPNIKEPolicyCRUD(this);
74         if (answer.getVPNIKEPolicyInterface() == null) {
75             throw new ServiceUnavailableException(serviceUnavailable());
76         }
77         return answer.getVPNIKEPolicyInterface();
78     }
79
80     @Override
81     protected NeutronVPNIKEPolicyRequest newNeutronRequest(NeutronVPNIKEPolicy o) {
82         return new NeutronVPNIKEPolicyRequest(o);
83     }
84
85     @Context
86     UriInfo uriInfo;
87
88     /**
89      * Returns a list of all VPN IKE Policies */
90
91     @GET
92     @Produces({ MediaType.APPLICATION_JSON })
93     @StatusCodes({
94             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
95             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
96             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
97             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
98     public Response listVPNIKEPolicies(
99             // return fields
100             @QueryParam("fields") List<String> fields,
101             // filter fields
102             @QueryParam("id") String queryID,
103             @QueryParam("name") String queryName,
104             @QueryParam("tenant_id") String queryTenantID,
105             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
106             @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
107             @QueryParam("phase1_negotiation_mode") String queryPhase1NegotiationMode,
108             @QueryParam("pfs") String queryPFS,
109             @QueryParam("ike_version") String queryIKEVersion
110             // pagination and sorting are TODO
111             ) {
112         INeutronVPNIKEPolicyCRUD labelInterface = getNeutronCRUD();
113         List<NeutronVPNIKEPolicy> allNeutronVPNIKEPolicy = labelInterface.getAll();
114         List<NeutronVPNIKEPolicy> ans = new ArrayList<NeutronVPNIKEPolicy>();
115         Iterator<NeutronVPNIKEPolicy> i = allNeutronVPNIKEPolicy.iterator();
116         while (i.hasNext()) {
117             NeutronVPNIKEPolicy oSS = i.next();
118             if ((queryID == null || queryID.equals(oSS.getID())) &&
119                     (queryName == null || queryName.equals(oSS.getName())) &&
120                     (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(oSS.getAuthAlgorithm())) &&
121                     (queryEncryptionAlgorithm == null || queryEncryptionAlgorithm.equals(oSS.getEncryptionAlgorithm())) &&
122                     (queryPhase1NegotiationMode == null || queryPhase1NegotiationMode.equals(oSS.getPhase1NegotiationMode())) &&
123                     (queryPFS == null || queryPFS.equals(oSS.getPerfectForwardSecrecy())) &&
124                     (queryIKEVersion == null || queryIKEVersion.equals(oSS.getIkeVersion())) &&
125                     (queryTenantID == null || queryTenantID.equals(oSS.getTenantID()))) {
126                 if (fields.size() > 0) {
127                     ans.add(extractFields(oSS,fields));
128                 } else {
129                     ans.add(oSS);
130                 }
131             }
132         }
133         //TODO: apply pagination to results
134         return Response.status(HttpURLConnection.HTTP_OK).entity(
135                 new NeutronVPNIKEPolicyRequest(ans)).build();
136     }
137
138     /**
139      * Returns a specific VPN IKE Policy */
140
141     @Path("{policyID}")
142     @GET
143     @Produces({ MediaType.APPLICATION_JSON })
144     @StatusCodes({
145             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
146             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
147             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
148             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
149             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
150             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
151     public Response showVPNIKEPolicy(
152             @PathParam("policyID") String policyUUID,
153             // return fields
154             @QueryParam("fields") List<String> fields
155             ) {
156         return show(policyUUID, fields);
157     }
158
159     /**
160      * Creates new VPN IKE Policy */
161     @POST
162     @Produces({ MediaType.APPLICATION_JSON })
163     @Consumes({ MediaType.APPLICATION_JSON })
164     @TypeHint(NeutronVPNIKEPolicy.class)
165     @StatusCodes({
166             @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
167             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
168     public Response createVPNIKEPolicy(final NeutronVPNIKEPolicyRequest input) {
169         return create(input);
170     }
171
172     /**
173      * Updates a VPN IKE Policy */
174     @Path("{policyID}")
175     @PUT
176     @Produces({ MediaType.APPLICATION_JSON })
177     @Consumes({ MediaType.APPLICATION_JSON })
178     @StatusCodes({
179             @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
180             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
181             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
182     public Response updateVPNIKEPolicy(
183             @PathParam("policyID") String policyUUID, final NeutronVPNIKEPolicyRequest input
184             ) {
185         return update(policyUUID, input);
186     }
187
188     /**
189      * Deletes a VPN IKE Policy */
190
191     @Path("{policyID}")
192     @DELETE
193     @StatusCodes({
194             @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
195             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
196             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
197     public Response deleteVPNIKEPolicy(
198             @PathParam("policyID") String policyUUID) {
199         return delete(policyUUID);
200     }
201 }