From 445f4bc51c9a635502fcb1cfd68afdb2240af4a7 Mon Sep 17 00:00:00 2001 From: Jim Hahn Date: Wed, 6 Nov 2019 16:38:19 -0500 Subject: Fix new sonar issues in RestManager Eliminated duplicate code issues. Unfortunately, introduced new sonar issues with lambda expressions. Issue-ID: POLICY-2203 Signed-off-by: Jim Hahn Change-Id: Ib5853fab6135d2177da449ef6261a352ee4f203e --- .../policy/drools/server/restful/RestManager.java | 62 +++++++++++----------- 1 file changed, 31 insertions(+), 31 deletions(-) (limited to 'policy-management/src/main/java') diff --git a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java index 7140d293..cd3951d7 100644 --- a/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java +++ b/policy-management/src/main/java/org/onap/policy/drools/server/restful/RestManager.java @@ -593,11 +593,10 @@ public class RestManager { public Response controller(@ApiParam(value = "Policy Controller Name", required = true) @PathParam("controller") String controllerName) { - return catchArgStateGenericEx(() -> { - return Response.status(Response.Status.OK) - .entity(PolicyControllerConstants.getFactory().get(controllerName)).build(); - - }, e -> { + return catchArgStateGenericEx( + () -> Response.status(Response.Status.OK) + .entity(PolicyControllerConstants.getFactory().get(controllerName)).build(), + e -> { logger.debug(FETCH_POLICY_BY_NAME_FAILED, this, controllerName, e.getMessage(), e); return (controllerName); }); @@ -1401,37 +1400,38 @@ public class RestManager { @ApiParam(value = "Fact Type", required = true) @PathParam("factType") String factClass, @ApiParam(value = "JsonPath filter expression", required = true) String rule) { - return catchArgStateGenericEx(() -> { - final DroolsController drools = this.getDroolsController(controllerName); - final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() - .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); + return catchArgStateGenericEx(() -> decoderFilterRule2(controllerName, topic, factClass, rule), e -> { + logger.debug("{}: cannot access decoder filter rules for policy-controller {} " + + "topic {} type {} because of {}", + this, controllerName, topic, factClass, e.getMessage(), e); + return (controllerName + ":" + topic + ":" + factClass); + }); + } - final CoderFilters filters = decoder.getCoder(factClass); - if (filters == null) { - return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); - } + private Object decoderFilterRule2(String controllerName, String topic, String factClass, String rule) { + final DroolsController drools = this.getDroolsController(controllerName); + final ProtocolCoderToolset decoder = EventProtocolCoderConstants.getManager() + .getDecoders(drools.getGroupId(), drools.getArtifactId(), topic); - final JsonProtocolFilter filter = filters.getFilter(); - if (filter == null) { - return Response.status(Response.Status.BAD_REQUEST) - .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build(); - } + final CoderFilters filters = decoder.getCoder(factClass); + if (filters == null) { + return Response.status(Response.Status.BAD_REQUEST) + .entity(new Error(controllerName + ":" + topic + ":" + factClass + DOES_NOT_EXIST_MSG)).build(); + } - if (rule == null || rule.isEmpty()) { - return Response.status(Response.Status.BAD_REQUEST).entity(new Error(controllerName + ":" + topic + ":" - + factClass + " no filter rule provided")).build(); - } + final JsonProtocolFilter filter = filters.getFilter(); + if (filter == null) { + return Response.status(Response.Status.BAD_REQUEST) + .entity(new Error(controllerName + ":" + topic + ":" + factClass + NO_FILTERS)).build(); + } - filter.setRule(rule); - return filter.getRule(); + if (rule == null || rule.isEmpty()) { + return Response.status(Response.Status.BAD_REQUEST).entity(new Error(controllerName + ":" + topic + ":" + + factClass + " no filter rule provided")).build(); + } - }, e -> { - logger.debug("{}: cannot access decoder filter rules for policy-controller {} " - + "topic {} type {} because of {}", - this, controllerName, topic, factClass, e.getMessage(), e); - return (controllerName + ":" + topic + ":" + factClass); - }); + filter.setRule(rule); + return filter.getRule(); } /** -- cgit 1.2.3-korg