This is an automated email from the ASF dual-hosted git repository. cdutz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-plc4x.git
commit 0b770620d4e02c5950229dbfbd08ebda79db72cc Author: Christofer Dutz <christofer.d...@c-ware.de> AuthorDate: Fri May 25 13:56:03 2018 +0200 Fixed some SonarQube findings --- .../iotfactory/IotElasticsearchFactory.java | 31 ++++++++++++++++------ 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java b/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java index 8f70545..a89ea50 100644 --- a/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java +++ b/examples/iot-factory/src/main/java/org/apache/plc4x/java/examples/iotfactory/IotElasticsearchFactory.java @@ -54,6 +54,15 @@ public class IotElasticsearchFactory { RUNNING_RIGHT } + private static class IotElasticsearchFactoryException extends RuntimeException { + private IotElasticsearchFactoryException(String message) { + super(message); + } + private IotElasticsearchFactoryException(String message, Throwable cause) { + super(message, cause); + } + } + private static class MyNode extends Node { private MyNode(Settings preparedSettings, Collection<Class<? extends Plugin>> classpathPlugins) { super(InternalSettingsPreparer.prepareEnvironment(preparedSettings, null), classpathPlugins); @@ -91,7 +100,7 @@ public class IotElasticsearchFactory { " }", XContentType.JSON); CreateIndexResponse createIndexResponse = indicesAdminClient.create(createIndexRequest).actionGet(); if(!createIndexResponse.isAcknowledged()) { - throw new RuntimeException("Could not create index 'iot-factory-data'"); + throw new IotElasticsearchFactoryException("Could not create index 'iot-factory-data'"); } } @@ -113,7 +122,7 @@ public class IotElasticsearchFactory { " }", XContentType.JSON); CreateIndexResponse createIndexResponse = indicesAdminClient.create(createIndexRequest).actionGet(); if(!createIndexResponse.isAcknowledged()) { - throw new RuntimeException("Could not create index 'iot-product-data'"); + throw new IotElasticsearchFactoryException("Could not create index 'iot-product-data'"); } } } @@ -167,7 +176,7 @@ public class IotElasticsearchFactory { boolean conveyorRight = (input & 64) != 0; try { - return XContentFactory.jsonBuilder() + XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .field("time", Calendar.getInstance().getTimeInMillis()) .field("conveyorEntry", conveyorEntry) @@ -178,8 +187,10 @@ public class IotElasticsearchFactory { .field( "conveyorLeft", conveyorLeft) .field( "conveyorRight", conveyorRight) .endObject(); + builder.close(); + return builder; } catch (IOException e) { - throw new RuntimeException("Error building JSON message.", e); + throw new IotElasticsearchFactoryException("Error building JSON message.", e); } } @@ -191,24 +202,28 @@ public class IotElasticsearchFactory { if (transferLeft) { conveyorState = ConveyorState.RUNNING_LEFT; try { - return XContentFactory.jsonBuilder() + XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .field("time", Calendar.getInstance().getTimeInMillis()) .field("type", "small") .endObject(); + builder.close(); + return builder; } catch (IOException e) { - throw new RuntimeException("Error building JSON message.", e); + throw new IotElasticsearchFactoryException("Error building JSON message.", e); } } else if (transferRight){ conveyorState = ConveyorState.RUNNING_RIGHT; try { - return XContentFactory.jsonBuilder() + XContentBuilder builder = XContentFactory.jsonBuilder() .startObject() .field("time", Calendar.getInstance().getTimeInMillis()) .field("type", "large") .endObject(); + builder.close(); + return builder; } catch (IOException e) { - throw new RuntimeException("Error building JSON message.", e); + throw new IotElasticsearchFactoryException("Error building JSON message.", e); } } } else if (!(transferLeft || transferRight)) { -- To stop receiving notification emails like this one, please contact cd...@apache.org.