/** * Convert event type from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceEventType asGrpcDeviceEventType(DeviceEventType api) throws SiteWhereException { switch (api) { case Alert: return GDeviceEventType.EVENT_TYPE_ALERT; case CommandInvocation: return GDeviceEventType.EVENT_TYPE_COMMAND_INVOCATION; case CommandResponse: return GDeviceEventType.EVENT_TYPE_COMMAND_RESPONSE; case Location: return GDeviceEventType.EVENT_TYPE_LOCATION; case Measurement: return GDeviceEventType.EVENT_TYPE_MEASUREMENT; case StateChange: return GDeviceEventType.EVENT_TYPE_STATE_CHANGE; } throw new SiteWhereException("Unknown event type: " + api.name()); }
Map<String, Object> valueMap = getValueMap(series, values); String eventType = (String) valueMap.get(EVENT_TYPE); DeviceEventType type = DeviceEventType.valueOf(eventType); if (type == null) { throw new SiteWhereException("Unknown event type: " + type);
throw new SiteWhereException("Event matched but did not contain event type field."); DeviceEventType eventType = DeviceEventType.valueOf(type); if (eventType == null) { throw new SiteWhereException("Event type not recognized: " + type);
throw new SiteWhereException("Unsupported event type: " + type.name());
throw new SiteWhereException("Event matched but did not contain event type field."); DeviceEventType eventType = DeviceEventType.valueOf(type); if (eventType == null) { throw new SiteWhereException("Event type not recognized: " + type);
@Override public SearchResults<IDeviceLocation> listDeviceLocationsForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Location.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceLocation.class, events, query, sort, criteria, LOOKUP); }
target.setEventType(DeviceEventType.valueOf(eventType));
@Override public SearchResults<IDeviceAlert> listDeviceAlertsForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Alert.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceAlert.class, events, query, sort, criteria, LOOKUP); }
target.setEventType(DeviceEventType.valueOf(eventType));
@Override public ISearchResults<IDeviceCommandResponse> listDeviceCommandInvocationResponses(UUID invocationId) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandResponse.name()) .append(MongoDeviceCommandResponse.PROP_ORIGINATING_EVENT_ID, invocationId); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceCommandResponse.class, events, query, sort, LOOKUP); }
@Override public ISearchResults<IDeviceCommandResponse> listDeviceCommandResponsesForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandResponse.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceCommandResponse.class, events, query, sort, criteria, LOOKUP); }
@Override public SearchResults<IDeviceMeasurement> listDeviceMeasurementsForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Measurement.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceMeasurement.class, events, query, sort, criteria, LOOKUP); }
@Override public ISearchResults<IDeviceCommandInvocation> listDeviceCommandInvocationsForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandInvocation.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceCommandInvocation.class, events, query, sort, criteria, LOOKUP); }
@Override public ISearchResults<IDeviceStateChange> listDeviceStateChangesForIndex(DeviceEventIndex index, List<UUID> entityIds, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(); Document query = new Document(getFieldForIndex(index), new Document("$in", entityIds)) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.StateChange.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1); return MongoPersistence.search(IDeviceStateChange.class, events, query, sort, criteria, LOOKUP); }
@Override public ISearchResults<IDeviceCommandResponse> listDeviceCommandInvocationResponses(String invocationId) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document query = new Document(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandResponse.name()) .append(MongoDeviceCommandResponse.PROP_ORIGINATING_EVENT_ID, invocationId); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1).append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1); return MongoPersistence.search(IDeviceCommandResponse.class, events, query, sort); }
/** * Get a query for counting events of a given type associated with one or more * entities for a given index and that meet the search criteria. * * @param index * @param type * @param entityIds * @param criteria * @param database * @return * @throws SiteWhereException */ protected static Query queryEventsOfTypeForIndexCount(DeviceEventIndex index, DeviceEventType type, List<UUID> entityIds, ISearchCriteria criteria, String database) throws SiteWhereException { return new Query( "SELECT count(" + EVENT_ID + ") FROM " + InfluxDbDeviceEvent.COLLECTION_EVENTS + " where type='" + type.name() + "' and " + buildInClause(index, entityIds) + buildDateRangeCriteria(criteria), database); }
@Override public SearchResults<IDeviceLocation> listDeviceLocations(List<String> assignmentTokens, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document query = new Document(); query.put(MongoDeviceEvent.PROP_DEVICE_ASSIGNMENT_TOKEN, new BasicDBObject("$in", assignmentTokens)); query.append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Location.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1).append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1); return MongoPersistence.search(IDeviceLocation.class, events, query, sort, criteria); }
@Override public SearchResults<IDeviceLocation> listDeviceLocations(String assignmentToken, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document query = new Document(MongoDeviceEvent.PROP_DEVICE_ASSIGNMENT_TOKEN, assignmentToken) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.Location.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1).append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1); return MongoPersistence.search(IDeviceLocation.class, events, query, sort, criteria); }
@Override public ISearchResults<IDeviceCommandResponse> listDeviceCommandResponses(String assignmentToken, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document query = new Document(MongoDeviceEvent.PROP_DEVICE_ASSIGNMENT_TOKEN, assignmentToken) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandResponse.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1).append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1); return MongoPersistence.search(IDeviceCommandResponse.class, events, query, sort, criteria); }
@Override public ISearchResults<IDeviceCommandResponse> listDeviceCommandResponsesForSite(String siteToken, IDateRangeSearchCriteria criteria) throws SiteWhereException { MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document query = new Document(MongoDeviceEvent.PROP_SITE_TOKEN, siteToken) .append(MongoDeviceEvent.PROP_EVENT_TYPE, DeviceEventType.CommandResponse.name()); MongoPersistence.addDateSearchCriteria(query, MongoDeviceEvent.PROP_EVENT_DATE, criteria); Document sort = new Document(MongoDeviceEvent.PROP_EVENT_DATE, -1).append(MongoDeviceEvent.PROP_RECEIVED_DATE, -1); return MongoPersistence.search(IDeviceCommandResponse.class, events, query, sort, criteria); }