@CommandHandler public void handle(RequestReserveNowCommand command, MetaData metaData) { checkCommandAllowed(command.getIdentityContext(), command.getClass()); checkCommunicationAllowed(); if (isReservable) { apply(new ReserveNowRequestedEvent(command.getChargingStationId(), this.protocol, command.getEvseId(), command.getIdentifyingToken(), command.getExpiryDate(), command.getParentIdentifyingToken(), command.getIdentityContext()), metaData); } else { apply(new ReserveNowRequestedForUnreservableChargingStationEvent(command.getChargingStationId(), command.getEvseId(), command.getIdentifyingToken(), command.getExpiryDate(), command.getParentIdentifyingToken(), command.getIdentityContext())); } }
/** * {@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); } } }