/** * {@inheritDoc} */ @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestReserveNowCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestReserveNowCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { RequestReserveNowApiCommand command = gson.fromJson(commandObject, RequestReserveNowApiCommand.class); commandGateway.send(new RequestReserveNowCommand(csId, command.getEvseId(), command.getIdentifyingToken(), command.getExpiryDate(), null, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to request a reservation on a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Reserve now command is not able to parse the payload, is your json correctly formatted?", ex); } } }