remove irrelevant old JavaDoc from a long bygone era in northbound.api
[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 package org.opendaylight.neutron.northbound.api;
9
10 import java.net.HttpURLConnection;
11 import java.util.ArrayList;
12 import java.util.List;
13 import javax.ws.rs.Consumes;
14 import javax.ws.rs.DELETE;
15 import javax.ws.rs.GET;
16 import javax.ws.rs.POST;
17 import javax.ws.rs.PUT;
18 import javax.ws.rs.Path;
19 import javax.ws.rs.PathParam;
20 import javax.ws.rs.Produces;
21 import javax.ws.rs.QueryParam;
22 import javax.ws.rs.core.MediaType;
23 import javax.ws.rs.core.Response;
24 import org.codehaus.enunciate.jaxrs.ResponseCode;
25 import org.codehaus.enunciate.jaxrs.StatusCodes;
26 import org.codehaus.enunciate.jaxrs.TypeHint;
27 import org.opendaylight.neutron.spi.INeutronVpnIkePolicyCRUD;
28 import org.opendaylight.neutron.spi.NeutronVpnIkePolicy;
29
30 /**
31  * Neutron Northbound REST APIs for VPN IKE Policy.
32  */
33 @Path("/vpn/ikepolicies")
34 public final class NeutronVpnIkePoliciesNorthbound
35         extends AbstractNeutronNorthbound<NeutronVpnIkePolicy, NeutronVpnIkePolicyRequest, INeutronVpnIkePolicyCRUD> {
36
37     private static final String RESOURCE_NAME = "VPNIKEPolicy";
38
39     @Override
40     protected String getResourceName() {
41         return RESOURCE_NAME;
42     }
43
44     /**
45      * Returns a list of all VPN IKE Policies.
46      */
47     @GET
48     @Produces({ MediaType.APPLICATION_JSON })
49     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
50             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
51             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
52             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
53     public Response listVpnIkePolicies(
54             // return fields
55             @QueryParam("fields") List<String> fields,
56             // filter fields
57             @QueryParam("id") String queryID,
58             @QueryParam("name") String queryName,
59             @QueryParam("tenant_id") String queryTenantID,
60             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
61             @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
62             @QueryParam("phase1_negotiation_mode") String queryPhase1NegotiationMode,
63             @QueryParam("pfs") String queryPFS,
64             @QueryParam("ike_version") String queryIKEVersion
65     // pagination and sorting are TODO
66     ) {
67         INeutronVpnIkePolicyCRUD labelInterface = getNeutronCRUD();
68         List<NeutronVpnIkePolicy> allNeutronVpnIkePolicy = labelInterface.getAll();
69         List<NeutronVpnIkePolicy> ans = new ArrayList<>();
70         for (NeutronVpnIkePolicy policy : allNeutronVpnIkePolicy) {
71             if ((queryID == null || queryID.equals(policy.getID()))
72                     && (queryName == null || queryName.equals(policy.getName()))
73                     && (queryAuthAlgorithm == null || queryAuthAlgorithm.equals(policy.getAuthAlgorithm()))
74                     && (queryEncryptionAlgorithm == null
75                             || queryEncryptionAlgorithm.equals(policy.getEncryptionAlgorithm()))
76                     && (queryPhase1NegotiationMode == null
77                             || queryPhase1NegotiationMode.equals(policy.getPhase1NegotiationMode()))
78                     && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
79                     && (queryIKEVersion == null || queryIKEVersion.equals(policy.getIkeVersion()))
80                     && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
81                 if (fields.size() > 0) {
82                     ans.add(policy.extractFields(fields));
83                 } else {
84                     ans.add(policy);
85                 }
86             }
87         }
88         //TODO: apply pagination to results
89         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIkePolicyRequest(ans)).build();
90     }
91
92     /**
93      * Returns a specific VPN IKE Policy.
94      */
95     @Path("{policyID}")
96     @GET
97     @Produces({ MediaType.APPLICATION_JSON })
98     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
99             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
100             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
101             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
102             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
103             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
104     public Response showVpnIkePolicy(@PathParam("policyID") String policyUUID,
105                                      // return fields
106                                      @QueryParam("fields") List<String> fields) {
107         return show(policyUUID, fields);
108     }
109
110     /**
111      * Creates new VPN IKE Policy.
112      */
113     @POST
114     @Produces({ MediaType.APPLICATION_JSON })
115     @Consumes({ MediaType.APPLICATION_JSON })
116     @TypeHint(NeutronVpnIkePolicy.class)
117     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
118             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
119     public Response createVpnIkePolicy(final NeutronVpnIkePolicyRequest input) {
120         return create(input);
121     }
122
123     /**
124      * Updates a VPN IKE Policy.
125      */
126     @Path("{policyID}")
127     @PUT
128     @Produces({ MediaType.APPLICATION_JSON })
129     @Consumes({ MediaType.APPLICATION_JSON })
130     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
131             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
132             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133     public Response updateVpnIkePolicy(@PathParam("policyID") String policyUUID,
134                                        final NeutronVpnIkePolicyRequest input) {
135         return update(policyUUID, input);
136     }
137
138     /**
139      * Deletes a VPN IKE Policy.
140      */
141     @Path("{policyID}")
142     @DELETE
143     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
144             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
145             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
146     public Response deleteVpnIkePolicy(@PathParam("policyID") String policyUUID) {
147         return delete(policyUUID);
148     }
149 }