remove irrelevant old JavaDoc from a long bygone era in northbound.api
[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 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.INeutronVpnIpSecPolicyCRUD;
28 import org.opendaylight.neutron.spi.NeutronVpnIpSecPolicy;
29
30 /**
31  * Neutron Northbound REST APIs for VPN IPSEC Policy.
32  */
33 @Path("/vpn/ipsecpolicies")
34 public final class NeutronVpnIpSecPoliciesNorthbound extends
35         AbstractNeutronNorthbound<NeutronVpnIpSecPolicy, NeutronVpnIpSecPolicyRequest, INeutronVpnIpSecPolicyCRUD> {
36
37     private static final String RESOURCE_NAME = "VPNIPSECPolicy";
38
39     @Override
40     protected String getResourceName() {
41         return RESOURCE_NAME;
42     }
43
44     /**
45      * Returns a list of all VPN IPSEC 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 listVpnIPSecPolicies(
54             // return fields
55             @QueryParam("fields") List<String> fields,
56             // filter fields
57             @QueryParam("id") String queryID,
58             @QueryParam("tenant_id") String queryTenantID,
59             @QueryParam("name") String queryName,
60             @QueryParam("transform_protocol") String queryTransformProtocol,
61             @QueryParam("encapsulation_mode") String queryEncapsulationMode,
62             @QueryParam("auth_algorithm") String queryAuthAlgorithm,
63             @QueryParam("encryption_algorithm") String queryEncryptionAlgorithm,
64             @QueryParam("pfs") String queryPFS
65     // pagination and sorting are TODO
66     ) {
67         INeutronVpnIpSecPolicyCRUD policyInterface = getNeutronCRUD();
68         List<NeutronVpnIpSecPolicy> allNeutronVpnIPSecPolicies = policyInterface.getAll();
69         List<NeutronVpnIpSecPolicy> ans = new ArrayList<>();
70         for (NeutronVpnIpSecPolicy policy : allNeutronVpnIPSecPolicies) {
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                     && (queryPFS == null || queryPFS.equals(policy.getPerfectForwardSecrecy()))
77                     && (queryTransformProtocol == null || queryTransformProtocol.equals(policy.getTransformProtocol()))
78                     && (queryEncapsulationMode == null || queryEncapsulationMode.equals(policy.getEncapsulationMode()))
79                     && (queryTenantID == null || queryTenantID.equals(policy.getTenantID()))) {
80                 if (fields.size() > 0) {
81                     ans.add(policy.extractFields(fields));
82                 } else {
83                     ans.add(policy);
84                 }
85             }
86         }
87         //TODO: apply pagination to results
88         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIpSecPolicyRequest(ans)).build();
89     }
90
91     /**
92      * Returns a specific VPN IPSEC Policy.
93      */
94     @Path("{policyID}")
95     @GET
96     @Produces({ MediaType.APPLICATION_JSON })
97     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
98             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
99             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
100             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
101             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
102             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103     public Response showVpnIPSecPolicy(@PathParam("policyID") String policyUUID,
104                                        // return fields
105                                        @QueryParam("fields") List<String> fields) {
106         return show(policyUUID, fields);
107     }
108
109     /**
110      * Creates new VPN IPSEC Policy.
111      */
112     @POST
113     @Produces({ MediaType.APPLICATION_JSON })
114     @Consumes({ MediaType.APPLICATION_JSON })
115     @TypeHint(NeutronVpnIpSecPolicy.class)
116     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118     public Response createVpnIPSecPolicy(final NeutronVpnIpSecPolicyRequest input) {
119         return create(input);
120     }
121
122     /**
123      * Updates a VPN IPSEC Policy.
124      */
125     @Path("{policyID}")
126     @PUT
127     @Produces({ MediaType.APPLICATION_JSON })
128     @Consumes({ MediaType.APPLICATION_JSON })
129     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
130             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
131             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
132     public Response updateVpnIPSecPolicy(@PathParam("policyID") String policyUUID,
133                                          final NeutronVpnIpSecPolicyRequest input) {
134         return update(policyUUID, input);
135     }
136
137     /**
138      * Deletes a VPN IPSEC Policy.
139      */
140     @Path("{policyID}")
141     @DELETE
142     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
143             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
144             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
145     public Response deleteVpnIPSecPolicy(@PathParam("policyID") String policyUUID) {
146         return delete(policyUUID);
147     }
148 }