From ab5bbf77b1e6c67b3e929e06a04446adcda4199c Mon Sep 17 00:00:00 2001 From: Douglas Date: Wed, 13 Nov 2019 14:34:20 -0300 Subject: [PATCH 1/6] KRMVP-1165 - [DATA] Set up data channel as default when channel is empty --- .../integration/endpoints/GatewayEventRestEndpoint.java | 4 ---- .../integration/processors/GatewayEventProcessor.java | 9 ++++++++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/GatewayEventRestEndpoint.java b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/GatewayEventRestEndpoint.java index 2c21c5914..ff3ba6464 100644 --- a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/GatewayEventRestEndpoint.java +++ b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/GatewayEventRestEndpoint.java @@ -175,10 +175,6 @@ public ResponseEntity onDataEvent(HttpServletRequest servletReque return new ResponseEntity(buildResponse(Messages.INVALID_HEADER_DEVICE_ID_FIELD.getCode(),locale), HttpStatus.BAD_REQUEST); } - if (deviceChannelFieldName == null) { - return new ResponseEntity(buildResponse(Messages.INVALID_HEADER_DEVICE_CHANNEL_FIELD.getCode(),locale), HttpStatus.BAD_REQUEST); - } - ResponseEntity exchange = getHealthCheckRabbit(); if (exchange.getStatusCode().equals(HttpStatus.OK)) { diff --git a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/processors/GatewayEventProcessor.java b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/processors/GatewayEventProcessor.java index f5f3c796b..b493bdf15 100644 --- a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/processors/GatewayEventProcessor.java +++ b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/processors/GatewayEventProcessor.java @@ -152,9 +152,16 @@ public void process(Gateway gateway, String payloadList, String deviceIdFieldNam Instant ingestedTimestamp = Instant.now(); + String channel = null; + if (Optional.ofNullable(deviceChannelFieldName).isPresent()) { + channel = payloadDevice.get(deviceChannelFieldName).toString(); + } else { + channel = "data"; + } + byte[] payloadBytes = converterHelper.getJsonPayload(device, jsonParsingService.toJsonString(payloadDevice)).getResult(); rabbitGateway.queueEventDataPub(device.getApiKey(), - payloadDevice.get(deviceChannelFieldName).toString(), + channel, ingestedTimestamp.toEpochMilli(), payloadBytes); } else { From f00fa708a10acf539e89966b03694baadb68a787 Mon Sep 17 00:00:00 2001 From: Douglas Date: Wed, 13 Nov 2019 17:47:27 -0300 Subject: [PATCH 2/6] KRMVP-1190 - Create cassandra script to add new fields in table and create new tables --- .../scripts/V5__add_new_incoming_tables.cql | 73 +++++++++++++++++++ .../scripts/V6__add_new_outgoing_tables.cql | 73 +++++++++++++++++++ 2 files changed, 146 insertions(+) create mode 100644 konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql create mode 100644 konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql diff --git a/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql b/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql new file mode 100644 index 000000000..cbe7a4aa9 --- /dev/null +++ b/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql @@ -0,0 +1,73 @@ +CREATE TABLE incoming_events_location_guid ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE incoming_events_location_guid_device_guid ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, device_guid), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE incoming_events_location_guid_channel ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, channel), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE incoming_events_location_guid_device_guid_channel ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, device_guid, channel), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +ALTER TABLE incoming_events ADD location_guid text; +ALTER TABLE incoming_events_deleted ADD location_guid text; +ALTER TABLE incoming_events_device_guid ADD location_guid text; +ALTER TABLE incoming_events_device_guid_channel ADD location_guid text; +ALTER TABLE incoming_events_channel ADD location_guid text; \ No newline at end of file diff --git a/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql b/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql new file mode 100644 index 000000000..1c3a9d701 --- /dev/null +++ b/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql @@ -0,0 +1,73 @@ +CREATE TABLE outgoing_events_location_guid ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE outgoing_events_location_guid_device_guid ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, device_guid), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE outgoing_events_location_guid_channel ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, channel), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +CREATE TABLE outgoing_events_location_guid_device_guid_channel ( + tenant_domain text, + application_name text, + timestamp bigint, + channel text, + device_guid text, + device_id text, + payload text, + location_guid text, + geo_lat double, + geo_lon double, + geo_hdop bigint, + geo_elev double, + ingested_timestamp bigint, + PRIMARY KEY ((tenant_domain, application_name, location_guid, device_guid, channel), timestamp) +) WITH CLUSTERING ORDER BY (timestamp DESC); + +ALTER TABLE outgoing_events ADD location_guid text; +ALTER TABLE outgoing_events_deleted ADD location_guid text; +ALTER TABLE outgoing_events_device_guid ADD location_guid text; +ALTER TABLE outgoing_events_device_guid_channel ADD location_guid text; +ALTER TABLE outgoing_events_channel ADD location_guid text; \ No newline at end of file From 1d460e740f3886ef6f636ab9c754eb83072a9e46 Mon Sep 17 00:00:00 2001 From: Douglas Date: Thu, 14 Nov 2019 10:58:20 -0300 Subject: [PATCH 3/6] KRMVP-1191 - Expose location guid in api --- .../konkerlabs/platform/registry/api/model/LocationVO.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/LocationVO.java b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/LocationVO.java index f8c1d2422..ca8e3edb8 100644 --- a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/LocationVO.java +++ b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/LocationVO.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.List; +import io.swagger.annotations.ApiModelProperty; import org.apache.commons.lang3.StringUtils; import com.fasterxml.jackson.annotation.JsonInclude; @@ -22,12 +23,16 @@ @ApiModel(value = "Location", discriminator = "com.konkerlabs.platform.registry.api.model") public class LocationVO extends LocationInputVO implements SerializableVO { + @ApiModelProperty(value = "the location guid", position = 6, example = "818599ad-3502-4e70-a852-fc7af8e0a9f3") + protected String guid; + public LocationVO(Location location) { this.parentName = getParentName(location.getParent()); this.name = location.getName(); this.description = location.getDescription(); this.defaultLocation = location.isDefaultLocation(); this.sublocations = getSublocations(location.getChildren()); + this.guid = location.getGuid(); } @Override @@ -43,6 +48,7 @@ public Location patchDB(Location model) { model.setName(this.getName()); model.setDescription(this.getDescription()); model.setDefaultLocation(this.isDefaultLocation()); + model.setGuid(this.getGuid()); return model; } From 1e689e49e51d248ee97a6f0023ec65b404d3e257 Mon Sep 17 00:00:00 2001 From: Douglas Date: Mon, 18 Nov 2019 13:56:39 -0300 Subject: [PATCH 4/6] KRMVP-1189 - Change service layer mongodb --- .../registry/api/model/EventsFilter.java | 4 + .../DeviceStatusRestController.java | 2 +- .../IncomingEventsRestController.java | 9 +- .../OutgoingEventsRestController.java | 3 +- .../controller/DeviceRestControllerTest.java | 4 +- .../IncomingEventsRestControllerTest.java | 43 ++++++++- .../OutgoingEventsRestControllerTest.java | 44 ++++++++- .../EventsCassandraToMongoService.java | 4 +- .../EventsMongoToCassandraService.java | 8 +- .../processors/DeviceEventProcessor.java | 1 + .../data/core/services/JedisTaskService.java | 4 +- .../publishers/EventPublisherDevice.java | 1 + .../processors/DeviceEventProcessorTest.java | 2 + .../services/DeviceLogEventServiceTest.java | 10 +- .../publishers/EventPublisherDeviceTest.java | 2 +- .../src/test/resources/fixtures/devices.json | 4 + .../test/resources/fixtures/locations.json | 96 +++++++++++++++++++ .../endpoints/DeviceEventRestEndpoint.java | 2 +- .../registry/business/model/Event.java | 1 + .../events/api/BaseEventRepositoryImpl.java | 32 ++++--- .../events/api/EventRepository.java | 2 + .../services/DeviceEventServiceImpl.java | 17 ++-- .../services/EventSchemaServiceImpl.java | 8 +- .../services/HealthAlertServiceImpl.java | 2 +- .../services/api/DeviceEventService.java | 8 ++ .../EventRepositoryTestConfiguration.java | 2 +- .../services/HealthAlertServiceTest.java | 4 +- .../events/EventRepositoryCassandraImpl.java | 3 +- .../events/EventRepositoryMongoImpl.java | 24 +++-- .../EventRepositoryMongoTest.java | 51 +++++----- .../test/services/DeviceEventServiceTest.java | 72 +++++++------- .../services/DeviceRegisterServiceTest.java | 4 +- .../web/controllers/DeviceController.java | 8 +- .../DeviceVisualizationController.java | 8 +- .../web/controllers/DeviceControllerTest.java | 36 +++++-- .../DeviceVisualizationControllerTest.java | 4 +- 36 files changed, 374 insertions(+), 155 deletions(-) create mode 100644 konker.registry.data.core/src/test/resources/fixtures/locations.json diff --git a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/EventsFilter.java b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/EventsFilter.java index 9a8ac533c..2dcbce2fc 100644 --- a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/EventsFilter.java +++ b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/model/EventsFilter.java @@ -25,6 +25,7 @@ public class EventsFilter { private final Logger LOGGER = LoggerFactory.getLogger(this.getClass()); private String deviceGuid; + private String locationGuid; private String channel; private Instant startingTimestamp; private Instant endTimestamp; @@ -32,6 +33,7 @@ public class EventsFilter { public void parse(String query) throws BadRequestResponseException { this.deviceGuid = null; + this.locationGuid = null; this.channel = null; this.startingTimestamp = null; this.endTimestamp = null; @@ -58,6 +60,8 @@ private void parseToken(String filter) throws BadRequestResponseException { if (tokens[0].equalsIgnoreCase("device")) { this.deviceGuid = tokens[1]; + } else if (tokens[0].equalsIgnoreCase("location")) { + this.locationGuid = tokens[1]; } else if (tokens[0].equalsIgnoreCase("channel")) { this.channel = tokens[1]; } else if (tokens[0].equalsIgnoreCase("timestamp")) { diff --git a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/DeviceStatusRestController.java b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/DeviceStatusRestController.java index a82e10414..6f1fa4ef0 100644 --- a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/DeviceStatusRestController.java +++ b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/DeviceStatusRestController.java @@ -121,7 +121,7 @@ public DeviceStatsVO stats( Application application = getApplication(applicationId); ServiceResponse deviceResponse = deviceRegisterService.getByDeviceGuid(tenant, application, deviceGuid); - ServiceResponse> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, false, 1); + ServiceResponse> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, null, false, 1); if (!deviceResponse.isOk()) { throw new NotFoundResponseException(deviceResponse); diff --git a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/IncomingEventsRestController.java b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/IncomingEventsRestController.java index 8177eef45..761de6859 100644 --- a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/IncomingEventsRestController.java +++ b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/IncomingEventsRestController.java @@ -41,6 +41,7 @@ public class IncomingEventsRestController extends AbstractRestController impleme public static final String SEARCH_NOTES = "### Query Search Terms\n\n" + "* `device`\n\n" + + "* `location`\n\n" + "* `channel`\n\n" + "* `timestamp`: ISO 8601 format\n\n" + "\n\n" + @@ -50,8 +51,9 @@ public class IncomingEventsRestController extends AbstractRestController impleme "\n\n" + "### Query Examples\n\n" + "* device:818599ad-0000-0000-0000-000000000000\n\n" + - "* channel:temperature device:818599ad-0000-0000-0000-000000000000\n\n" + + "* channel:temperature device:818599ad-0000-0000-0000-000000000000 location:818599ad-0000-0000-0000-000000000011\n\n" + "* channel:temperature\n\n" + + "* location:818599ad-0000-0000-0000-000000000011\n\n" + "* timestamp:>2017-04-05T14:50:00+01:00\n\n" + "* timestamp:<2017-04-05T14:55:00-01:00\n\n" + "* timestamp:>2017-04-05T13:54:30.891Z timestamp:<2017-04-05T13:56:30.891Z\n\n"; @@ -92,6 +94,7 @@ public List list( EventsFilter filter = new EventsFilter(); filter.parse(query); String deviceGuid = filter.getDeviceGuid(); + String locationGuid = filter.getLocationGuid(); String channel = filter.getChannel(); Instant startingTimestamp = filter.getStartingTimestamp(); Instant endTimestamp = filter.getEndTimestamp(); @@ -101,11 +104,11 @@ public List list( application, loggedUser, deviceGuid, + locationGuid, channel, startingTimestamp, endTimestamp, - ascending, - limit); + ascending, limit); if (!restDestinationResponse.isOk()) { throw new BadServiceResponseException( restDestinationResponse, validationsCode); diff --git a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/OutgoingEventsRestController.java b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/OutgoingEventsRestController.java index b3e04b10b..9cb050e18 100644 --- a/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/OutgoingEventsRestController.java +++ b/konker.registry.api/src/main/java/com/konkerlabs/platform/registry/api/web/controller/OutgoingEventsRestController.java @@ -76,11 +76,12 @@ public List list( EventsFilter filter = new EventsFilter(); filter.parse(query); String deviceGuid = filter.getDeviceGuid(); + String locationGuid = filter.getLocationGuid(); String channel = filter.getChannel(); Instant startingTimestamp = filter.getStartingTimestamp(); Instant endTimestamp = filter.getEndTimestamp(); - ServiceResponse> restDestinationResponse = deviceEventService.findOutgoingBy(tenant, application, user.getParentUser(), deviceGuid, channel, startingTimestamp, endTimestamp, ascending, limit); + ServiceResponse> restDestinationResponse = deviceEventService.findOutgoingBy(tenant, application, user.getParentUser(), deviceGuid, locationGuid, channel, startingTimestamp, endTimestamp, ascending, limit); if (!restDestinationResponse.isOk()) { throw new BadServiceResponseException( restDestinationResponse, validationsCode); diff --git a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/DeviceRestControllerTest.java b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/DeviceRestControllerTest.java index b8472be34..f8f4afd52 100644 --- a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/DeviceRestControllerTest.java +++ b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/DeviceRestControllerTest.java @@ -659,7 +659,7 @@ public void shouldShowDeviceStats() throws Exception { when(applicationService.getByApplicationName(tenant, application.getName())) .thenReturn(ServiceResponseBuilder.ok().withResult(application).build()); - when(deviceEventService.findIncomingBy(tenant, application, device1.getGuid(), null, null, null, false, 1)) + when(deviceEventService.findIncomingBy(tenant, application, device1.getGuid(), null, null, null, null, false, 1)) .thenReturn(ServiceResponseBuilder.>ok().withResult(events).build()); getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/{2}/stats", application.getName(), BASEPATH, device1.getGuid())) @@ -705,7 +705,7 @@ public void shouldTryShowDeviceStatWithBadRequest() throws Exception { when(applicationService.getByApplicationName(tenant, application.getName())) .thenReturn(ServiceResponseBuilder.ok().withResult(application).build()); - when(deviceEventService.findIncomingBy(tenant, application, device1.getGuid(), null, null, null, false, 1)) + when(deviceEventService.findIncomingBy(tenant, application, device1.getGuid(), null, null, null, null, false, 1)) .thenReturn(ServiceResponseBuilder.>ok().withResult(events).build()); getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/{2}/stats", application.getName(), BASEPATH, device1.getGuid())) diff --git a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/IncomingEventsRestControllerTest.java b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/IncomingEventsRestControllerTest.java index d1a554333..644dd5bfe 100644 --- a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/IncomingEventsRestControllerTest.java +++ b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/IncomingEventsRestControllerTest.java @@ -115,7 +115,16 @@ public void shouldListEventsNoParam() throws Exception { incomingEvents.add(event1); incomingEvents.add(event2); - when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(100))) + when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(incomingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -145,7 +154,15 @@ public void shouldListEventsWithQuery() throws Exception { incomingEvents.add(event1); incomingEvents.add(event2); - when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.eq("0000"), org.mockito.Matchers.eq("temp"), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(100))) + when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), + org.mockito.Matchers.eq("0000"), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.eq("temp"), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(incomingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -176,7 +193,16 @@ public void shouldListEventsSortOldest() throws Exception { incomingEvents.add(event1); incomingEvents.add(event2); - when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(true), org.mockito.Matchers.eq(100))) + when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(true), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(incomingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -207,7 +233,16 @@ public void shouldListEventsWithLimit() throws Exception { incomingEvents.add(event1); incomingEvents.add(event2); - when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(500))) + when(deviceEventService.findIncomingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(500))) .thenReturn(ServiceResponseBuilder.>ok().withResult(incomingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) diff --git a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/OutgoingEventsRestControllerTest.java b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/OutgoingEventsRestControllerTest.java index 50a96efad..d6e755d17 100644 --- a/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/OutgoingEventsRestControllerTest.java +++ b/konker.registry.api/src/test/java/com/konkerlabs/platform/registry/api/test/web/controller/OutgoingEventsRestControllerTest.java @@ -115,7 +115,16 @@ public void shouldListEventsNoParam() throws Exception { outgoingEvents.add(event1); outgoingEvents.add(event2); - when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(100))) + when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(outgoingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -145,7 +154,16 @@ public void shouldListEventsWithQuery() throws Exception { outgoingEvents.add(event1); outgoingEvents.add(event2); - when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.eq("0000"), org.mockito.Matchers.eq("temp"), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(100))) + when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.eq("0000"), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.eq("temp"), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(outgoingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -176,7 +194,16 @@ public void shouldListEventsSortOldest() throws Exception { outgoingEvents.add(event1); outgoingEvents.add(event2); - when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(true), org.mockito.Matchers.eq(100))) + when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(true), + org.mockito.Matchers.eq(100))) .thenReturn(ServiceResponseBuilder.>ok().withResult(outgoingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) @@ -207,7 +234,16 @@ public void shouldListEventsWithLimit() throws Exception { outgoingEvents.add(event1); outgoingEvents.add(event2); - when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), org.mockito.Matchers.any(Application.class), org.mockito.Matchers.any(User.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(String.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.isNull(Instant.class), org.mockito.Matchers.eq(false), org.mockito.Matchers.eq(500))) + when(deviceEventService.findOutgoingBy(org.mockito.Matchers.any(Tenant.class), + org.mockito.Matchers.any(Application.class), + org.mockito.Matchers.any(User.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(String.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.isNull(Instant.class), + org.mockito.Matchers.eq(false), + org.mockito.Matchers.eq(500))) .thenReturn(ServiceResponseBuilder.>ok().withResult(outgoingEvents).build()); when(applicationService.getByApplicationName(tenant, application.getName())) diff --git a/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsCassandraToMongoService.java b/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsCassandraToMongoService.java index cf74229c9..872851140 100644 --- a/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsCassandraToMongoService.java +++ b/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsCassandraToMongoService.java @@ -74,7 +74,7 @@ private void process(Tenant tenant, Application application, Instant startInstan LOGGER.info("Tenant {} Application {}", tenant.getName(), application.getName()); - List incomingEvents = cassandraEventsRepository.findIncomingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit); + List incomingEvents = cassandraEventsRepository.findIncomingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit); LOGGER.info("\tIncoming events: {}", incomingEvents.size()); for (Event event : incomingEvents) { @@ -85,7 +85,7 @@ private void process(Tenant tenant, Application application, Instant startInstan LOGGER.info("\tCompleted!"); } - List outgoingEvents = cassandraEventsRepository.findOutgoingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit); + List outgoingEvents = cassandraEventsRepository.findOutgoingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit); LOGGER.info("\tOutgoing events: {}", outgoingEvents.size()); for (Event event : outgoingEvents) { diff --git a/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsMongoToCassandraService.java b/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsMongoToCassandraService.java index 2ba59921e..d460cab9d 100644 --- a/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsMongoToCassandraService.java +++ b/konker.registry.cassandra-etl/src/main/java/org/konker/registry/cassandraetl/services/EventsMongoToCassandraService.java @@ -74,7 +74,7 @@ private void process(Tenant tenant, Application application, Instant startInstan LOGGER.info("Tenant {} Application {}", tenant.getName(), application.getName()); - List incomingEvents = mongoEventsRepository.findIncomingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit); + List incomingEvents = mongoEventsRepository.findIncomingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit); int count = 0; while (!incomingEvents.isEmpty()) { @@ -84,11 +84,11 @@ private void process(Tenant tenant, Application application, Instant startInstan cassandraEventsRepository.saveIncoming(tenant, application, event); } Event lastEvent = incomingEvents.get(incomingEvents.size() - 1); - incomingEvents = mongoEventsRepository.findIncomingBy(tenant, application, deviceGuid, channel, lastEvent.getCreationTimestamp(), endInstant, ascending, limit); + incomingEvents = mongoEventsRepository.findIncomingBy(tenant, application, deviceGuid, null, channel, lastEvent.getCreationTimestamp(), endInstant, ascending, limit); } LOGGER.info("\tTotal Incoming: {}", count); - List outgoingEvents = mongoEventsRepository.findOutgoingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit); + List outgoingEvents = mongoEventsRepository.findOutgoingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit); count = 0; while (!outgoingEvents.isEmpty()) { @@ -98,7 +98,7 @@ private void process(Tenant tenant, Application application, Instant startInstan cassandraEventsRepository.saveOutgoing(tenant, application, event); } Event lastEvent = outgoingEvents.get(outgoingEvents.size() - 1); - outgoingEvents = mongoEventsRepository.findOutgoingBy(tenant, application, deviceGuid, channel, lastEvent.getCreationTimestamp(), endInstant, ascending, limit); + outgoingEvents = mongoEventsRepository.findOutgoingBy(tenant, application, deviceGuid, null, channel, lastEvent.getCreationTimestamp(), endInstant, ascending, limit); } LOGGER.info("\tTotal Outgoing: {}", count); diff --git a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/integration/processors/DeviceEventProcessor.java b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/integration/processors/DeviceEventProcessor.java index 69ccc4237..f9c832421 100644 --- a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/integration/processors/DeviceEventProcessor.java +++ b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/integration/processors/DeviceEventProcessor.java @@ -137,6 +137,7 @@ public void process(Device device, String channel, String jsonPayload, Instant i ? device.getTenant().getDomainName() : null) .applicationName(Optional.ofNullable(device.getApplication()).isPresent() ? device.getApplication().getName(): null) + .locationGuid(device.getLocation().getGuid()) .build() ) .creationTimestamp(creationTimestamp) diff --git a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/JedisTaskService.java b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/JedisTaskService.java index d8caab812..fbd271e28 100644 --- a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/JedisTaskService.java +++ b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/JedisTaskService.java @@ -49,8 +49,8 @@ public void onMessage(String channel, String message) { String deviceChannel = channel.contains(".") ? channel.substring(channel.indexOf('.') + 1) : null; Device device = deviceRegisterService.findByApiKey(deviceApiKey); - response = deviceEventService.findOutgoingBy(device.getTenant(), device.getApplication(), device.getGuid(), - deviceChannel, startTimestamp, null, asc, limit); + response = deviceEventService.findOutgoingBy(device.getTenant(), device.getApplication(), device.getGuid(), null, + deviceChannel, startTimestamp, null, asc, limit); this.unsubscribe(channel); } }; diff --git a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/publishers/EventPublisherDevice.java b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/publishers/EventPublisherDevice.java index 5ee1b4726..375405b02 100644 --- a/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/publishers/EventPublisherDevice.java +++ b/konker.registry.data.core/src/main/java/com/konkerlabs/platform/registry/data/core/services/publishers/EventPublisherDevice.java @@ -100,6 +100,7 @@ public void sendMessage(Event outgoingEvent, Map data, Device ou .tenantDomain(outgoingDevice.getTenant().getDomainName()) .applicationName(outgoingDevice.getApplication().getName()) .deviceId(outgoingDevice.getDeviceId()) + .locationGuid(outgoingDevice.getLocation().getGuid()) .build() ); diff --git a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/integration/processors/DeviceEventProcessorTest.java b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/integration/processors/DeviceEventProcessorTest.java index 5534911e2..bc22797ef 100644 --- a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/integration/processors/DeviceEventProcessorTest.java +++ b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/integration/processors/DeviceEventProcessorTest.java @@ -102,6 +102,7 @@ public void setUp() { .deviceId("device_id") .tenantDomain("tenantDomain") .applicationName("applicationName") + .locationGuid("84399b2e-d99e-11e5-86bc-34238775abcd") .build() ) @@ -121,6 +122,7 @@ public void setUp() { .friendlyName("applicationName") .build() ) + .location(Location.builder().guid("84399b2e-d99e-11e5-86bc-34238775abcd").build()) .apiKey(sourceApiKey) .id("id") .guid("device_guid") diff --git a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/DeviceLogEventServiceTest.java b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/DeviceLogEventServiceTest.java index f95db47de..118428a2c 100644 --- a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/DeviceLogEventServiceTest.java +++ b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/DeviceLogEventServiceTest.java @@ -227,7 +227,7 @@ public void shouldLogFirstDeviceEvent() throws Exception { deviceEventService.logIncomingEvent(device, event); - Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(),channel,event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); + Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(), null, channel, event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); assertThat(last, notNullValue()); @@ -243,7 +243,7 @@ public void shouldLogDeviceEventWithInvalidLatLon() throws Exception { doNothing().when(jedisTaskService).registerLastEventTimestamp(event); deviceEventService.logIncomingEvent(device, event); - Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(),channel,event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); + Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(), null, channel, event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); assertThat(last, notNullValue()); assertThat(last.getGeolocation(), nullValue()); @@ -259,7 +259,7 @@ public void shouldLogDeviceEventWithInvalidHdop() throws Exception { doNothing().when(jedisTaskService).registerLastEventTimestamp(event); deviceEventService.logIncomingEvent(device, event); - Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(),channel,event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); + Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(), null, channel, event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); assertThat(last, notNullValue()); assertThat(last.getGeolocation().getHdop(), nullValue()); @@ -275,7 +275,7 @@ public void shouldLogDeviceEventWithInvalidElev() throws Exception { doNothing().when(jedisTaskService).registerLastEventTimestamp(event); deviceEventService.logIncomingEvent(device, event); - Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(),channel,event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); + Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(), null, channel, event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); assertThat(last, notNullValue()); assertThat(last.getGeolocation().getElev(), nullValue()); @@ -291,7 +291,7 @@ public void shouldLogDeviceEventWithValidGeo() throws Exception { doNothing().when(jedisTaskService).registerLastEventTimestamp(event); deviceEventService.logIncomingEvent(device, event); - Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(),channel,event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); + Event last = eventRepository.findIncomingBy(tenant,application,device.getGuid(), null, channel, event.getCreationTimestamp().minusSeconds(1L), null, false, 1).get(0); assertThat(last, notNullValue()); assertThat(last.getGeolocation(), notNullValue()); diff --git a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/publishers/EventPublisherDeviceTest.java b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/publishers/EventPublisherDeviceTest.java index 8bfe8327b..0bd4ce528 100644 --- a/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/publishers/EventPublisherDeviceTest.java +++ b/konker.registry.data.core/src/test/java/com/konkerlabs/platform/registry/test/data/core/services/publishers/EventPublisherDeviceTest.java @@ -66,7 +66,7 @@ EmailConfig.class, EventPublisherDeviceTest.EventPublisherDeviceTestConfig.class }) -@UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json", "/fixtures/applications.json"}) +@UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json", "/fixtures/applications.json", "/fixtures/locations.json"}) public class EventPublisherDeviceTest extends BusinessLayerTestSupport{ private static final String THE_DEVICE_GUID = "7d51c242-81db-11e6-a8c2-0746f010e945"; diff --git a/konker.registry.data.core/src/test/resources/fixtures/devices.json b/konker.registry.data.core/src/test/resources/fixtures/devices.json index 4da4fb9b3..54e566c6e 100644 --- a/konker.registry.data.core/src/test/resources/fixtures/devices.json +++ b/konker.registry.data.core/src/test/resources/fixtures/devices.json @@ -50,6 +50,10 @@ "$id" : "smartffkonker", "$ref" : "applications" }, + "location" : { + "$id" : "j854dz2dayzm8dgna678", + "$ref" : "locations" + }, "deviceId" : "SN1234567890", "apiKey" : "e4399b2ed998", "name" : "Test name", diff --git a/konker.registry.data.core/src/test/resources/fixtures/locations.json b/konker.registry.data.core/src/test/resources/fixtures/locations.json new file mode 100644 index 000000000..5f6d02455 --- /dev/null +++ b/konker.registry.data.core/src/test/resources/fixtures/locations.json @@ -0,0 +1,96 @@ +{ + "locations": [ + { + "_id" : "591200ea9061e67cb2228f85", + "_class" : "com.konkerlabs.platform.registry.business.model.Location", + "name" : "br", + "description" : "Brazil", + "guid" : "d75758a6-235b-413b-85b3-d218404f8c11", + "defaultLocation" : false, + "tenant" : { + "$id" : "71fb0d48-674b-4f64-a3e5-0256ff3a63af", + "$ref" : "tenants" + }, + "application" : { + "$id" : "konker", + "$ref" : "applications" + } + }, + { + "_id" : "vmes6ye0k5dqouz0m0fm", + "_class" : "com.konkerlabs.platform.registry.business.model.Location", + "name" : "sp", + "description" : "São Paulo", + "guid" : "55fe5b24-be8a-4d33-8cdf-fd08c14175b4", + "defaultLocation" : true, + "tenant" : { + "$id" : "71fb0d48-674b-4f64-a3e5-0256ff3a63af", + "$ref" : "tenants" + }, + "application" : { + "$id" : "konker", + "$ref" : "applications" + }, + "parent" : { + "$id" : "591200ea9061e67cb2228f85", + "$ref" : "locations" + } + }, + { + "_id" : "bz048xdft8s5ii28o5vh", + "_class" : "com.konkerlabs.platform.registry.business.model.Location", + "name" : "rj", + "description" : "Rio Janeiro", + "guid" : "8f07f5e4-b411-45d4-90b5-a5228f7e0361", + "defaultLocation" : false, + "tenant" : { + "$id" : "71fb0d48-674b-4f64-a3e5-0256ff3a63af", + "$ref" : "tenants" + }, + "application" : { + "$id" : "konker", + "$ref" : "applications" + }, + "parent" : { + "$id" : "591200ea9061e67cb2228f85", + "$ref" : "locations" + } + }, + { + "_id" : "j854dz2dayzm8dgna3kb", + "_class" : "com.konkerlabs.platform.registry.business.model.Location", + "name" : "sala-101", + "description" : "Sala 101", + "guid" : "a14e671f-32d7-4ec0-8006-8d93eeed401c", + "defaultLocation" : false, + "tenant" : { + "$id" : "71fb0d48-674b-4f64-a3e5-0256ff3a63af", + "$ref" : "tenants" + }, + "application" : { + "$id" : "konker", + "$ref" : "applications" + }, + "parent" : { + "$id" : "bz048xdft8s5ii28o5vh", + "$ref" : "locations" + } + }, + { + "_id" : "j854dz2dayzm8dgna678", + "_class" : "com.konkerlabs.platform.registry.business.model.Location", + "name" : "sala-911", + "description" : "Sala 911", + "guid" : "a14e671f-32d7-4ec0-8006-8d93eeed404f", + "defaultLocation" : false, + "tenant" : { + "$id" : "71fb0d48-674b-4f64-a3e5-0256ff3a63af", + "$ref" : "tenants" + }, + "application" : { + "$id" : "smartffkonker", + "$ref" : "applications" + } + } + ] +} \ No newline at end of file diff --git a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/DeviceEventRestEndpoint.java b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/DeviceEventRestEndpoint.java index 42843fa8b..35de5daa0 100644 --- a/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/DeviceEventRestEndpoint.java +++ b/konker.registry.data/src/main/java/com/konkerlabs/platform/registry/integration/endpoints/DeviceEventRestEndpoint.java @@ -156,7 +156,7 @@ public DeferredResult> subEvent(HttpServletRequest servletRequest, Integer limit = offset.isPresent() ? 50 : 1; ServiceResponse> response = deviceEventService.findOutgoingBy(device.getTenant(), device.getApplication(), device.getGuid(), - channel, startTimestamp, null, asc, limit); + null, channel, startTimestamp, null, asc, limit); if (!response.getResult().isEmpty() || !waitTime.isPresent() || (waitTime.isPresent() && waitTime.get().equals(new Long("0")))) { deferredResult.setResult(EventVO.from(response.getResult())); diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/model/Event.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/model/Event.java index 0780a9f5e..4943897e5 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/model/Event.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/model/Event.java @@ -44,6 +44,7 @@ public static class EventActor implements URIDealer, Serializable { private String tenantDomain; private String applicationName; private String deviceGuid; + private String locationGuid; @JsonView(EventJsonView.class) private String deviceId; diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/BaseEventRepositoryImpl.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/BaseEventRepositoryImpl.java index 58765d844..83f812b58 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/BaseEventRepositoryImpl.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/BaseEventRepositoryImpl.java @@ -70,7 +70,7 @@ public void copy(Tenant tenant, Device originDevice, Device destDevice) throws B Instant endInstant = ZonedDateTime.now().plusYears(100L).toInstant(); // incoming - List incomingEvents = findIncomingBy(tenant, originDevice.getApplication(), originDevice.getGuid(), null, startInstant, endInstant, false, null); + List incomingEvents = findIncomingBy(tenant, originDevice.getApplication(), originDevice.getGuid(), null, null, startInstant, endInstant, false, null); for (Event event : incomingEvents) { event.getIncoming().setApplicationName(destDevice.getApplication().getName()); event.getIncoming().setDeviceGuid(destDevice.getGuid()); @@ -80,7 +80,7 @@ public void copy(Tenant tenant, Device originDevice, Device destDevice) throws B } // outgoing - List outgoingEvents = findOutgoingBy(tenant, originDevice.getApplication(), originDevice.getGuid(), null, startInstant, endInstant, false, null); + List outgoingEvents = findOutgoingBy(tenant, originDevice.getApplication(), originDevice.getGuid(), null, null, startInstant, endInstant, false, null); for (Event event : outgoingEvents) { event.getOutgoing().setApplicationName(destDevice.getApplication().getName()); event.getOutgoing().setDeviceGuid(destDevice.getGuid()); @@ -94,26 +94,28 @@ public void copy(Tenant tenant, Device originDevice, Device destDevice) throws B public List findIncomingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startInstant, Instant endInstant, boolean ascending, Integer limit) throws BusinessException { - return doFindByCommon(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit, - Type.INCOMING, false); + return doFindByCommon(tenant, application, deviceGuid, locationGuid, channel, startInstant, endInstant, ascending, + limit, Type.INCOMING, false); } @Override public List findOutgoingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startInstant, Instant endInstant, boolean ascending, Integer limit) throws BusinessException { - return doFindByCommon(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit, - Type.OUTGOING, false); + return doFindByCommon(tenant, application, deviceGuid, locationGuid, channel, startInstant, endInstant, ascending, + limit, Type.OUTGOING, false); } @@ -133,9 +135,9 @@ public Event saveOutgoing(Tenant tenant, Application application, Event event) t protected abstract void doRemoveBy(Tenant tenant, Application application, String deviceGuid, List events, Type incoming) throws Exception; - protected abstract List doFindBy(Tenant tenant, Application application, String deviceGuid, String channel, - Instant startInstant, Instant endInstant, boolean ascending, - Integer limit, Type incoming, boolean b) throws BusinessException; + protected abstract List doFindBy(Tenant tenant, Application application, String deviceGuid, String locationGuid, String channel, + Instant startInstant, Instant endInstant, boolean ascending, + Integer limit, Type incoming, boolean b) throws BusinessException; private Event doSaveCommon(Tenant tenant, Application application, Event event, Type incoming) throws BusinessException { @@ -179,9 +181,9 @@ private void doRemoveByCommon(Tenant tenant, Application application, String dev } - private List doFindByCommon(Tenant tenant, Application application, String deviceGuid, String channel, - Instant startInstant, Instant endInstant, boolean ascending, - Integer limit, Type incoming, boolean isDeleted) throws BusinessException { + private List doFindByCommon(Tenant tenant, Application application, String deviceGuid, String locationGuid, String channel, + Instant startInstant, Instant endInstant, boolean ascending, + Integer limit, Type incoming, boolean isDeleted) throws BusinessException { Optional.ofNullable(tenant) .filter(tenant1 -> Optional.ofNullable(tenant1.getDomainName()).filter(s -> !s.isEmpty()).isPresent()) @@ -191,9 +193,9 @@ private List doFindByCommon(Tenant tenant, Application application, Strin !Optional.ofNullable(limit).isPresent()) throw new IllegalArgumentException("Limit cannot be null when start instant isn't provided"); - return doFindBy(tenant, application, deviceGuid, channel, - startInstant, endInstant, ascending, - limit, incoming, isDeleted); + return doFindBy(tenant, application, deviceGuid, + locationGuid, channel, startInstant, endInstant, + ascending, limit, incoming, isDeleted); } diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/EventRepository.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/EventRepository.java index f1cc72baa..352340937 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/EventRepository.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/api/EventRepository.java @@ -44,6 +44,7 @@ public String getCode() { List findIncomingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startInstant, Instant endInstant, @@ -53,6 +54,7 @@ List findIncomingBy(Tenant tenant, List findOutgoingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startInstant, Instant endInstant, diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/DeviceEventServiceImpl.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/DeviceEventServiceImpl.java index 784efa296..848ad2311 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/DeviceEventServiceImpl.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/DeviceEventServiceImpl.java @@ -19,7 +19,6 @@ import javax.annotation.PostConstruct; import java.time.Instant; -import java.util.Collections; import java.util.List; import java.util.Optional; import java.util.stream.Collectors; @@ -58,6 +57,7 @@ public ServiceResponse> findIncomingBy(Tenant tenant, Application application, User user, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -71,7 +71,7 @@ public ServiceResponse> findIncomingBy(Tenant tenant, .build(); } - ServiceResponse> serviceResponse = findIncomingBy(tenant, application, deviceGuid, channel, startingTimestamp, endTimestamp, ascending, limit); + ServiceResponse> serviceResponse = findIncomingBy(tenant, application, deviceGuid, locationGuid, channel, startingTimestamp, endTimestamp, ascending, limit); if (serviceResponse.isOk() && Optional.ofNullable(user.getLocation()).isPresent()) { @@ -92,6 +92,7 @@ public ServiceResponse> findIncomingBy(Tenant tenant, public ServiceResponse> findIncomingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startTimestamp, Instant endTimestamp, @@ -119,11 +120,11 @@ public ServiceResponse> findIncomingBy(Tenant tenant, .withResult(eventRepository.findIncomingBy(tenant, application, deviceGuid, + locationGuid, channel, startTimestamp, endTimestamp, - ascending, - limit)).build(); + ascending, limit)).build(); } catch (BusinessException e) { return ServiceResponseBuilder.>error() .withMessage(e.getMessage()) @@ -136,6 +137,7 @@ public ServiceResponse> findOutgoingBy(Tenant tenant, Application application, User user, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -149,7 +151,7 @@ public ServiceResponse> findOutgoingBy(Tenant tenant, .build(); } - ServiceResponse> serviceResponse = findOutgoingBy(tenant, application, deviceGuid, channel, startingTimestamp, endTimestamp, ascending, limit); + ServiceResponse> serviceResponse = findOutgoingBy(tenant, application, deviceGuid, locationGuid, channel, startingTimestamp, endTimestamp, ascending, limit); if (serviceResponse.isOk() && Optional.ofNullable(user.getLocation()).isPresent()) { @@ -170,6 +172,7 @@ public ServiceResponse> findOutgoingBy(Tenant tenant, public ServiceResponse> findOutgoingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -201,11 +204,11 @@ public ServiceResponse> findOutgoingBy(Tenant tenant, .withResult(eventRepository.findOutgoingBy(tenant, application, deviceGuid, + locationGuid, channel, startingTimestamp, endTimestamp, - ascending, - limit)).build(); + ascending, limit)).build(); } catch (BusinessException e) { return ServiceResponseBuilder.>error() .withMessage(Validations.LIMIT_NULL.getCode()) diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/EventSchemaServiceImpl.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/EventSchemaServiceImpl.java index 57161970a..6c6a1b8f1 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/EventSchemaServiceImpl.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/EventSchemaServiceImpl.java @@ -1,8 +1,6 @@ package com.konkerlabs.platform.registry.business.services; import java.io.IOException; -import java.time.Duration; -import java.time.Instant; import java.util.ArrayList; import java.util.Collections; import java.util.LinkedHashSet; @@ -18,8 +16,6 @@ import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.Cacheable; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.Scope; import org.springframework.data.mongodb.core.MongoTemplate; @@ -349,8 +345,8 @@ public ServiceResponse findLastIncomingBy(Tenant tenant, Applicatio try { // List all last events - List lastEvents = eventRepository.findIncomingBy(tenant, application, deviceGuid, null, null, null, false, - limit); + List lastEvents = eventRepository.findIncomingBy(tenant, application, deviceGuid, null, null, null, null, + false, limit); ObjectMapper mapper = new ObjectMapper(); Device device = deviceRepository.findByTenantAndGuid(tenant.getId(), deviceGuid); diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/HealthAlertServiceImpl.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/HealthAlertServiceImpl.java index e1ad17dfc..8e992fef1 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/HealthAlertServiceImpl.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/HealthAlertServiceImpl.java @@ -502,7 +502,7 @@ public ServiceResponse getCurrentHealthByGuid(Tenant tenant, .build(); } - ServiceResponse> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, false, 1); + ServiceResponse> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, null, false, 1); if (incomingResponse.isOk() && incomingResponse.getResult().isEmpty()) { return ServiceResponseBuilder.ok() .withResult(HealthAlert.builder().severity(HealthAlertSeverity.NODATA).build()) diff --git a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/api/DeviceEventService.java b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/api/DeviceEventService.java index 27623f0fe..1a0a3c5a3 100644 --- a/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/api/DeviceEventService.java +++ b/konker.registry.services.core/src/main/java/com/konkerlabs/platform/registry/business/services/api/DeviceEventService.java @@ -35,6 +35,7 @@ public String getCode() { * @param application * @param user * @param deviceGuid + * @param locationGuid * @param startingTimestamp * @param endTimestamp * @param limit @@ -44,6 +45,7 @@ ServiceResponse> findIncomingBy(Tenant tenant, Application application, User user, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -56,6 +58,7 @@ ServiceResponse> findIncomingBy(Tenant tenant, * @param tenant * @param application * @param deviceGuid + * @param locationGuid * @param startingTimestamp * @param endTimestamp * @param limit @@ -64,6 +67,7 @@ ServiceResponse> findIncomingBy(Tenant tenant, ServiceResponse> findIncomingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -77,6 +81,7 @@ ServiceResponse> findIncomingBy(Tenant tenant, * @param application * @param user * @param deviceGuid + * @param locationGuid * @param startingTimestamp * @param endTimestamp * @param limit @@ -86,6 +91,7 @@ ServiceResponse> findOutgoingBy(Tenant tenant, Application application, User user, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, @@ -98,6 +104,7 @@ ServiceResponse> findOutgoingBy(Tenant tenant, * @param tenant * @param application * @param deviceGuid + * @param locationGuid * @param startingTimestamp * @param endTimestamp * @param limit @@ -106,6 +113,7 @@ ServiceResponse> findOutgoingBy(Tenant tenant, ServiceResponse> findOutgoingBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startingTimestamp, Instant endTimestamp, diff --git a/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/base/EventRepositoryTestConfiguration.java b/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/base/EventRepositoryTestConfiguration.java index faa6eef10..ca26fd5b6 100644 --- a/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/base/EventRepositoryTestConfiguration.java +++ b/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/base/EventRepositoryTestConfiguration.java @@ -30,7 +30,7 @@ protected void doRemoveBy(Tenant tenant, Application application, String deviceG } @Override - protected List doFindBy(Tenant tenant, Application application, String deviceGuid, String channel, Instant startInstant, Instant endInstant, boolean ascending, Integer limit, Type incoming, boolean b) throws BusinessException { + protected List doFindBy(Tenant tenant, Application application, String deviceGuid, String locationGuid, String channel, Instant startInstant, Instant endInstant, boolean ascending, Integer limit, Type incoming, boolean b) throws BusinessException { return null; } diff --git a/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/business/services/HealthAlertServiceTest.java b/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/business/services/HealthAlertServiceTest.java index acdd8fa3f..d7eeb490d 100644 --- a/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/business/services/HealthAlertServiceTest.java +++ b/konker.registry.services.core/src/test/java/com/konkerlabs/platform/registry/test/business/services/HealthAlertServiceTest.java @@ -821,7 +821,7 @@ public void shouldReturnDeviceDisabledGetCurrentHealth() { @Test public void shouldReturnDeviceNoDataGetCurrentHealth() { List events = Collections.emptyList(); - when(deviceEventService.findIncomingBy(currentTenant, application, healthAlert.getDevice().getGuid(), null, null, null, false, 1)) + when(deviceEventService.findIncomingBy(currentTenant, application, healthAlert.getDevice().getGuid(), null, null, null, null, false, 1)) .thenReturn(ServiceResponseBuilder.>ok().withResult(events).build()); ServiceResponse response = healthAlertService.getCurrentHealthByGuid( @@ -838,7 +838,7 @@ public void shouldGetCurrentHealth() { List events = new LinkedList<>(); events.add(Event.builder().build()); - when(deviceEventService.findIncomingBy(currentTenant, application, healthAlert.getDevice().getGuid(), null, null, null, false, 1)) + when(deviceEventService.findIncomingBy(currentTenant, application, healthAlert.getDevice().getGuid(), null, null, null, null, false, 1)) .thenReturn(ServiceResponseBuilder.>ok().withResult(events).build()); ServiceResponse response = healthAlertService.getCurrentHealthByGuid( diff --git a/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java b/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java index 76d42b2d1..a4edf2eb6 100644 --- a/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java +++ b/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java @@ -243,6 +243,7 @@ private PreparedStatement getInsertIncomingPreparedStatement(String table) { protected List doFindBy(Tenant tenant, Application application, String deviceGuid, + String locationGuid, String channel, Instant startInstant, Instant endInstant, @@ -424,7 +425,7 @@ private String getQuery(Tenant tenant, Application application, String deviceGui @Override protected void doRemoveBy(Tenant tenant, Application application, String deviceGuid, Type type) throws Exception { - List keys = doFindBy(tenant, application, deviceGuid, null, null, null, false, null, type, false); + List keys = doFindBy(tenant, application, deviceGuid, null, null, null, null, false, null, type, false); Set channels = new HashSet<>(); diff --git a/konker.registry.services.storage.mongodb/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryMongoImpl.java b/konker.registry.services.storage.mongodb/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryMongoImpl.java index 55dd2dfa4..8fe9797c6 100644 --- a/konker.registry.services.storage.mongodb/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryMongoImpl.java +++ b/konker.registry.services.storage.mongodb/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryMongoImpl.java @@ -78,6 +78,7 @@ protected Event doSave(Tenant tenant, Application application, Event event, Type incoming.put("applicationName",event.getIncoming().getApplicationName()); incoming.put("channel",event.getIncoming().getChannel()); incoming.put("deviceId", event.getIncoming().getDeviceId()); + incoming.put("locationGuid", event.getIncoming().getLocationGuid()); DBObject toSave = new BasicDBObject(); @@ -104,6 +105,7 @@ protected Event doSave(Tenant tenant, Application application, Event event, Type outgoing.put("applicationName",event.getOutgoing().getApplicationName()); outgoing.put("channel",event.getOutgoing().getChannel()); outgoing.put("deviceId", event.getOutgoing().getDeviceId()); + outgoing.put("locationGuid", event.getOutgoing().getLocationGuid()); toSave.put(Type.OUTGOING.getActorFieldName(), outgoing); } @@ -114,19 +116,21 @@ protected Event doSave(Tenant tenant, Application application, Event event, Type } protected List doFindBy(Tenant tenant, - Application application, - String deviceGuid, - String channel, - Instant startInstant, - Instant endInstant, - boolean ascending, - Integer limit, - Type type, - boolean isDeleted) throws BusinessException { + Application application, + String deviceGuid, + String locationGuid, + String channel, + Instant startInstant, + Instant endInstant, + boolean ascending, + Integer limit, + Type type, + boolean isDeleted) throws BusinessException { List criterias = new ArrayList<>(); Optional.ofNullable(deviceGuid).ifPresent(instant -> criterias.add(Criteria.where(MessageFormat.format("{0}.{1}", type.getActorFieldName(),"deviceGuid")).is(deviceGuid))); + Optional.ofNullable(locationGuid).ifPresent(instant -> criterias.add(Criteria.where(MessageFormat.format("{0}.{1}", type.getActorFieldName(), "locationGuid")).is(locationGuid))); Optional.ofNullable(startInstant).ifPresent(instant -> criterias.add(Criteria.where("ts").gt(instant.toEpochMilli()))); Optional.ofNullable(endInstant).ifPresent(instant -> criterias.add(Criteria.where("ts").lte(instant.toEpochMilli()))); Optional.ofNullable(isDeleted) @@ -165,6 +169,7 @@ protected List doFindBy(Tenant tenant, .map(dbObject1 -> { return Event.EventActor.builder() .deviceGuid(Optional.ofNullable(dbObject1.get("deviceGuid")).isPresent() ? dbObject1.get("deviceGuid").toString() : null) + .locationGuid(Optional.ofNullable(dbObject1.get("locationGuid")).isPresent() ? dbObject1.get("locationGuid").toString() : null) .tenantDomain(Optional.ofNullable(dbObject1.get("tenantDomain")).isPresent() ? dbObject1.get("tenantDomain").toString() : null) .applicationName(Optional.ofNullable(dbObject1.get("applicationName")).isPresent() ? dbObject1.get("applicationName").toString() : null) .channel(Optional.ofNullable(dbObject1.get("channel")).isPresent() ? dbObject1.get("channel").toString() : null) @@ -179,6 +184,7 @@ protected List doFindBy(Tenant tenant, .map(dbObject1 -> { return Event.EventActor.builder() .deviceGuid(Optional.ofNullable(dbObject1.get("deviceGuid")).isPresent() ? dbObject1.get("deviceGuid").toString() : null) + .locationGuid(Optional.ofNullable(dbObject1.get("locationGuid")).isPresent() ? dbObject1.get("locationGuid").toString() : null) .tenantDomain(Optional.ofNullable(dbObject1.get("tenantDomain")).isPresent() ? dbObject1.get("tenantDomain").toString() : null) .applicationName(Optional.ofNullable(dbObject1.get("applicationName")).isPresent() ? dbObject1.get("applicationName").toString() : null) .channel(Optional.ofNullable(dbObject1.get("channel")).isPresent() ? dbObject1.get("channel").toString() : null) diff --git a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/business/repositories/EventRepositoryMongoTest.java b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/business/repositories/EventRepositoryMongoTest.java index 31f3cf68c..083561f2e 100644 --- a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/business/repositories/EventRepositoryMongoTest.java +++ b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/business/repositories/EventRepositoryMongoTest.java @@ -130,6 +130,7 @@ public void setUp() { persisted.put("incoming", ((Supplier) () -> { DBObject incoming = new BasicDBObject(); incoming.put("deviceGuid",incomingEvent.getIncoming().getDeviceGuid()); + incoming.put("locationGuid",incomingEvent.getIncoming().getLocationGuid()); incoming.put("deviceId", incomingEvent.getIncoming().getDeviceId()); incoming.put("tenantDomain",incomingEvent.getIncoming().getTenantDomain()); incoming.put("applicationName",incomingEvent.getIncoming().getApplicationName()); @@ -268,9 +269,9 @@ public void shouldSaveTheIncomingEvent() throws Exception { @Test @UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json","/fixtures/deviceEvents.json","/fixtures/applications.json"}) public void shouldRetrieveLastTwoEventsByTenantAndDeviceWhenFindingIncomingBy() throws Exception { - List events = eventRepository.findIncomingBy(tenant, application, deviceGuid, "command", - firstEventTimestamp.plus(1,ChronoUnit.SECONDS), - null,false,2); + List events = eventRepository.findIncomingBy(tenant, application, deviceGuid, null, + "command", + firstEventTimestamp.plus(1,ChronoUnit.SECONDS), null, false, 2); assertThat(events,notNullValue()); assertThat(events,hasSize(2)); @@ -282,18 +283,18 @@ public void shouldRetrieveLastTwoEventsByTenantAndDeviceWhenFindingIncomingBy() @Test @UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json","/fixtures/deviceEvents.json","/fixtures/applications.json"}) public void shouldRemoveEvents() throws Exception { - List events = eventRepository.findIncomingBy(tenant, application, deviceGuid, "command", - firstEventTimestamp.plus(1,ChronoUnit.SECONDS), - null,false,2); + List events = eventRepository.findIncomingBy(tenant, application, deviceGuid, null, + "command", + firstEventTimestamp.plus(1,ChronoUnit.SECONDS), null, false, 2); assertThat(events,notNullValue()); assertThat(events,hasSize(2)); eventRepository.removeBy(tenant, application, deviceGuid); - events = eventRepository.findIncomingBy(tenant, application, deviceGuid, "command", - firstEventTimestamp.plus(1,ChronoUnit.SECONDS), - null,false,2); + events = eventRepository.findIncomingBy(tenant, application, deviceGuid, null, + "command", + firstEventTimestamp.plus(1,ChronoUnit.SECONDS), null, false, 2); assertThat(events,notNullValue()); assertThat(events,hasSize(0)); @@ -304,9 +305,9 @@ public void shouldRemoveEvents() throws Exception { public void shouldCopyEvents() throws Exception { String destinationGuid = "8363c556-84ea-11e6-92a2-4b01fea7e243"; - List events = eventRepository.findIncomingBy(tenant, application, destinationGuid, "command", - firstEventTimestamp.plus(1,ChronoUnit.SECONDS), - null,false,2); + List events = eventRepository.findIncomingBy(tenant, application, destinationGuid, null, + "command", + firstEventTimestamp.plus(1,ChronoUnit.SECONDS), null, false, 2); assertThat(events,notNullValue()); assertThat(events,hasSize(0)); @@ -317,11 +318,11 @@ public void shouldCopyEvents() throws Exception { eventRepository.copy(tenant, originDevice, destDevice); // checks if events were copied - events = eventRepository.findIncomingBy(tenant, applicationSmartff, destinationGuid, "e4399b2ed998.testchannel", + events = eventRepository.findIncomingBy(tenant, applicationSmartff, destinationGuid, null, + "e4399b2ed998.testchannel", null, null, - false, - 2); + false, 2); assertThat(events,notNullValue()); assertThat(events,hasSize(2)); @@ -333,7 +334,7 @@ public void shouldRaiseAnExceptionIfTenantIsNullWhenFindingIncomingBy() throws E thrown.expect(IllegalArgumentException.class); thrown.expectMessage("Tenant cannot be null"); - eventRepository.findIncomingBy(null,null,deviceGuid,null,firstEventTimestamp,null,false,null); + eventRepository.findIncomingBy(null,null,deviceGuid, null, null, firstEventTimestamp, null, false, null); } @Test @@ -342,17 +343,17 @@ public void shouldRaiseAnExceptionIfStartingOffsetAndLimitAreNullWhenFindingInco thrown.expectMessage("Limit cannot be null when start instant isn't provided"); - eventRepository.findIncomingBy(tenant,application,deviceGuid,null,null,null,false,null); + eventRepository.findIncomingBy(tenant,application,deviceGuid, null, null, null, null, false, null); } @Test @UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json","/fixtures/deviceEvents.json","/fixtures/applications.json"}) public void shouldRetrieveTheOnlyFirstEventByTenantAndDeviceWhenFindingIncomingBy() throws Exception { List events = eventRepository.findIncomingBy(tenant, application, - deviceGuid,"command", - firstEventTimestamp, - secondEventTimestamp.minus(1, ChronoUnit.SECONDS),true, - 1); + deviceGuid, null, + "command", + firstEventTimestamp, secondEventTimestamp.minus(1, ChronoUnit.SECONDS), + true, 1); assertThat(events,notNullValue()); assertThat(events,hasSize(1)); @@ -364,10 +365,10 @@ public void shouldRetrieveTheOnlyFirstEventByTenantAndDeviceWhenFindingIncomingB @UsingDataSet(locations = {"/fixtures/tenants.json","/fixtures/devices.json","/fixtures/deviceEvents.json","/fixtures/applications.json"}) public void shouldLimitResultsAccordingToLimitParameterWhenFindingIncomingBy() throws Exception { List events = eventRepository.findIncomingBy(tenant, application, - deviceGuid,"command", - firstEventTimestamp, - thirdEventTimestamp,false, - 1); + deviceGuid, null, + "command", + firstEventTimestamp, thirdEventTimestamp, + false, 1); assertThat(events,notNullValue()); assertThat(events,hasSize(1)); diff --git a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceEventServiceTest.java b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceEventServiceTest.java index 3d19e167b..458de9e76 100644 --- a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceEventServiceTest.java +++ b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceEventServiceTest.java @@ -121,12 +121,12 @@ public void shouldReturnAnErrorMessageIfTenantIsNullWhenFindingBy() throws Excep null, null, device.getId(), + null, channel, firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(CommonValidations.TENANT_NULL.getCode())); } @@ -139,12 +139,12 @@ public void shouldReturnAnErrorMessageIfStartInstantIsNullAndLimitIsNullWhenFind tenant, application, device.getId(), + null, channel, null, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(DeviceEventService.Validations.LIMIT_NULL.getCode())); } @@ -156,12 +156,12 @@ public void shouldFindAllRequestEvents() throws Exception { tenant, application, device.getGuid(), + null, "command", firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(3)); @@ -179,12 +179,12 @@ public void shouldReturnAnErrorMessageIfTenantIsNullWhenFindingByWithUser() thro null, user, device.getId(), + null, channel, firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(CommonValidations.TENANT_NULL.getCode())); } @@ -198,12 +198,12 @@ public void shouldReturnAnErrorMessageIfStartInstantIsNullAndLimitIsNullWhenFind application, user, device.getId(), + null, channel, null, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(DeviceEventService.Validations.LIMIT_NULL.getCode())); } @@ -216,12 +216,12 @@ public void shouldReturnAnErrorIfUserHasNoAccessToApplication() throws Exception application, userApplication, device.getGuid(), + null, "command", firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(ApplicationService.Validations.APPLICATION_HAS_NO_PERMISSION.getCode())); } @@ -242,9 +242,9 @@ public void shouldFindAllRequestEventsWithUserApplication() throws Exception { null, null, null, + null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(2)); @@ -267,9 +267,9 @@ public void shouldFindAllRequestEventsWithUserLocation() throws Exception { null, null, null, + null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(1)); @@ -283,12 +283,12 @@ public void shouldFindAllRequestEventsWithUser() throws Exception { application, user, device.getGuid(), + null, "command", firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(3)); @@ -304,12 +304,12 @@ public void shouldReturnAnErrorMessageIfTenantIsNullWhenFindingByOutgoing() thro null, null, device.getId(), + null, channel, firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(CommonValidations.TENANT_NULL.getCode())); } @@ -322,12 +322,12 @@ public void shouldReturnAnErrorMessageIfStartInstantIsNullAndLimitIsNullWhenFind tenant, application, device.getId(), + null, channel, null, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(DeviceEventService.Validations.LIMIT_NULL.getCode())); } @@ -343,12 +343,12 @@ public void shouldFindAllRequestEventsOutgoing() throws Exception { tenant, application, device.getGuid(), + null, "e4399b2ed998.testchannel", null, null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(2)); @@ -367,12 +367,12 @@ public void shouldReturnAnErrorMessageIfTenantIsNullWhenFindingByOutgoingWithUse null, user, device.getId(), + null, channel, firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(CommonValidations.TENANT_NULL.getCode())); } @@ -390,12 +390,12 @@ public void shouldReturnAnErrorMessageIfStartInstantIsNullAndLimitIsNullWhenFind application, user, device.getId(), + null, channel, null, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(DeviceEventService.Validations.LIMIT_NULL.getCode())); } @@ -412,12 +412,12 @@ public void shouldReturnAnErrorIfUserHasNoAccessToApplicationFindingByOutgoing() application, userApplication, device.getGuid(), + null, "command", firstEventTimestamp, null, false, - null - ); + null); assertThat(serviceResponse, hasErrorMessage(ApplicationService.Validations.APPLICATION_HAS_NO_PERMISSION.getCode())); } @@ -438,9 +438,9 @@ public void shouldFindAllRequestEventsWithUserApplicationFindingByOutgoing() thr null, null, null, + null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(2)); @@ -463,9 +463,9 @@ public void shouldFindAllRequestEventsWithUserLocationFindingByOutgoing() throws null, null, null, + null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(1)); @@ -485,12 +485,12 @@ public void shouldFindAllRequestEventsWithUserFindingByOutgoing() throws Excepti application, user, device.getGuid(), + null, "e4399b2ed998.testchannel", null, null, false, - 10 - ); + 10); assertThat(serviceResponse.getResult(),notNullValue()); assertThat(serviceResponse.getResult(),hasSize(2)); diff --git a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceRegisterServiceTest.java b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceRegisterServiceTest.java index da6fe0f01..bf9d7fb31 100644 --- a/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceRegisterServiceTest.java +++ b/konker.registry.services.storage.mongodb/src/test/java/com/konkerlabs/platform/registry/test/services/DeviceRegisterServiceTest.java @@ -592,9 +592,9 @@ public void shouldDeleteInLogicalWayEachDataIngestedOnDeviceForSucceedDeletion() .findByTenantDomainNameAndDeviceGuid(currentTenant.getDomainName(), THE_OTHER_DEVICE_GUID); - ServiceResponse> incomingEvents = deviceEventService.findIncomingBy(currentTenant, konkerApplication, THE_OTHER_DEVICE_GUID, + ServiceResponse> incomingEvents = deviceEventService.findIncomingBy(currentTenant, konkerApplication, THE_OTHER_DEVICE_GUID, null, INCOMING_CHANNEL, null, null, false, 100); - ServiceResponse> outgoingEvents = deviceEventService.findOutgoingBy(currentTenant, konkerApplication, THE_OTHER_DEVICE_GUID, + ServiceResponse> outgoingEvents = deviceEventService.findOutgoingBy(currentTenant, konkerApplication, THE_OTHER_DEVICE_GUID, null, OUTGOING_CHANNEL, null, null, false, 100); assertThat(incomingEvents.getResult().size(), equalTo(2)); diff --git a/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceController.java b/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceController.java index d1c5c2fcf..f656c76a1 100644 --- a/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceController.java +++ b/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceController.java @@ -243,8 +243,8 @@ public ModelAndView deviceEvents(@PathVariable String deviceGuid, @PathVariable( ModelAndView mv = new ModelAndView("devices/events"); - List incomingEvents = deviceEventService.findIncomingBy(tenant, application, device.getGuid(), null, null, null, false, 50).getResult(); - List outgoingEvents = deviceEventService.findOutgoingBy(tenant, application, device.getGuid(), null, null, null, false, 50).getResult(); + List incomingEvents = deviceEventService.findIncomingBy(tenant, application, device.getGuid(), null, null, null, null, false, 50).getResult(); + List outgoingEvents = deviceEventService.findOutgoingBy(tenant, application, device.getGuid(), null, null, null, null, false, 50).getResult(); boolean hasAnyEvent = !incomingEvents.isEmpty() || !outgoingEvents.isEmpty(); @@ -297,7 +297,7 @@ public ModelAndView loadIncomingEvents(@PathVariable String deviceGuid, Instant instantEnd = StringUtils.isNotEmpty(dateEnd) ? ZonedDateTime.of(LocalDateTime.parse(dateEnd, dtf), ZoneId.of(user.getZoneId().getId())).toInstant() : null; ModelAndView mv = new ModelAndView("devices/events-incoming", "recentIncomingEvents", - deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, instantStart, instantEnd, false, 50).getResult()); + deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, instantStart, instantEnd, false, 50).getResult()); return mv; } @@ -315,7 +315,7 @@ public ModelAndView loadOutgoingEvents(@PathVariable String deviceGuid, Instant instantEnd = StringUtils.isNotEmpty(dateEnd) ? ZonedDateTime.of(LocalDateTime.parse(dateEnd, dtf), ZoneId.of(user.getZoneId().getId())).toInstant() : null; ModelAndView mv = new ModelAndView("devices/events-outgoing", "recentOutgoingEvents", - deviceEventService.findOutgoingBy(tenant, application, deviceGuid, null, instantStart, instantEnd, false, 50).getResult()); + deviceEventService.findOutgoingBy(tenant, application, deviceGuid, null, null, instantStart, instantEnd, false, 50).getResult()); return mv; } diff --git a/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceVisualizationController.java b/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceVisualizationController.java index e781653df..5eac89243 100644 --- a/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceVisualizationController.java +++ b/konker.registry.web/src/main/java/com/konkerlabs/platform/registry/web/controllers/DeviceVisualizationController.java @@ -135,8 +135,8 @@ private List doSearch(String dateStart, String dateEnd, boolean online, String d Application application = device.getApplication(); if (online) { - ServiceResponse> response = deviceEventService.findIncomingBy(tenant, application, deviceGuid, channel, null, - null, false, limit); + ServiceResponse> response = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, channel, + null, null, false, limit); List eventsResult = decorateEventResult(response); return eventsResult; @@ -148,8 +148,8 @@ private List doSearch(String dateStart, String dateEnd, boolean online, String d ZonedDateTime zonedDateEnd = ZonedDateTime.of(end, ZoneId.of(user.getZoneId().getId())); ServiceResponse> response = deviceEventService.findIncomingBy(tenant, application, - deviceGuid, channel, zonedDateStart.toInstant(), - zonedDateEnd.toInstant(), false, limit); + deviceGuid, null, channel, + zonedDateStart.toInstant(), zonedDateEnd.toInstant(), false, limit); List eventsResult = decorateEventResult(response); return eventsResult; diff --git a/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceControllerTest.java b/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceControllerTest.java index 36c907520..09c4f313a 100644 --- a/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceControllerTest.java +++ b/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceControllerTest.java @@ -228,9 +228,9 @@ public void shouldShowDeviceEventList() throws Exception { savedDevice.setRegistrationDate(Instant.now()); when(deviceRegisterService.getByDeviceGuid(tenant, application, savedDevice.getGuid())) .thenReturn(ServiceResponseBuilder. ok().withResult(savedDevice).build()); - when(deviceEventService.findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50)) + when(deviceEventService.findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); - when(deviceEventService.findOutgoingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50)) + when(deviceEventService.findOutgoingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); // find last numeric metric mocks @@ -258,7 +258,7 @@ public void shouldShowDeviceEventList() throws Exception { .andExpect(view().name("devices/events")); verify(deviceRegisterService).getByDeviceGuid(tenant, application, savedDevice.getGuid()); - verify(deviceEventService).findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50); + verify(deviceEventService).findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50); } @Test @@ -267,9 +267,9 @@ public void shouldShowDeviceEventListWithNumericMetric() throws Exception { savedDevice.setRegistrationDate(Instant.now()); when(deviceRegisterService.getByDeviceGuid(tenant, application, savedDevice.getGuid())) .thenReturn(ServiceResponseBuilder. ok().withResult(savedDevice).build()); - when(deviceEventService.findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50)) + when(deviceEventService.findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); - when(deviceEventService.findOutgoingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50)) + when(deviceEventService.findOutgoingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); // find last numeric metric mocks @@ -300,7 +300,7 @@ public void shouldShowDeviceEventListWithNumericMetric() throws Exception { .andExpect(view().name("devices/events")); verify(deviceRegisterService).getByDeviceGuid(tenant, application, savedDevice.getGuid()); - verify(deviceEventService).findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, false, 50); + verify(deviceEventService).findIncomingBy(tenant, application, savedDevice.getGuid(), null, null, null, null, false, 50); } @Test @@ -391,7 +391,7 @@ public void shouldRedirectToListDevicesAndShowSuccessMessageAfterDeletionSucceed @WithMockUser(authorities={"VIEW_DEVICE_LOG"}) public void shouldListIncomingEvents() throws Exception { - when(deviceEventService.findIncomingBy(tenant, application, "deviceId", null, null, null, false, 50)) + when(deviceEventService.findIncomingBy(tenant, application, "deviceId", null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); when(applicationService.getByApplicationName(tenant, application.getName())) .thenReturn(ServiceResponseBuilder.ok().withResult(application).build()); @@ -406,7 +406,15 @@ public void shouldListIncomingEvents() throws Exception { @WithMockUser(authorities={"VIEW_DEVICE_LOG"}) public void shouldListIncomingEventsWithFilter() throws Exception { - when(deviceEventService.findIncomingBy(Matchers.any(Tenant.class), Matchers.any(Application.class), Matchers.matches("deviceId"), Matchers.isNull(String.class), Matchers.any(Instant.class), Matchers.any(Instant.class), Matchers.anyBoolean(), Matchers.anyInt())) + when(deviceEventService.findIncomingBy(Matchers.any(Tenant.class), + Matchers.any(Application.class), + Matchers.matches("deviceId"), + Matchers.isNull(String.class), + Matchers.isNull(String.class), + Matchers.any(Instant.class), + Matchers.any(Instant.class), + Matchers.anyBoolean(), + Matchers.anyInt())) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); when(applicationService.getByApplicationName(Matchers.any(Tenant.class), Matchers.anyString())) @@ -424,7 +432,7 @@ public void shouldListIncomingEventsWithFilter() throws Exception { @WithMockUser(authorities={"VIEW_DEVICE_LOG"}) public void shouldListOutgoingEvents() throws Exception { - when(deviceEventService.findOutgoingBy(tenant, application, "deviceId", null, null, null, false, 50)) + when(deviceEventService.findOutgoingBy(tenant, application, "deviceId", null, null, null, null, false, 50)) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); when(applicationService.getByApplicationName(tenant, application.getName())) .thenReturn(ServiceResponseBuilder.ok().withResult(application).build()); @@ -439,7 +447,15 @@ public void shouldListOutgoingEvents() throws Exception { @WithMockUser(authorities={"VIEW_DEVICE_LOG"}) public void shouldListOutgoingEventsWithFilter() throws Exception { - when(deviceEventService.findOutgoingBy(Matchers.any(Tenant.class), Matchers.any(Application.class), Matchers.matches("deviceId"), Matchers.isNull(String.class), Matchers.any(Instant.class), Matchers.any(Instant.class), Matchers.anyBoolean(), Matchers.anyInt())) + when(deviceEventService.findOutgoingBy(Matchers.any(Tenant.class), + Matchers.any(Application.class), + Matchers.matches("deviceId"), + Matchers.isNull(String.class), + Matchers.isNull(String.class), + Matchers.any(Instant.class), + Matchers.any(Instant.class), + Matchers.anyBoolean(), + Matchers.anyInt())) .thenReturn(ServiceResponseBuilder.> ok().withResult(Collections.emptyList()).build()); when(applicationService.getByApplicationName(Matchers.any(Tenant.class), Matchers.anyString())) .thenReturn(ServiceResponseBuilder.ok().withResult(application).build()); diff --git a/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceVisualizationControllerTest.java b/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceVisualizationControllerTest.java index a6878ed14..9e7872777 100644 --- a/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceVisualizationControllerTest.java +++ b/konker.registry.web/src/test/java/com/konkerlabs/platform/registry/test/web/controllers/DeviceVisualizationControllerTest.java @@ -206,7 +206,7 @@ public void shouldReturnDataOnline() throws Exception { when(deviceRegisterService.findByTenantDomainNameAndDeviceGuid(tenant.getDomainName(), DEVICE_GUID)) .thenReturn(Device.builder().application(application).build()); - when(deviceEventService.findIncomingBy(tenant, application, DEVICE_GUID, CHANNEL, null, null, false, 100)) + when(deviceEventService.findIncomingBy(tenant, application, DEVICE_GUID, null, CHANNEL, null, null, false, 100)) .thenReturn(ServiceResponseBuilder.>ok() .withResult(eventsList).build()); @@ -227,7 +227,7 @@ public void shouldReturnDataByDateRange() throws Exception { when(deviceRegisterService.findByTenantDomainNameAndDeviceGuid(tenant.getDomainName(), DEVICE_GUID)) .thenReturn(Device.builder().application(application).build()); - when(deviceEventService.findIncomingBy(tenant, application, DEVICE_GUID, CHANNEL, startingTimestamp, endTimestamp, false, 100)) + when(deviceEventService.findIncomingBy(tenant, application, DEVICE_GUID, null, CHANNEL, startingTimestamp, endTimestamp, false, 100)) .thenReturn(ServiceResponseBuilder.>ok() .withResult(eventsList).build()); From 534afaae8fe209cd9edd013b67cb3ca5b9117ce5 Mon Sep 17 00:00:00 2001 From: Douglas Date: Tue, 19 Nov 2019 11:19:39 -0300 Subject: [PATCH 5/6] KRMVP-1188 - Change service layer cassandra --- .../events/EventRepositoryCassandraImpl.java | 58 ++++++++++++++++--- .../scripts/V5__add_new_incoming_tables.cql | 2 +- .../scripts/V6__add_new_outgoing_tables.cql | 14 ++++- 3 files changed, 65 insertions(+), 9 deletions(-) diff --git a/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java b/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java index a4edf2eb6..9cbc0c5cc 100644 --- a/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java +++ b/konker.registry.services.storage.cassandra/src/main/java/com/konkerlabs/platform/registry/business/repositories/events/EventRepositoryCassandraImpl.java @@ -37,12 +37,20 @@ public class EventRepositoryCassandraImpl extends BaseEventRepositoryImpl implem private static final String INCOMING_EVENTS_CHANNEL = "incoming_events_channel"; private static final String INCOMING_EVENTS_DEVICE_GUID = "incoming_events_device_guid"; private static final String INCOMING_EVENTS_DEVICE_GUID_CHANNEL = "incoming_events_device_guid_channel"; + private static final String INCOMING_EVENTS_LOCATION_GUID = "incoming_events_location_guid"; + private static final String INCOMING_EVENTS_LOCATION_GUID_CHANNEL = "incoming_events_location_guid_channel"; + private static final String INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID = "incoming_events_location_guid_device_guid"; + private static final String INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL = "incoming_events_location_guid_deviceguid_channel"; private static final String INCOMING_EVENTS_DELETED = "incoming_events_deleted"; private static final String OUTGOING_EVENTS = "outgoing_events"; private static final String OUTGOING_EVENTS_CHANNEL = "outgoing_events_channel"; private static final String OUTGOING_EVENTS_DEVICE_GUID = "outgoing_events_device_guid"; private static final String OUTGOING_EVENTS_DEVICE_GUID_CHANNEL = "outgoing_events_device_guid_channel"; + private static final String OUTGOING_EVENTS_LOCATION_GUID = "outgoing_events_location_guid"; + private static final String OUTGOING_EVENTS_LOCATION_GUID_CHANNEL = "outgoing_events_location_guid_channel"; + private static final String OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID = "outgoing_events_location_guid_device_guid"; + private static final String OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL = "outgoing_events_location_guid_deviceguid_channel"; private static final String OUTGOING_EVENTS_DELETED = "outgoing_events_deleted"; @Autowired @@ -72,11 +80,19 @@ protected Event doSave(Tenant tenant, Application application, Event event, Type saveEvent(tenant, application, event, type, INCOMING_EVENTS_DEVICE_GUID, false); saveEvent(tenant, application, event, type, INCOMING_EVENTS_DEVICE_GUID_CHANNEL, false); saveEvent(tenant, application, event, type, INCOMING_EVENTS_CHANNEL, false); + saveEvent(tenant, application, event, type, INCOMING_EVENTS_LOCATION_GUID, false); + saveEvent(tenant, application, event, type, INCOMING_EVENTS_LOCATION_GUID_CHANNEL, false); + saveEvent(tenant, application, event, type, INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID, false); + saveEvent(tenant, application, event, type, INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL, false); } else if (type == Type.OUTGOING) { saveEvent(tenant, application, event, type, OUTGOING_EVENTS, true); saveEvent(tenant, application, event, type, OUTGOING_EVENTS_DEVICE_GUID, false); saveEvent(tenant, application, event, type, OUTGOING_EVENTS_DEVICE_GUID_CHANNEL, false); saveEvent(tenant, application, event, type, OUTGOING_EVENTS_CHANNEL, false); + saveEvent(tenant, application, event, type, OUTGOING_EVENTS_LOCATION_GUID, false); + saveEvent(tenant, application, event, type, OUTGOING_EVENTS_LOCATION_GUID_CHANNEL, false); + saveEvent(tenant, application, event, type, OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID, false); + saveEvent(tenant, application, event, type, OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL, false); } return event; @@ -95,6 +111,7 @@ private void saveEvent(Tenant tenant, Application application, Event event, Type event.getIncoming().getChannel(), event.getIncoming().getDeviceGuid(), event.getIncoming().getDeviceId(), + event.getIncoming().getLocationGuid(), Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getElev() : null, Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getHdop() : null, Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getLat() : null, @@ -116,6 +133,7 @@ private void saveEvent(Tenant tenant, Application application, Event event, Type event.getOutgoing().getChannel(), event.getOutgoing().getDeviceGuid(), event.getOutgoing().getDeviceId(), + event.getOutgoing().getLocationGuid(), Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getElev() : null, Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getHdop() : null, Optional.ofNullable(event.getGeolocation()).isPresent() ? event.getGeolocation().getLat() : null, @@ -152,6 +170,7 @@ private PreparedStatement getInsertOutgoingPreparedStatement(String table) { query.append("channel, "); query.append("device_guid, "); query.append("device_id, "); + query.append("location_guid, "); query.append("geo_elev, "); query.append("geo_hdop, "); @@ -179,6 +198,7 @@ private PreparedStatement getInsertOutgoingPreparedStatement(String table) { query.append("?, "); query.append("?, "); query.append("?, "); + query.append("?, "); query.append("?"); query.append(")"); @@ -209,6 +229,7 @@ private PreparedStatement getInsertIncomingPreparedStatement(String table) { query.append("channel, "); query.append("device_guid, "); query.append("device_id, "); + query.append("location_guid, "); query.append("geo_elev, "); query.append("geo_hdop, "); query.append("geo_lat, "); @@ -227,6 +248,7 @@ private PreparedStatement getInsertIncomingPreparedStatement(String table) { query.append("?, "); query.append("?, "); query.append("?, "); + query.append("?, "); query.append("?"); query.append(")"); @@ -256,6 +278,7 @@ protected List doFindBy(Tenant tenant, String query = getQuery(tenant, application, + locationGuid, deviceGuid, channel, startInstant, @@ -343,7 +366,7 @@ protected List doFindBy(Tenant tenant, } - private String getQuery(Tenant tenant, Application application, String deviceGuid, String channel, + private String getQuery(Tenant tenant, Application application, String locationGuid, String deviceGuid, String channel, Instant startInstant, Instant endInstant, boolean ascending, Integer limit, Type type, List filters) { @@ -351,26 +374,42 @@ private String getQuery(Tenant tenant, Application application, String deviceGui StringBuilder query = new StringBuilder(); if (type == Type.INCOMING) { - query.append("SELECT tenant_domain, application_name, timestamp, channel, device_guid, device_id, geo_elev, geo_hdop, geo_lat, geo_lon, ingested_timestamp, payload FROM "); - - if (deviceGuid != null && channel != null) { + query.append("SELECT tenant_domain, application_name, timestamp, channel, device_guid, device_id, location_guid, geo_elev, geo_hdop, geo_lat, geo_lon, ingested_timestamp, payload FROM "); + + if (locationGuid != null && deviceGuid != null && channel != null) { + table = INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL; + } else if (locationGuid != null && channel != null) { + table = INCOMING_EVENTS_LOCATION_GUID_CHANNEL; + } else if (locationGuid != null && deviceGuid != null) { + table = INCOMING_EVENTS_LOCATION_GUID_DEVICE_GUID; + } else if (deviceGuid != null && channel != null) { table = INCOMING_EVENTS_DEVICE_GUID_CHANNEL; } else if (deviceGuid != null) { table = INCOMING_EVENTS_DEVICE_GUID; } else if (channel != null) { table = INCOMING_EVENTS_CHANNEL; + } else if (locationGuid != null) { + table = INCOMING_EVENTS_LOCATION_GUID; } else if (deviceGuid == null && channel == null) { table = INCOMING_EVENTS; } } else if (type == Type.OUTGOING) { - query.append("SELECT tenant_domain, application_name, timestamp, channel, device_guid, device_id, geo_elev, geo_hdop, geo_lat, geo_lon, incoming_channel, incoming_device_guid, incoming_device_id, ingested_timestamp, payload FROM "); - - if (deviceGuid != null && channel != null) { + query.append("SELECT tenant_domain, application_name, timestamp, channel, device_guid, device_id, location_guid, geo_elev, geo_hdop, geo_lat, geo_lon, incoming_channel, incoming_device_guid, incoming_device_id, ingested_timestamp, payload FROM "); + + if (locationGuid != null && deviceGuid != null && channel != null) { + table = OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID_CHANNEL; + } else if (locationGuid != null && channel != null) { + table = OUTGOING_EVENTS_LOCATION_GUID_CHANNEL; + } else if (locationGuid != null && deviceGuid != null) { + table = OUTGOING_EVENTS_LOCATION_GUID_DEVICE_GUID; + } else if (deviceGuid != null && channel != null) { table = OUTGOING_EVENTS_DEVICE_GUID_CHANNEL; } else if (deviceGuid != null) { table = OUTGOING_EVENTS_DEVICE_GUID; } else if (channel != null) { table = OUTGOING_EVENTS_CHANNEL; + } else if (locationGuid != null) { + table = OUTGOING_EVENTS_LOCATION_GUID; } else if (deviceGuid == null && channel == null) { table = OUTGOING_EVENTS; } @@ -387,6 +426,11 @@ private String getQuery(Tenant tenant, Application application, String deviceGui query.append(" AND application_name = ?"); filters.add(application.getName()); + if (locationGuid != null) { + query.append(" AND location_guid = ?"); + filters.add(locationGuid); + } + if (deviceGuid != null) { query.append(" AND device_guid = ?"); filters.add(deviceGuid); diff --git a/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql b/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql index cbe7a4aa9..0e9450943 100644 --- a/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql +++ b/konker.registry.services.storage.cassandra/src/scripts/V5__add_new_incoming_tables.cql @@ -49,7 +49,7 @@ CREATE TABLE incoming_events_location_guid_channel ( PRIMARY KEY ((tenant_domain, application_name, location_guid, channel), timestamp) ) WITH CLUSTERING ORDER BY (timestamp DESC); -CREATE TABLE incoming_events_location_guid_device_guid_channel ( +CREATE TABLE incoming_events_location_guid_deviceguid_channel ( tenant_domain text, application_name text, timestamp bigint, diff --git a/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql b/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql index 1c3a9d701..18758c6d1 100644 --- a/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql +++ b/konker.registry.services.storage.cassandra/src/scripts/V6__add_new_outgoing_tables.cql @@ -7,6 +7,9 @@ CREATE TABLE outgoing_events_location_guid ( device_id text, payload text, location_guid text, + incoming_channel text, + incoming_device_guid text, + incoming_device_id text, geo_lat double, geo_lon double, geo_hdop bigint, @@ -24,6 +27,9 @@ CREATE TABLE outgoing_events_location_guid_device_guid ( device_id text, payload text, location_guid text, + incoming_channel text, + incoming_device_guid text, + incoming_device_id text, geo_lat double, geo_lon double, geo_hdop bigint, @@ -41,6 +47,9 @@ CREATE TABLE outgoing_events_location_guid_channel ( device_id text, payload text, location_guid text, + incoming_channel text, + incoming_device_guid text, + incoming_device_id text, geo_lat double, geo_lon double, geo_hdop bigint, @@ -49,7 +58,7 @@ CREATE TABLE outgoing_events_location_guid_channel ( PRIMARY KEY ((tenant_domain, application_name, location_guid, channel), timestamp) ) WITH CLUSTERING ORDER BY (timestamp DESC); -CREATE TABLE outgoing_events_location_guid_device_guid_channel ( +CREATE TABLE outgoing_events_location_guid_deviceguid_channel ( tenant_domain text, application_name text, timestamp bigint, @@ -58,6 +67,9 @@ CREATE TABLE outgoing_events_location_guid_device_guid_channel ( device_id text, payload text, location_guid text, + incoming_channel text, + incoming_device_guid text, + incoming_device_id text, geo_lat double, geo_lon double, geo_hdop bigint, From f47e5c0a05f4c9010446bb53380fdd7bdb866a64 Mon Sep 17 00:00:00 2001 From: Douglas Date: Fri, 22 Nov 2019 11:01:31 -0300 Subject: [PATCH 6/6] KRMVP-1188 - Change service layer cassandra --- version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/version b/version index 6f279e629..7c7a3812b 100644 --- a/version +++ b/version @@ -1 +1 @@ -2.3.2-CAPPUCCINO \ No newline at end of file +2.3.3-CAPPUCCINO \ No newline at end of file