X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fnorthbound%2Fflowprogrammer%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fflowprogrammer%2Fnorthbound%2FFlowProgrammerNorthbound.java;h=42bd59ea4577ff5c6d40b3ad4e8efaa976c900f5;hb=refs%2Fchanges%2F10%2F7610%2F5;hp=4928ddef3b0296b8525531791dfe4272064dfaa1;hpb=5b16b5aa030d26cbf2c6dc17b3f7a530fbdb987f;p=controller.git diff --git a/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java b/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java index 4928ddef3b..42bd59ea45 100644 --- a/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java +++ b/opendaylight/northbound/flowprogrammer/src/main/java/org/opendaylight/controller/flowprogrammer/northbound/FlowProgrammerNorthbound.java @@ -19,10 +19,12 @@ import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import javax.ws.rs.core.SecurityContext; +import javax.ws.rs.ext.ContextResolver; import org.codehaus.enunciate.jaxrs.ResponseCode; import org.codehaus.enunciate.jaxrs.StatusCodes; @@ -37,6 +39,7 @@ import org.opendaylight.controller.northbound.commons.exception.NotAcceptableExc import org.opendaylight.controller.northbound.commons.exception.ResourceNotFoundException; import org.opendaylight.controller.northbound.commons.exception.ServiceUnavailableException; import org.opendaylight.controller.northbound.commons.exception.UnauthorizedException; +import org.opendaylight.controller.northbound.commons.query.QueryContext; import org.opendaylight.controller.northbound.commons.utils.NorthboundUtils; import org.opendaylight.controller.sal.authorization.Privilege; import org.opendaylight.controller.sal.core.Node; @@ -62,6 +65,14 @@ public class FlowProgrammerNorthbound { private String username; + private QueryContext queryContext; + @Context + public void setQueryContext(ContextResolver queryCtxResolver) { + if (queryCtxResolver != null) { + queryContext = queryCtxResolver.getContext(QueryContext.class); + } + } + @Context public void setSecurityContext(SecurityContext context) { if (context != null && context.getUserPrincipal() != null) { @@ -194,15 +205,21 @@ public class FlowProgrammerNorthbound { @StatusCodes({ @ResponseCode(code = 200, condition = "Operation successful"), @ResponseCode(code = 401, condition = "User not authorized to perform this operation"), @ResponseCode(code = 404, condition = "The containerName is not found"), - @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) - public FlowConfigs getStaticFlows(@PathParam("containerName") String containerName) { + @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable"), + @ResponseCode(code = 400, condition = "Incorrect query syntex")}) + public FlowConfigs getStaticFlows(@PathParam("containerName") String containerName, + @QueryParam("_q") String queryString) { if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) { throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName); } - List flowConfigs = getStaticFlowsInternal(containerName, null); - return new FlowConfigs(flowConfigs); + FlowConfigs result = new FlowConfigs(getStaticFlowsInternal(containerName, null)); + if (queryString != null) { + queryContext.createQuery(queryString, FlowConfigs.class) + .filter(result, FlowConfig.class); + } + return result; } /** @@ -272,7 +289,8 @@ public class FlowProgrammerNorthbound { @ResponseCode(code = 404, condition = "The containerName or nodeId is not found"), @ResponseCode(code = 503, condition = "One or more of Controller Services are unavailable") }) public FlowConfigs getStaticFlows(@PathParam("containerName") String containerName, - @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId) { + @PathParam("nodeType") String nodeType, @PathParam("nodeId") String nodeId, + @QueryParam("_q") String queryString) { if (!NorthboundUtils.isAuthorized(getUserName(), containerName, Privilege.READ, this)) { throw new UnauthorizedException("User is not authorized to perform this operation on container " + containerName); @@ -281,8 +299,12 @@ public class FlowProgrammerNorthbound { if (node == null) { throw new ResourceNotFoundException(nodeId + " : " + RestMessages.NONODE.toString()); } - List flows = getStaticFlowsInternal(containerName, node); - return new FlowConfigs(flows); + FlowConfigs flows = new FlowConfigs(getStaticFlowsInternal(containerName, node)); + if (queryString != null) { + queryContext.createQuery(queryString, FlowConfigs.class) + .filter(flows, FlowConfig.class); + } + return flows; } /**