Checkstyle formatting issues fix (Northbound API)
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronBgpvpnsNorthbound.java
1 /*
2  * Copyright (c) 2015 Ericsson India Global Services Pvt Ltd. 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 import java.util.ArrayList;
13 import java.util.Iterator;
14 import java.util.List;
15 import javax.ws.rs.Consumes;
16 import javax.ws.rs.DELETE;
17 import javax.ws.rs.DefaultValue;
18 import javax.ws.rs.GET;
19 import javax.ws.rs.POST;
20 import javax.ws.rs.PUT;
21 import javax.ws.rs.Path;
22 import javax.ws.rs.PathParam;
23 import javax.ws.rs.Produces;
24 import javax.ws.rs.QueryParam;
25 import javax.ws.rs.core.Context;
26 import javax.ws.rs.core.MediaType;
27 import javax.ws.rs.core.Response;
28 import javax.ws.rs.core.UriInfo;
29 import org.codehaus.enunciate.jaxrs.ResponseCode;
30 import org.codehaus.enunciate.jaxrs.StatusCodes;
31 import org.codehaus.enunciate.jaxrs.TypeHint;
32 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
33 import org.opendaylight.neutron.spi.NeutronBgpvpn;
34 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
35
36 /**
37  * Neutron Northbound REST APIs for Bgpvpn.<br>
38  * This class provides REST APIs for managing neutron Bgpvpns
39  *
40  * <br>
41  * <br>
42  * Authentication scheme : <b>HTTP Basic</b><br>
43  * Authentication realm : <b>opendaylight</b><br>
44  * Transport : <b>HTTP and HTTPS</b><br>
45  * <br>
46  * HTTPS Authentication is disabled by default. Administrator can enable it in
47  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
48  * trusted authority.<br>
49  * More info :
50  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
51  *
52  */
53
54 @Path("/bgpvpns")
55 public class NeutronBgpvpnsNorthbound
56         extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
57
58     @Context
59     UriInfo uriInfo;
60
61     private static final String RESOURCE_NAME = "Bgpvpn";
62
63     @Override
64     protected String getResourceName() {
65         return RESOURCE_NAME;
66     }
67
68     @Override
69     protected NeutronBgpvpn extractFields(NeutronBgpvpn o, List<String> fields) {
70         return o.extractFields(fields);
71     }
72
73     @Override
74     protected NeutronBgpvpnRequest newNeutronRequest(NeutronBgpvpn o) {
75         return new NeutronBgpvpnRequest(o);
76     }
77
78     @Override
79     protected INeutronBgpvpnCRUD getNeutronCRUD() {
80         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronBgpvpnCRUD(this);
81         if (answer.getBgpvpnInterface() == null) {
82             throw new ServiceUnavailableException(serviceUnavailable());
83         }
84         return answer.getBgpvpnInterface();
85     }
86
87     /**
88      * Returns a list of all Bgpvpns */
89
90     @GET
91     @Produces({ MediaType.APPLICATION_JSON })
92     //@TypeHint(OpenStackBgpvpns.class)
93     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
94             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
95             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
96             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
97     public Response listBgpvpns(
98             // return fields
99             @QueryParam("fields") List<String> fields,
100             // note: openstack isn't clear about filtering on lists, so we aren't handling them
101             @QueryParam("id") String queryID,
102             @QueryParam("name") String queryName,
103             @QueryParam("admin_state_up") String queryAdminStateUp,
104             @QueryParam("status") String queryStatus,
105             @QueryParam("tenant_id") String queryTenantID,
106             @QueryParam("type") String queryType,
107             @QueryParam("auto_aggregate") String queryAutoAggregate,
108             // pagination
109             @QueryParam("limit") Integer limit,
110             @QueryParam("marker") String marker,
111             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
112     // sorting not supported
113     ) {
114         INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
115         List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
116         List<NeutronBgpvpn> ans = new ArrayList<>();
117         Iterator<NeutronBgpvpn> i = allBgpvpns.iterator();
118         while (i.hasNext()) {
119             NeutronBgpvpn oSN = i.next();
120             //match filters: TODO provider extension
121             Boolean bAdminStateUp = null;
122             Boolean bAutoAggregate = null;
123             if (queryAdminStateUp != null) {
124                 bAdminStateUp = Boolean.valueOf(queryAdminStateUp);
125             }
126             if (queryAutoAggregate != null) {
127                 bAutoAggregate = Boolean.valueOf(queryAutoAggregate);
128             }
129             if ((queryID == null || queryID.equals(oSN.getID()))
130                     && (queryName == null || queryName.equals(oSN.getBgpvpnName()))
131                     && (bAdminStateUp == null || bAdminStateUp.booleanValue() == oSN.isAdminStateUp())
132                     && (queryStatus == null || queryStatus.equals(oSN.getStatus()))
133                     && (bAutoAggregate == null || bAutoAggregate.booleanValue() == oSN.isAutoAggregate())
134                     && (queryTenantID == null || queryTenantID.equals(oSN.getTenantID()))) {
135                 if (fields.size() > 0) {
136                     ans.add(extractFields(oSN, fields));
137                 } else {
138                     ans.add(oSN);
139                 }
140             }
141         }
142
143         if (limit != null && ans.size() > 1) {
144             // Return a paginated request
145             NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
146                     pageReverse, uriInfo, ans, NeutronBgpvpn.class);
147             return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
148         }
149
150         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
151
152     }
153
154     /**
155      * Returns a specific Bgpvpn */
156
157     @Path("{bgpvpnUUID}")
158     @GET
159     @Produces({ MediaType.APPLICATION_JSON })
160     //@TypeHint(OpenStackBgpvpns.class)
161     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
162             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
163             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
164             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
165             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
166     public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
167             // return fields
168             @QueryParam("fields") List<String> fields) {
169         return show(bgpvpnUUID, fields);
170     }
171
172     /**
173      * Creates new Bgpvpns */
174     @POST
175     @Produces({ MediaType.APPLICATION_JSON })
176     @Consumes({ MediaType.APPLICATION_JSON })
177     @TypeHint(NeutronBgpvpn.class)
178     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
179             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
180     public Response createBgpvpns(final NeutronBgpvpnRequest input) {
181         return create(input);
182     }
183
184     /**
185      * Updates a Bgpvpn */
186     @Override
187     protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
188         //Fill in defaults if they're missing in update
189         delta.initDefaults();
190         delta.setID(uuid);
191         delta.setTenantID(original.getTenantID());
192     }
193
194     @Path("{bgpvpnUUID}")
195     @PUT
196     @Produces({ MediaType.APPLICATION_JSON })
197     @Consumes({ MediaType.APPLICATION_JSON })
198     //@TypeHint(OpenStackBgpvpns.class)
199     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
200             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
201             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
202     public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
203         return update(bgpvpnUUID, input);
204     }
205
206     /**
207      * Deletes a Bgpvpn */
208
209     @Path("{bgpvpnUUID}")
210     @DELETE
211     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
212             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
213             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
214     public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
215         return delete(bgpvpnUUID);
216     }
217 }