@Override public IDeviceCommandInvocation addDeviceCommandInvocation(String assignmentToken, IDeviceCommand command, IDeviceCommandInvocationCreateRequest request) throws SiteWhereException { IDeviceAssignment assignment = assertApiDeviceAssignment(assignmentToken); DeviceCommandInvocation ci = SiteWherePersistence.deviceCommandInvocationCreateLogic(assignment, command, request); MongoCollection<Document> events = getMongoClient().getEventsCollection(getTenant()); Document ciObject = MongoDeviceCommandInvocation.toDocument(ci); MongoPersistence.insertEvent(events, ciObject, isUseBulkEventInserts(), getEventBuffer()); return MongoDeviceCommandInvocation.fromDocument(ciObject); }
/** * Create a new device command invocation entry for an assignment. * * @param context * @param assignment * @param command * @param request * @return * @throws SiteWhereException */ public static IDeviceCommandInvocation createDeviceCommandInvocation(IHBaseContext context, IDeviceAssignment assignment, IDeviceCommand command, IDeviceCommandInvocationCreateRequest request) throws SiteWhereException { long time = getEventTime(request); byte[] rowkey = getEventRowKey(context, assignment, time); byte[] qualifier = getQualifier(EventRecordType.CommandInvocation, time, context.getPayloadMarshaler().getEncoding()); // Create a command invocation and marshal to JSON. DeviceCommandInvocation ci = SiteWherePersistence.deviceCommandInvocationCreateLogic(assignment, command, request); String id = getEncodedEventId(rowkey, qualifier); ci.setId(id); byte[] payload = context.getPayloadMarshaler().encodeDeviceCommandInvocation(ci); Put put = new Put(rowkey); put.addColumn(ISiteWhereHBase.FAMILY_ID, qualifier, payload); context.getDeviceEventBuffer().add(put); return ci; }