remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronMeteringLabelsNorthbound.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.Path;
18 import javax.ws.rs.PathParam;
19 import javax.ws.rs.Produces;
20 import javax.ws.rs.QueryParam;
21 import javax.ws.rs.core.MediaType;
22 import javax.ws.rs.core.Response;
23 import org.codehaus.enunciate.jaxrs.ResponseCode;
24 import org.codehaus.enunciate.jaxrs.StatusCodes;
25 import org.opendaylight.neutron.spi.INeutronMeteringLabelCRUD;
26 import org.opendaylight.neutron.spi.NeutronMeteringLabel;
27
28 /**
29  * Neutron Northbound REST APIs for Metering Lables.
30  */
31 @Path("/metering/metering-labels")
32 public final class NeutronMeteringLabelsNorthbound extends
33         AbstractNeutronNorthbound<NeutronMeteringLabel, NeutronMeteringLabelRequest, INeutronMeteringLabelCRUD> {
34
35     private static final String RESOURCE_NAME = "Metering Label";
36
37     @Override
38     protected String getResourceName() {
39         return RESOURCE_NAME;
40     }
41
42     /**
43      * Returns a list of all metering labels.
44      */
45     @GET
46     @Produces({ MediaType.APPLICATION_JSON })
47     //@TypeHint(OpenStackNetworks.class)
48     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
49             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
50             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
51             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
52     public Response listMeteringLabels(
53             // return fields
54             @QueryParam("fields") List<String> fields,
55             // filter fields
56             @QueryParam("id") String queryID,
57             @QueryParam("name") String queryName,
58             @QueryParam("tenant_id") String queryTenantID
59     // pagination and sorting are TODO
60     ) {
61         INeutronMeteringLabelCRUD labelInterface = getNeutronCRUD();
62         List<NeutronMeteringLabel> allNeutronMeteringLabel = labelInterface.getAll();
63         List<NeutronMeteringLabel> ans = new ArrayList<>();
64         for (NeutronMeteringLabel label : allNeutronMeteringLabel) {
65             if ((queryID == null || queryID.equals(label.getID()))
66                     && (queryName == null || queryName.equals(label.getName()))
67                     && (queryTenantID == null || queryTenantID.equals(label.getTenantID()))) {
68                 if (fields.size() > 0) {
69                     ans.add(label.extractFields(fields));
70                 } else {
71                     ans.add(label);
72                 }
73             }
74         }
75         //TODO: apply pagination to results
76         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronMeteringLabelRequest(ans)).build();
77     }
78
79     /**
80      * Returns a specific metering label.
81      */
82     @Path("{labelUUID}")
83     @GET
84     @Produces({ MediaType.APPLICATION_JSON })
85     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
86             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
87             @ResponseCode(code = HttpURLConnection.HTTP_FORBIDDEN, condition = "Forbidden"),
88             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
89             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
90             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
91     public Response showMeteringLabel(@PathParam("labelUUID") String labelUUID,
92             // return fields
93             @QueryParam("fields") List<String> fields) {
94         return show(labelUUID, fields);
95     }
96
97     /**
98      * Creates new metering label.
99      */
100     @POST
101     @Produces({ MediaType.APPLICATION_JSON })
102     @Consumes({ MediaType.APPLICATION_JSON })
103     //@TypeHint(NeutronNetwork.class)
104     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
105             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
106     public Response createMeteringLabel(final NeutronMeteringLabelRequest input) {
107         return create(input);
108     }
109
110     /**
111      * Deletes a Metering Label.
112      */
113     @Path("{labelUUID}")
114     @DELETE
115     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
116             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
117             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
118     public Response deleteMeteringLabel(@PathParam("labelUUID") String labelUUID) {
119         return delete(labelUUID);
120     }
121 }