@Override public IDeviceLocation addDeviceLocation(String assignmentToken, IDeviceLocationCreateRequest request) throws SiteWhereException { IDeviceAssignment assignment = assertApiDeviceAssignment(assignmentToken); DeviceLocation location = SiteWherePersistence.deviceLocationCreateLogic(assignment, request); MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document locObject = MongoDeviceLocation.toDocument(location, false); MongoPersistence.insertEvent(events, locObject, isUseBulkEventInserts(), getEventBuffer()); // Update assignment state if requested. location = MongoDeviceLocation.fromDocument(locObject, false); if (request.isUpdateState()) { getAssignmentStateManager().addLocation(assignmentToken, location); } return location; }
/** * Create a new device location entry for an assignment. * * @param context * @param assignment * @param request * @return * @throws SiteWhereException */ public static IDeviceLocation createDeviceLocation(IHBaseContext context, IDeviceAssignment assignment, IDeviceLocationCreateRequest request) throws SiteWhereException { long time = getEventTime(request); byte[] rowkey = getEventRowKey(context, assignment, time); byte[] qualifier = getQualifier(EventRecordType.Location, time, context.getPayloadMarshaler().getEncoding()); DeviceLocation location = SiteWherePersistence.deviceLocationCreateLogic(assignment, request); String id = getEncodedEventId(rowkey, qualifier); location.setId(id); byte[] payload = context.getPayloadMarshaler().encodeDeviceLocation(location); Put put = new Put(rowkey); put.addColumn(ISiteWhereHBase.FAMILY_ID, qualifier, payload); context.getDeviceEventBuffer().add(put); // Update state if requested. if (request.isUpdateState()) { context.getAssignmentStateManager().addLocation(assignment.getToken(), location); } return location; }