payloadBuilder.setEventDate(GOptionalFixed64.newBuilder().setValue(location.getEventDate().getTime())); payloadBuilder.setLatitude(GOptionalDouble.newBuilder().setValue(location.getLatitude())); payloadBuilder.setLongitude(GOptionalDouble.newBuilder().setValue(location.getLongitude())); payloadBuilder.setElevation(GOptionalDouble.newBuilder().setValue(location.getElevation())); if (location.getMetadata() != null) { payloadBuilder.putAllMetadata(location.getMetadata());
/** * Common logic for creating {@link DeviceLocation} from * {@link IDeviceLocationCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceLocation deviceLocationCreateLogic(IDeviceAssignment assignment, IDeviceLocationCreateRequest request) throws SiteWhereException { DeviceLocation location = new DeviceLocation(); deviceEventCreateLogic(request, assignment, location); location.setLatitude(request.getLatitude()); location.setLongitude(request.getLongitude()); location.setElevation(request.getElevation()); return location; }
if (locReq.getEventDate() == null) { ((DeviceLocationCreateRequest) locReq).setEventDate(new Date());
@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; }
/** * Common logic for creating {@link DeviceLocation} from * {@link IDeviceLocationCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceLocation deviceLocationCreateLogic(IDeviceAssignment assignment, IDeviceLocationCreateRequest request) throws SiteWhereException { DeviceLocation location = new DeviceLocation(); deviceEventCreateLogic(request, assignment, location); location.setLatitude(request.getLatitude()); location.setLongitude(request.getLongitude()); location.setElevation(request.getElevation()); 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; }
Model.DeviceLocation.Builder mb = Model.DeviceLocation.newBuilder(); mb.setHardwareId(event.getHardwareId()); mb.setEventDate(location.getEventDate().getTime()); mb.setLatitude(location.getLatitude()); mb.setLongitude(location.getLongitude()); mb.setElevation(location.getElevation()); if (location.getMetadata() != null) { Set<String> metaKeys = location.getMetadata().keySet(); for (String key : metaKeys) { mb.addMetadata(Model.Metadata.newBuilder().setName(key).setValue(location.getMetadata().get(key))) .build();
/** * Convert device location create request from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceLocationCreateRequest asGrpcDeviceLocationCreateRequest(IDeviceLocationCreateRequest api) throws SiteWhereException { GDeviceLocationCreateRequest.Builder grpc = GDeviceLocationCreateRequest.newBuilder(); if (api.getLatitude() != null) { grpc.setLatitude(GOptionalDouble.newBuilder().setValue(api.getLatitude()).build()); } if (api.getLongitude() != null) { grpc.setLongitude(GOptionalDouble.newBuilder().setValue(api.getLongitude()).build()); } if (api.getElevation() != null) { grpc.setElevation(GOptionalDouble.newBuilder().setValue(api.getElevation()).build()); } grpc.setEvent(EventModelConverter.createGrpcDeviceEventCreateRequest(api)); return grpc.build(); }