remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronSFCPortPairGroupsNorthbound.java
1 /*
2  * Copyright (c) 2016 Brocade Communications Systems, Inc. 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.opendaylight.neutron.spi.INeutronSFCPortPairGroupCRUD;
27 import org.opendaylight.neutron.spi.NeutronSFCPortPairGroup;
28
29 /**
30  * Neutron Northbound REST APIs for OpenStack SFC Port Pair.
31  */
32 @Path("/sfc/portpairgroups")
33 public final class NeutronSFCPortPairGroupsNorthbound extends AbstractNeutronNorthbound<NeutronSFCPortPairGroup,
34         NeutronSFCPortPairGroupRequest, INeutronSFCPortPairGroupCRUD> {
35
36     private static final String RESOURCE_NAME = "Sfc Port Pair Group";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all SFC Port Pair Groups.
45      */
46     @GET
47     @Produces({ MediaType.APPLICATION_JSON })
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 listSFCPortPairGroups(
53             // return fields
54             @QueryParam("fields") List<String> fields,
55             @QueryParam("id") String queryID,
56             @QueryParam("name") String queryName,
57             @QueryParam("tenant_id") String queryTenantID,
58             @QueryParam("port_pairs") List<String> queryPortPairsUUID) {
59         INeutronSFCPortPairGroupCRUD sfcPortPairGroupInterface = getNeutronCRUD();
60         List<NeutronSFCPortPairGroup> allSFCPortPairGroup = sfcPortPairGroupInterface.getAll();
61         List<NeutronSFCPortPairGroup> ans = new ArrayList<>();
62         for (NeutronSFCPortPairGroup sfcPortPairGroup : allSFCPortPairGroup) {
63             if ((queryID == null || queryID.equals(sfcPortPairGroup.getID()))
64                     && (queryName == null || queryName.equals(sfcPortPairGroup.getName()))
65                     && (queryTenantID == null || queryTenantID.equals(sfcPortPairGroup.getTenantID()))) {
66                 if (fields.size() > 0) {
67                     ans.add(sfcPortPairGroup.extractFields(fields));
68                 } else {
69                     ans.add(sfcPortPairGroup);
70                 }
71             }
72         }
73
74         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairGroupRequest(ans)).build();
75
76     }
77
78     /**
79      * Returns a specific SFC Port Pair Group.
80      */
81     @Path("{portPairGroupUUID}")
82     @GET
83     @Produces({ MediaType.APPLICATION_JSON })
84     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
85             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
86             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
87             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
88             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
89     public Response showSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
90             // return fields
91             @QueryParam("fields") List<String> fields) {
92         return show(sfcPortPairGroupUUID, fields);
93     }
94
95     /**
96      * Creates new SFC Port Pair Group.
97      */
98     @POST
99     @Produces({ MediaType.APPLICATION_JSON })
100     @Consumes({ MediaType.APPLICATION_JSON })
101     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
102             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
103     public Response createSFCPortPairGroup(final NeutronSFCPortPairGroupRequest input) {
104         return create(input);
105     }
106
107     @Override
108     protected void updateDelta(String uuid, NeutronSFCPortPairGroup delta, NeutronSFCPortPairGroup original) {
109         /*
110          * Note: what we get appears to not be a delta but
111          * rather an incomplete updated object.  So we need to set
112          * the ID to complete the object and then send that down
113          * for folks to check
114          */
115         delta.setID(uuid);
116         delta.setTenantID(original.getTenantID());
117     }
118
119     /**
120      * Updates an existing SFC Port Pair Group.
121      */
122     @Path("{portPairGroupUUID}")
123     @PUT
124     @Produces({ MediaType.APPLICATION_JSON })
125     @Consumes({ MediaType.APPLICATION_JSON })
126     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
127             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
128             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
129     public Response updateSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
130             final NeutronSFCPortPairGroupRequest input) {
131         return update(sfcPortPairGroupUUID, input);
132     }
133
134     /**
135      * Deletes the SFC Port Pair Group.
136      */
137     @Path("{portPairGroupUUID}")
138     @DELETE
139     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
140             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
141             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
142     public Response deleteSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID) {
143         return delete(sfcPortPairGroupUUID);
144     }
145 }