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