remove irrelevant old JavaDoc from a long bygone era in 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 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.DefaultValue;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.Context;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.UriInfo;
27 import org.codehaus.enunciate.jaxrs.ResponseCode;
28 import org.codehaus.enunciate.jaxrs.StatusCodes;
29 import org.codehaus.enunciate.jaxrs.TypeHint;
30 import org.opendaylight.neutron.spi.INeutronBgpvpnCRUD;
31 import org.opendaylight.neutron.spi.NeutronBgpvpn;
32
33 /**
34  * Neutron Northbound REST APIs for Bgpvpn.
35  */
36 @Path("/bgpvpns")
37 public final class NeutronBgpvpnsNorthbound
38         extends AbstractNeutronNorthbound<NeutronBgpvpn, NeutronBgpvpnRequest, INeutronBgpvpnCRUD> {
39
40     private static final String RESOURCE_NAME = "Bgpvpn";
41
42     @Context
43     UriInfo uriInfo;
44
45     @Override
46     protected String getResourceName() {
47         return RESOURCE_NAME;
48     }
49
50     /**
51      * Returns a list of all Bgpvpns.
52      */
53     @GET
54     @Produces({ MediaType.APPLICATION_JSON })
55     //@TypeHint(OpenStackBgpvpns.class)
56     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
57             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
58             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
59             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
60     public Response listBgpvpns(
61             // return fields
62             @QueryParam("fields") List<String> fields,
63             // note: openstack isn't clear about filtering on lists, so we aren't handling them
64             @QueryParam("id") String queryID,
65             @QueryParam("name") String queryName,
66             @QueryParam("admin_state_up") String queryAdminStateUp,
67             @QueryParam("status") String queryStatus,
68             @QueryParam("tenant_id") String queryTenantID,
69             @QueryParam("type") String queryType,
70             @QueryParam("auto_aggregate") String queryAutoAggregate,
71             // pagination
72             @QueryParam("limit") Integer limit,
73             @QueryParam("marker") String marker,
74             @DefaultValue("false") @QueryParam("page_reverse") Boolean pageReverse
75     // sorting not supported
76     ) {
77         INeutronBgpvpnCRUD bgpvpnInterface = getNeutronCRUD();
78         List<NeutronBgpvpn> allBgpvpns = bgpvpnInterface.getAll();
79         List<NeutronBgpvpn> ans = new ArrayList<>();
80         for (NeutronBgpvpn bgpvpn : allBgpvpns) {
81             //match filters: TODO provider extension
82             Boolean adminStateUp = queryAdminStateUp != null ? Boolean.valueOf(queryAdminStateUp) : null;
83             Boolean autoAggregate = queryAutoAggregate != null ? Boolean.valueOf(queryAutoAggregate) : null;
84             if ((queryID == null || queryID.equals(bgpvpn.getID()))
85                     && (queryName == null || queryName.equals(bgpvpn.getName()))
86                     && (adminStateUp == null || adminStateUp.booleanValue() == bgpvpn.isAdminStateUp())
87                     && (queryStatus == null || queryStatus.equals(bgpvpn.getStatus()))
88                     && (autoAggregate == null || autoAggregate.booleanValue() == bgpvpn.isAutoAggregate())
89                     && (queryTenantID == null || queryTenantID.equals(bgpvpn.getTenantID()))) {
90                 if (fields.size() > 0) {
91                     ans.add(bgpvpn.extractFields(fields));
92                 } else {
93                     ans.add(bgpvpn);
94                 }
95             }
96         }
97
98         if (limit != null && ans.size() > 1) {
99             // Return a paginated request
100             NeutronBgpvpnRequest request = (NeutronBgpvpnRequest) PaginatedRequestFactory.createRequest(limit, marker,
101                     pageReverse, uriInfo, ans, NeutronBgpvpn.class);
102             return Response.status(HttpURLConnection.HTTP_OK).entity(request).build();
103         }
104
105         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronBgpvpnRequest(ans)).build();
106
107     }
108
109     /**
110      * Returns a specific Bgpvpn.
111      */
112     @Path("{bgpvpnUUID}")
113     @GET
114     @Produces({ MediaType.APPLICATION_JSON })
115     //@TypeHint(OpenStackBgpvpns.class)
116     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
118             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
119             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
120             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
121     public Response showBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID,
122             // return fields
123             @QueryParam("fields") List<String> fields) {
124         return show(bgpvpnUUID, fields);
125     }
126
127     /**
128      * Creates new Bgpvpns.
129      */
130     @POST
131     @Produces({ MediaType.APPLICATION_JSON })
132     @Consumes({ MediaType.APPLICATION_JSON })
133     @TypeHint(NeutronBgpvpn.class)
134     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
135             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
136     public Response createBgpvpns(final NeutronBgpvpnRequest input) {
137         return create(input);
138     }
139
140     /**
141      * Updates a Bgpvpn.
142      */
143     @Override
144     protected void updateDelta(String uuid, NeutronBgpvpn delta, NeutronBgpvpn original) {
145         //Fill in defaults if they're missing in update
146         delta.initDefaults();
147         delta.setID(uuid);
148         delta.setTenantID(original.getTenantID());
149     }
150
151     @Path("{bgpvpnUUID}")
152     @PUT
153     @Produces({ MediaType.APPLICATION_JSON })
154     @Consumes({ MediaType.APPLICATION_JSON })
155     //@TypeHint(OpenStackBgpvpns.class)
156     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
157             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
158             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
159     public Response updateBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID, final NeutronBgpvpnRequest input) {
160         return update(bgpvpnUUID, input);
161     }
162
163     /**
164      * Deletes a Bgpvpn.
165      */
166     @Path("{bgpvpnUUID}")
167     @DELETE
168     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
169             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
170             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
171     public Response deleteBgpvpn(@PathParam("bgpvpnUUID") String bgpvpnUUID) {
172         return delete(bgpvpnUUID);
173     }
174 }