remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronVpnServicesNorthbound.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.INeutronVpnServiceCRUD;
28 import org.opendaylight.neutron.spi.NeutronVpnService;
29
30 /**
31  * Neutron Northbound REST APIs for VPN Service.
32  */
33 @Path("/vpn/vpnservices")
34 public final class NeutronVpnServicesNorthbound
35         extends AbstractNeutronNorthbound<NeutronVpnService, NeutronVpnServiceRequest, INeutronVpnServiceCRUD> {
36
37     private static final String RESOURCE_NAME = "VpnService";
38
39     @Override
40     protected String getResourceName() {
41         return RESOURCE_NAME;
42     }
43
44     /**
45      * Returns a list of all VPN Services.
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 listVPNServices(
54             // return fields
55             @QueryParam("fields") List<String> fields,
56             // OpenStack VPNService attributes
57             @QueryParam("id") String queryID,
58             @QueryParam("tenant_id") String queryTenantID,
59             @QueryParam("name") String queryName,
60             @QueryParam("admin_state_up") Boolean queryAdminStateUp,
61             @QueryParam("router_id") String queryRouterID,
62             @QueryParam("status") String queryStatus,
63             @QueryParam("subnet_id") String querySubnetID,
64             // pagination
65             @QueryParam("limit") String limit,
66             @QueryParam("marker") String marker,
67             @QueryParam("page_reverse") String pageReverse
68     // sorting not supported
69     ) {
70         INeutronVpnServiceCRUD vpnServiceInterface = getNeutronCRUD();
71         List<NeutronVpnService> allVPNService = vpnServiceInterface.getAll();
72         List<NeutronVpnService> ans = new ArrayList<>();
73         for (NeutronVpnService vpnService : allVPNService) {
74             if ((queryID == null || queryID.equals(vpnService.getID()))
75                     && (queryName == null || queryName.equals(vpnService.getName()))
76                     && (queryAdminStateUp == null || queryAdminStateUp.equals(vpnService.getAdminStateUp()))
77                     && (queryStatus == null || queryStatus.equals(vpnService.getStatus()))
78                     && (querySubnetID == null || querySubnetID.equals(vpnService.getSubnetUUID()))
79                     && (queryRouterID == null || queryRouterID.equals(vpnService.getRouterUUID()))
80                     && (queryTenantID == null || queryTenantID.equals(vpnService.getTenantID()))) {
81                 if (fields.size() > 0) {
82                     ans.add(vpnService.extractFields(fields));
83                 } else {
84                     ans.add(vpnService);
85                 }
86             }
87         }
88
89         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronVpnServiceRequest(ans)).build();
90     }
91
92     /**
93      * Returns a specific VPN Service.
94      */
95     @Path("{serviceID}")
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_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 showVPNService(@PathParam("serviceID") String serviceID,
104             // return fields
105             @QueryParam("fields") List<String> fields) {
106         return show(serviceID, fields);
107     }
108
109     /**
110      * Creates new VPN Service.
111      */
112     @POST
113     @Produces({ MediaType.APPLICATION_JSON })
114     @Consumes({ MediaType.APPLICATION_JSON })
115     @TypeHint(NeutronVpnService.class)
116     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118     public Response createVPNService(final NeutronVpnServiceRequest input) {
119         return create(input);
120     }
121
122     /**
123      * Updates a VPN Service.
124      */
125     @Path("{serviceID}")
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 updateVPNService(@PathParam("serviceID") String serviceID, final NeutronVpnServiceRequest input) {
133         return update(serviceID, input);
134     }
135
136     /**
137      * Deletes a VPN Service.
138      */
139     @Path("{serviceID}")
140     @DELETE
141     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
142             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
143             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
144     public Response deleteVPNService(@PathParam("serviceID") String serviceID) {
145         return delete(serviceID);
146     }
147 }