sort out signature of extraceField method
[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.Iterator;
13 import java.util.List;
14 import javax.ws.rs.Consumes;
15 import javax.ws.rs.DELETE;
16 import javax.ws.rs.GET;
17 import javax.ws.rs.POST;
18 import javax.ws.rs.PUT;
19 import javax.ws.rs.Path;
20 import javax.ws.rs.PathParam;
21 import javax.ws.rs.Produces;
22 import javax.ws.rs.QueryParam;
23 import javax.ws.rs.core.MediaType;
24 import javax.ws.rs.core.Response;
25 import org.codehaus.enunciate.jaxrs.ResponseCode;
26 import org.codehaus.enunciate.jaxrs.StatusCodes;
27 import org.opendaylight.neutron.spi.INeutronSFCPortPairGroupCRUD;
28 import org.opendaylight.neutron.spi.NeutronCRUDInterfaces;
29 import org.opendaylight.neutron.spi.NeutronSFCPortPairGroup;
30
31 /**
32  * Neutron Northbound REST APIs for OpenStack SFC Port Pair.<br>
33  * This class provides REST APIs for managing OpenStack SFC Port Pair
34  *
35  * <br>
36  * <br>
37  * Authentication scheme : <b>HTTP Basic</b><br>
38  * Authentication realm : <b>opendaylight</b><br>
39  * Transport : <b>HTTP and HTTPS</b><br>
40  * <br>
41  * HTTPS Authentication is disabled by default. Administrator can enable it in
42  * tomcat-server.xml after adding a proper keystore / SSL certificate from a
43  * trusted authority.<br>
44  * More info :
45  * http://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html#Configuration
46  *
47  */
48
49 @Path("/sfc/portpairgroups")
50 public class NeutronSFCPortPairGroupsNorthbound extends AbstractNeutronNorthbound<NeutronSFCPortPairGroup,
51         NeutronSFCPortPairGroupRequest, INeutronSFCPortPairGroupCRUD> {
52
53     private static final String RESOURCE_NAME = "Sfc Port Pair Group";
54
55     @Override
56     protected String getResourceName() {
57         return RESOURCE_NAME;
58     }
59
60     @Override
61     protected NeutronSFCPortPairGroupRequest newNeutronRequest(NeutronSFCPortPairGroup o) {
62         return new NeutronSFCPortPairGroupRequest(o);
63     }
64
65     @Override
66     protected INeutronSFCPortPairGroupCRUD getNeutronCRUD() {
67         NeutronCRUDInterfaces answer = new NeutronCRUDInterfaces().fetchINeutronSFCPortPairGroupCRUD(this);
68         if (answer.getSFCPortPairGroupInterface() == null) {
69             throw new ServiceUnavailableException(serviceUnavailable());
70         }
71         return answer.getSFCPortPairGroupInterface();
72     }
73
74     /**
75      * Returns a list of all SFC Port Pair Groups*/
76
77     @GET
78     @Produces({ MediaType.APPLICATION_JSON })
79     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
80             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
81             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
82             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
83     public Response listSFCPortPairGroups(
84             // return fields
85             @QueryParam("fields") List<String> fields,
86             @QueryParam("id") String queryID,
87             @QueryParam("name") String queryName,
88             @QueryParam("tenant_id") String queryTenantID,
89             @QueryParam("port_pairs") List<String> queryPortPairsUUID) {
90         INeutronSFCPortPairGroupCRUD sfcPortPairGroupInterface = getNeutronCRUD();
91         List<NeutronSFCPortPairGroup> allSFCPortPairGroup = sfcPortPairGroupInterface.getAll();
92         List<NeutronSFCPortPairGroup> ans = new ArrayList<>();
93         Iterator<NeutronSFCPortPairGroup> i = allSFCPortPairGroup.iterator();
94         while (i.hasNext()) {
95             NeutronSFCPortPairGroup oSFCPPG = i.next();
96             if ((queryID == null || queryID.equals(oSFCPPG.getID()))
97                     && (queryName == null || queryName.equals(oSFCPPG.getName()))
98                     && (queryTenantID == null || queryTenantID.equals(oSFCPPG.getTenantID()))) {
99                 if (fields.size() > 0) {
100                     ans.add(oSFCPPG.extractFields(fields));
101                 } else {
102                     ans.add(oSFCPPG);
103                 }
104             }
105         }
106
107         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronSFCPortPairGroupRequest(ans)).build();
108
109     }
110
111     /**
112      * Returns a specific SFC Port Pair Group*/
113
114     @Path("{portPairGroupUUID}")
115     @GET
116     @Produces({ MediaType.APPLICATION_JSON })
117     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
118             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
119             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
120             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
121             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
122     public Response showSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
123             // return fields
124             @QueryParam("fields") List<String> fields) {
125         return show(sfcPortPairGroupUUID, fields);
126     }
127
128     /**
129      * Creates new SFC Port Pair Group*/
130     @POST
131     @Produces({ MediaType.APPLICATION_JSON })
132     @Consumes({ MediaType.APPLICATION_JSON })
133     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
134             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
135     public Response createSFCPortPairGroup(final NeutronSFCPortPairGroupRequest input) {
136         return create(input);
137     }
138
139     @Override
140     protected void updateDelta(String uuid, NeutronSFCPortPairGroup delta, NeutronSFCPortPairGroup original) {
141         /*
142          *  note: what we get appears to not be a delta but
143          * rather an incomplete updated object.  So we need to set
144          * the ID to complete the object and then send that down
145          * for folks to check
146          */
147
148         delta.setID(uuid);
149         delta.setTenantID(original.getTenantID());
150     }
151
152     /**
153      * Updates an existing SFC Port Pair Group*/
154     @Path("{portPairGroupUUID}")
155     @PUT
156     @Produces({ MediaType.APPLICATION_JSON })
157     @Consumes({ MediaType.APPLICATION_JSON })
158     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
159             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
160             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
161     public Response updateSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID,
162             final NeutronSFCPortPairGroupRequest input) {
163         return update(sfcPortPairGroupUUID, input);
164     }
165
166     /**
167      * Deletes the SFC Port Pair Group*/
168
169     @Path("{portPairGroupUUID}")
170     @DELETE
171     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_NO_CONTENT, condition = "No Content"),
172             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
173             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
174     public Response deleteSFCPortPairGroup(@PathParam("portPairGroupUUID") String sfcPortPairGroupUUID) {
175         return delete(sfcPortPairGroupUUID);
176     }
177 }