Skip to content

Commit

Permalink
Merge pull request #449 from KonkerLabs/gw-data-channel
Browse files Browse the repository at this point in the history
New fetuare
  • Loading branch information
sonecabr authored Nov 22, 2019
2 parents 4ebf3b3 + f47e5c0 commit 3a4d02f
Show file tree
Hide file tree
Showing 42 changed files with 598 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ 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;

public void parse(String query) throws BadRequestResponseException {

this.deviceGuid = null;
this.locationGuid = null;
this.channel = null;
this.startingTimestamp = null;
this.endTimestamp = null;
Expand All @@ -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")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,12 +23,16 @@
@ApiModel(value = "Location", discriminator = "com.konkerlabs.platform.registry.api.model")
public class LocationVO extends LocationInputVO implements SerializableVO<Location, LocationVO> {

@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
Expand All @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public DeviceStatsVO stats(
Application application = getApplication(applicationId);

ServiceResponse<Device> deviceResponse = deviceRegisterService.getByDeviceGuid(tenant, application, deviceGuid);
ServiceResponse<List<Event>> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, false, 1);
ServiceResponse<List<Event>> incomingResponse = deviceEventService.findIncomingBy(tenant, application, deviceGuid, null, null, null, null, false, 1);

if (!deviceResponse.isOk()) {
throw new NotFoundResponseException(deviceResponse);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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:&gt;2017-04-05T14:50:00+01:00\n\n" +
"* timestamp:&lt;2017-04-05T14:55:00-01:00\n\n" +
"* timestamp:&gt;2017-04-05T13:54:30.891Z timestamp:&lt;2017-04-05T13:56:30.891Z\n\n";
Expand Down Expand Up @@ -92,6 +94,7 @@ public List<EventVO> 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();
Expand All @@ -101,11 +104,11 @@ public List<EventVO> list(
application,
loggedUser,
deviceGuid,
locationGuid,
channel,
startingTimestamp,
endTimestamp,
ascending,
limit);
ascending, limit);

if (!restDestinationResponse.isOk()) {
throw new BadServiceResponseException( restDestinationResponse, validationsCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,12 @@ public List<EventVO> 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<List<Event>> restDestinationResponse = deviceEventService.findOutgoingBy(tenant, application, user.getParentUser(), deviceGuid, channel, startingTimestamp, endTimestamp, ascending, limit);
ServiceResponse<List<Event>> restDestinationResponse = deviceEventService.findOutgoingBy(tenant, application, user.getParentUser(), deviceGuid, locationGuid, channel, startingTimestamp, endTimestamp, ascending, limit);

if (!restDestinationResponse.isOk()) {
throw new BadServiceResponseException( restDestinationResponse, validationsCode);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ public void shouldShowDeviceStats() throws Exception {
when(applicationService.getByApplicationName(tenant, application.getName()))
.thenReturn(ServiceResponseBuilder.<Application>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.<List<Event>>ok().withResult(events).build());

getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/{2}/stats", application.getName(), BASEPATH, device1.getGuid()))
Expand Down Expand Up @@ -705,7 +705,7 @@ public void shouldTryShowDeviceStatWithBadRequest() throws Exception {
when(applicationService.getByApplicationName(tenant, application.getName()))
.thenReturn(ServiceResponseBuilder.<Application>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.<List<Event>>ok().withResult(events).build());

getMockMvc().perform(MockMvcRequestBuilders.get(MessageFormat.format("/{0}/{1}/{2}/stats", application.getName(), BASEPATH, device1.getGuid()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<List<Event>>ok().withResult(incomingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(incomingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(incomingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(incomingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.<List<Event>>ok().withResult(outgoingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(outgoingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(outgoingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down Expand Up @@ -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.<List<Event>>ok().withResult(outgoingEvents).build());

when(applicationService.getByApplicationName(tenant, application.getName()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ private void process(Tenant tenant, Application application, Instant startInstan

LOGGER.info("Tenant {} Application {}", tenant.getName(), application.getName());

List<Event> incomingEvents = cassandraEventsRepository.findIncomingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit);
List<Event> incomingEvents = cassandraEventsRepository.findIncomingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit);
LOGGER.info("\tIncoming events: {}", incomingEvents.size());

for (Event event : incomingEvents) {
Expand All @@ -85,7 +85,7 @@ private void process(Tenant tenant, Application application, Instant startInstan
LOGGER.info("\tCompleted!");
}

List<Event> outgoingEvents = cassandraEventsRepository.findOutgoingBy(tenant, application, deviceGuid, channel, startInstant, endInstant, ascending, limit);
List<Event> outgoingEvents = cassandraEventsRepository.findOutgoingBy(tenant, application, deviceGuid, null, channel, startInstant, endInstant, ascending, limit);
LOGGER.info("\tOutgoing events: {}", outgoingEvents.size());

for (Event event : outgoingEvents) {
Expand Down
Loading

0 comments on commit 3a4d02f

Please sign in to comment.