remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVpnIpSecSiteConnectionsNorthbound.java
1 /*
2  * Copyright (c) 2013, 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.INeutronVpnIpSecSiteConnectionsCRUD;
28 import org.opendaylight.neutron.spi.NeutronVpnIpSecSiteConnection;
29
30 /**
31  * Neutron Northbound REST APIs for VPN IPSEC SiteConnection.<br>
32  */
33 @Path("/vpn/ipsecsiteconnections")
34 public final class NeutronVpnIpSecSiteConnectionsNorthbound
35         extends AbstractNeutronNorthbound<NeutronVpnIpSecSiteConnection,
36         NeutronVpnIpSecSiteConnectionRequest, INeutronVpnIpSecSiteConnectionsCRUD> {
37
38     private static final String RESOURCE_NAME = "VPNIPSECSiteConnections";
39
40     @Override
41     protected String getResourceName() {
42         return RESOURCE_NAME;
43     }
44
45     /**
46      * Returns a list of all VPN IPSEC SiteConnections.
47      */
48     @GET
49     @Produces({ MediaType.APPLICATION_JSON })
50     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
51             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
52             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
53             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
54     public Response listVpnIPSecSiteConnections(
55             // return fields
56             @QueryParam("fields") List<String> fields,
57             // filter fields
58             @QueryParam("id") String queryID,
59             @QueryParam("tenant_id") String queryTenantID,
60             @QueryParam("name") String queryName,
61             @QueryParam("peer_address") String queryPeerAddress,
62             @QueryParam("peer_id") String queryPeerID,
63             @QueryParam("route_mode") String queryRouteMode,
64             @QueryParam("mtu") Integer queryMtu,
65             @QueryParam("auth_mode") String queryAuthMode,
66             @QueryParam("psk") String queryPsk,
67             @QueryParam("initiator") String queryInitiator,
68             @QueryParam("admin_state_up") Boolean queryAdminStateUp,
69             @QueryParam("status") String queryStatus,
70             @QueryParam("ikepolicy_id") String queryIkePolicyID,
71             @QueryParam("ipsecpolicy_id") String queryIpSecPolicyID,
72             @QueryParam("vpnservice_id") String queryVpnServiceID
73     // pagination and sorting are TODO
74     ) {
75         INeutronVpnIpSecSiteConnectionsCRUD labelInterface = getNeutronCRUD();
76         List<NeutronVpnIpSecSiteConnection> allNeutronVpnIPSecSiteConnection = labelInterface.getAll();
77         List<NeutronVpnIpSecSiteConnection> ans = new ArrayList<>();
78         for (NeutronVpnIpSecSiteConnection siteConnection : allNeutronVpnIPSecSiteConnection) {
79             if ((queryID == null || queryID.equals(siteConnection.getID()))
80                     && (queryTenantID == null || queryTenantID.equals(siteConnection.getTenantID()))
81                     && (queryName == null || queryName.equals(siteConnection.getName()))
82                     && (queryPeerAddress == null || queryPeerAddress.equals(siteConnection.getPeerAddress()))
83                     && (queryPeerID == null || queryPeerID.equals(siteConnection.getPeerID()))
84                     && (queryRouteMode == null || queryRouteMode.equals(siteConnection.getRouteMode()))
85                     && (queryMtu == null || queryMtu.equals(siteConnection.getMtu()))
86                     && (queryAuthMode == null || queryAuthMode.equals(siteConnection.getAuthMode()))
87                     && (queryPsk == null || queryPsk.equals(siteConnection.getPreSharedKey()))
88                     && (queryInitiator == null || queryInitiator.equals(siteConnection.getInitiator()))
89                     && (queryAdminStateUp == null || queryAdminStateUp.equals(siteConnection.getAdminStateUp()))
90                     && (queryStatus == null || queryStatus.equals(siteConnection.getStatus()))
91                     && (queryIkePolicyID == null || queryIkePolicyID.equals(siteConnection.getIkePolicyID()))
92                     && (queryIpSecPolicyID == null || queryIpSecPolicyID.equals(siteConnection.getIpsecPolicyID()))
93                     && (queryVpnServiceID == null || queryVpnServiceID.equals(siteConnection.getVpnServiceID()))) {
94                 if (fields.size() > 0) {
95                     ans.add(siteConnection.extractFields(fields));
96                 } else {
97                     ans.add(siteConnection);
98                 }
99             }
100         }
101
102         // TODO: apply pagination to results
103         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnIpSecSiteConnectionRequest(ans)).build();
104     }
105
106     /**
107      * Returns a specific VPN IPSEC SiteConnection.
108      */
109     @Path("{connectionID}")
110     @GET
111     @Produces({ MediaType.APPLICATION_JSON })
112     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
113             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
114             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
115             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
116             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118     public Response showVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID,
119                                                // return fields
120                                                @QueryParam("fields") List<String> fields) {
121         return show(connectionID, fields);
122     }
123
124     /**
125      * Creates new VPN IPSEC SiteConnection.
126      */
127     @POST
128     @Produces({ MediaType.APPLICATION_JSON })
129     @Consumes({ MediaType.APPLICATION_JSON })
130     @TypeHint(NeutronVpnIpSecSiteConnection.class)
131     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
132             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
133     public Response createVpnIPSecSiteConnection(final NeutronVpnIpSecSiteConnectionRequest input) {
134         return create(input);
135     }
136
137     /**
138      * Updates a VPN IPSEC SiteConnection.
139      */
140     @Path("{connectionID}")
141     @PUT
142     @Produces({ MediaType.APPLICATION_JSON })
143     @Consumes({ MediaType.APPLICATION_JSON })
144     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
145             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
146             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
147     public Response updateVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID,
148                                                  final NeutronVpnIpSecSiteConnectionRequest input) {
149         return update(connectionID, input);
150     }
151
152     /**
153      * Deletes a VPN IPSEC SiteConnection.
154      */
155     @Path("{connectionID}")
156     @DELETE
157     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
158             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
159             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
160     public Response deleteVpnIPSecSiteConnection(@PathParam("connectionID") String connectionID) {
161         return delete(connectionID);
162     }
163
164 }