remove irrelevant old JavaDoc from a long bygone era in northbound.api
[neutron.git] / northbound-api / src / main / java / org / opendaylight / neutron / northbound / api / NeutronFirewallPolicyNorthbound.java
1 /*
2  * Copyright (c) 2014, 2015 Red Hat, 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.INeutronFirewallPolicyCRUD;
27 import org.opendaylight.neutron.spi.NeutronFirewallPolicy;
28
29 /**
30  * Neutron Northbound REST APIs for Firewall Policies.
31  */
32 @Path("/fw/firewall_policies")
33 public final class NeutronFirewallPolicyNorthbound extends
34         AbstractNeutronNorthbound<NeutronFirewallPolicy, NeutronFirewallPolicyRequest, INeutronFirewallPolicyCRUD> {
35
36     private static final String RESOURCE_NAME = "Firewall Policy";
37
38     @Override
39     protected String getResourceName() {
40         return RESOURCE_NAME;
41     }
42
43     /**
44      * Returns a list of all Firewall Policies.
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
53     public Response listGroups(
54             // return fields
55             @QueryParam("fields") List<String> fields,
56             // OpenStack Firewall Policy attributes
57             @QueryParam("id") String queryFirewallPolicyUUID,
58             @QueryParam("tenant_id") String queryFirewallPolicyTenantID,
59             @QueryParam("name") String queryFirewallPolicyName,
60             @QueryParam("shared") Boolean querySecurityPolicyIsShared,
61             @QueryParam("audited") Boolean querySecurityPolicyIsAudited,
62             // pagination
63             @QueryParam("limit") String limit,
64             @QueryParam("marker") String marker,
65             @QueryParam("page_reverse") String pageReverse
66     // sorting not supported
67     ) {
68         INeutronFirewallPolicyCRUD firewallPolicyInterface = getNeutronCRUD();
69         List<NeutronFirewallPolicy> ans = new ArrayList<>();
70         for (NeutronFirewallPolicy nsg : firewallPolicyInterface.getAll()) {
71             if ((queryFirewallPolicyUUID == null || queryFirewallPolicyUUID.equals(nsg.getID()))
72                     && (queryFirewallPolicyTenantID == null || queryFirewallPolicyTenantID.equals(nsg.getTenantID()))
73                     && (queryFirewallPolicyName == null || queryFirewallPolicyName.equals(nsg.getName()))
74                     && (querySecurityPolicyIsShared == null
75                             || querySecurityPolicyIsShared.equals(nsg.getFirewallPolicyIsShared()))
76                     && (querySecurityPolicyIsAudited == null
77                             || querySecurityPolicyIsAudited.equals(nsg.getFirewallPolicyIsAudited()))) {
78                 if (fields.size() > 0) {
79                     ans.add(nsg.extractFields(fields));
80                 } else {
81                     ans.add(nsg);
82                 }
83             }
84         }
85         //TODO: apply pagination to results
86         return Response.status(HttpURLConnection.HTTP_OK).entity(new NeutronFirewallPolicyRequest(ans)).build();
87     }
88
89     /**
90      * Returns a specific Firewall Policy.
91      */
92     @Path("{firewallPolicyUUID}")
93     @GET
94     @Produces({ MediaType.APPLICATION_JSON })
95     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_OK, condition = "Operation successful"),
96             @ResponseCode(code = HttpURLConnection.HTTP_UNAUTHORIZED, condition = "Unauthorized"),
97             @ResponseCode(code = HttpURLConnection.HTTP_NOT_FOUND, condition = "Not Found"),
98             @ResponseCode(code = HttpURLConnection.HTTP_NOT_IMPLEMENTED, condition = "Not Implemented"),
99             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
100     public Response showFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
101             // return fields
102             @QueryParam("fields") List<String> fields) {
103         return show(firewallPolicyUUID, fields);
104     }
105
106     /**
107      * Creates new Firewall Policy.
108      */
109     @POST
110     @Produces({ MediaType.APPLICATION_JSON })
111     @Consumes({ MediaType.APPLICATION_JSON })
112     @StatusCodes({ @ResponseCode(code = HttpURLConnection.HTTP_CREATED, condition = "Created"),
113             @ResponseCode(code = HttpURLConnection.HTTP_UNAVAILABLE, condition = "No providers available") })
114     public Response createFirewallPolicies(final NeutronFirewallPolicyRequest input) {
115         return create(input);
116     }
117
118     /**
119      * Updates a Firewall Policy.
120      */
121     @Path("{firewallPolicyUUID}")
122     @PUT
123     @Produces({ MediaType.APPLICATION_JSON })
124     @Consumes({ MediaType.APPLICATION_JSON })
125     //@TypeHint(OpenStackSubnets.class)
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 updateFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID,
130             final NeutronFirewallPolicyRequest input) {
131         return update(firewallPolicyUUID, input);
132     }
133
134     /**
135      * Deletes a Firewall Policy.
136      */
137     @Path("{firewallPolicyUUID}")
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 deleteFirewallPolicy(@PathParam("firewallPolicyUUID") String firewallPolicyUUID) {
143         return delete(firewallPolicyUUID);
144     }
145 }