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