@Override public IDeviceCommandResponse addDeviceCommandResponse(String assignmentToken, IDeviceCommandResponseCreateRequest request) throws SiteWhereException { IDeviceAssignment assignment = assertApiDeviceAssignment(assignmentToken); DeviceCommandResponse response = SiteWherePersistence.deviceCommandResponseCreateLogic(assignment, request); MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document dbresponse = MongoDeviceCommandResponse.toDocument(response); MongoPersistence.insertEvent(events, dbresponse, isUseBulkEventInserts(), getEventBuffer()); return MongoDeviceCommandResponse.fromDocument(dbresponse); }
/** * Create a device command response. * * @param context * @param assignment * @param request * @return * @throws SiteWhereException */ public static IDeviceCommandResponse createDeviceCommandResponse(IHBaseContext context, IDeviceAssignment assignment, IDeviceCommandResponseCreateRequest request) throws SiteWhereException { long time = getEventTime(request); byte[] rowkey = getEventRowKey(context, assignment, time); byte[] qualifier = getQualifier(EventRecordType.CommandResponse, time, context.getPayloadMarshaler().getEncoding()); // Create a state change and marshal to JSON. DeviceCommandResponse cr = SiteWherePersistence.deviceCommandResponseCreateLogic(assignment, request); String id = getEncodedEventId(rowkey, qualifier); cr.setId(id); byte[] payload = context.getPayloadMarshaler().encodeDeviceCommandResponse(cr); Put put = new Put(rowkey); put.addColumn(ISiteWhereHBase.FAMILY_ID, qualifier, payload); context.getDeviceEventBuffer().add(put); linkDeviceCommandResponseToInvocation(context, cr); return cr; }