/** * Common logic for creating a {@link DeviceCommandResponse} from an * {@link IDeviceCommandResponseCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceCommandResponse deviceCommandResponseCreateLogic(IDeviceAssignment assignment, IDeviceCommandResponseCreateRequest request) throws SiteWhereException { requireNotNull("Originating Event Id", request.getOriginatingEventId()); DeviceCommandResponse response = new DeviceCommandResponse(); deviceEventCreateLogic(request, assignment, response); response.setOriginatingEventId(request.getOriginatingEventId()); response.setResponseEventId(request.getResponseEventId()); response.setResponse(request.getResponse()); return response; }
/** * Common logic for creating a {@link DeviceCommandResponse} from an * {@link IDeviceCommandResponseCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceCommandResponse deviceCommandResponseCreateLogic(IDeviceAssignment assignment, IDeviceCommandResponseCreateRequest request) throws SiteWhereException { if (request.getOriginatingEventId() == null) { throw new SiteWhereSystemException(ErrorCode.IncompleteData, ErrorLevel.ERROR); } DeviceCommandResponse response = new DeviceCommandResponse(); deviceEventCreateLogic(request, assignment, response); response.setOriginatingEventId(request.getOriginatingEventId()); response.setResponseEventId(request.getResponseEventId()); response.setResponse(request.getResponse()); return response; }
/** * Convert device command response create request from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceCommandResponseCreateRequest asGrpcDeviceCommandResponseCreateRequest( IDeviceCommandResponseCreateRequest api) throws SiteWhereException { GDeviceCommandResponseCreateRequest.Builder grpc = GDeviceCommandResponseCreateRequest.newBuilder(); if (api.getOriginatingEventId() != null) { grpc.setOriginatingEventId(CommonModelConverter.asGrpcUuid(api.getOriginatingEventId())); } if (api.getResponseEventId() != null) { grpc.setResponseEventId(CommonModelConverter.asGrpcUuid(api.getResponseEventId())); } if (api.getResponse() != null) { grpc.setResponse(GOptionalString.newBuilder().setValue(api.getResponse()).build()); } grpc.setEvent(EventModelConverter.createGrpcDeviceEventCreateRequest(api)); return grpc.build(); }