/** * Convert device state change create request from API to GRPC. * * @param api * @return * @throws SiteWhereException */ public static GDeviceStateChangeCreateRequest asGrpcDeviceStateChangeCreateRequest( IDeviceStateChangeCreateRequest api) throws SiteWhereException { GDeviceStateChangeCreateRequest.Builder grpc = GDeviceStateChangeCreateRequest.newBuilder(); grpc.setAttribute(api.getAttribute()); grpc.setType(api.getType()); if (api.getPreviousState() != null) { grpc.setPreviousState(GOptionalString.newBuilder().setValue(api.getPreviousState())); } if (api.getNewState() != null) { grpc.setNewState(GOptionalString.newBuilder().setValue(api.getNewState())); } grpc.setEvent(EventModelConverter.createGrpcDeviceEventCreateRequest(api)); return grpc.build(); }
/** * Common logic for creating a {@link DeviceStateChange} from an * {@link IDeviceStateChangeCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceStateChange deviceStateChangeCreateLogic(IDeviceAssignment assignment, IDeviceStateChangeCreateRequest request) throws SiteWhereException { if (request.getCategory() == null) { throw new SiteWhereSystemException(ErrorCode.IncompleteData, ErrorLevel.ERROR); } if (request.getType() == null) { throw new SiteWhereSystemException(ErrorCode.IncompleteData, ErrorLevel.ERROR); } DeviceStateChange state = new DeviceStateChange(); deviceEventCreateLogic(request, assignment, state); state.setCategory(request.getCategory()); state.setType(request.getType()); state.setPreviousState(request.getPreviousState()); state.setNewState(request.getNewState()); if (request.getData() != null) { state.getData().putAll(request.getData()); } return state; }
/** * Common logic for creating a {@link DeviceStateChange} from an * {@link IDeviceStateChangeCreateRequest}. * * @param assignment * @param request * @return * @throws SiteWhereException */ public static DeviceStateChange deviceStateChangeCreateLogic(IDeviceAssignment assignment, IDeviceStateChangeCreateRequest request) throws SiteWhereException { require("Attribute", request.getAttribute()); require("Type", request.getType()); DeviceStateChange state = new DeviceStateChange(); deviceEventCreateLogic(request, assignment, state); state.setAttribute(request.getAttribute()); state.setType(request.getType()); state.setPreviousState(request.getPreviousState()); state.setNewState(request.getNewState()); return state; } }