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