@Test(expected = IllegalArgumentException.class) public void testInvalidUpdateType() throws UserIdentityUnauthorizedException { JsonObject commandObject = gson.fromJson("{listVersion:1,updateType:'NEW',items:[{token:'1',status:'ACCEPTED', mobilityServiceProvider:'MSP',visibleId:'7007'},{token:'2',status:'BLOCKED'}]}", JsonObject.class); handler.handle(OperatorApiJsonTestUtils.CHARGING_STATION_ID_STRING, commandObject, ROOT_IDENTITY_CONTEXT); }
@Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class); } try { Set<IdentifyingToken> authorizationList = Sets.newHashSet(); SendAuthorizationListApiCommand command = gson.fromJson(commandObject, SendAuthorizationListApiCommand.class); authorizationList.addAll(command.getItems()); AuthorizationListUpdateType updateType = AuthorizationListUpdateType.valueOf(command.getUpdateType()); ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestSendAuthorizationListCommand(csId, authorizationList, command.getListVersion(), "", updateType, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to send a authorization list to a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("SendAuthorizationList command not able to parse the payload, is your json correctly formatted?", ex); } }
RequestSendAuthorizationListJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class); } try { Set<IdentifyingToken> authorizationList = Sets.newHashSet(); SendAuthorizationListApiCommand command = gson.fromJson(commandObject, SendAuthorizationListApiCommand.class); authorizationList.addAll(command.getItems()); AuthorizationListUpdateType updateType = AuthorizationListUpdateType.valueOf(command.getUpdateType()); ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestSendAuthorizationListCommand(csId, authorizationList, command.getListVersion(), "", updateType, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to send a authorization list to a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("SendAuthorizationList command not able to parse the payload, is your json correctly formatted?", ex); } } }
RequestSendAuthorizationListJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class); } try { Set<IdentifyingToken> authorizationList = Sets.newHashSet(); SendAuthorizationListApiCommand command = gson.fromJson(commandObject, SendAuthorizationListApiCommand.class); authorizationList.addAll(command.getItems()); AuthorizationListUpdateType updateType = AuthorizationListUpdateType.valueOf(command.getUpdateType()); ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestSendAuthorizationListCommand(csId, authorizationList, command.getListVersion(), "", updateType, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to send a authorization list to a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("SendAuthorizationList command not able to parse the payload, is your json correctly formatted?", ex); } }  }
RequestSendAuthorizationListJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class); } try { Set<IdentifyingToken> authorizationList = Sets.newHashSet(); SendAuthorizationListApiCommand command = gson.fromJson(commandObject, SendAuthorizationListApiCommand.class); authorizationList.addAll(command.getItems()); AuthorizationListUpdateType updateType = AuthorizationListUpdateType.valueOf(command.getUpdateType()); ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestSendAuthorizationListCommand(csId, authorizationList, command.getListVersion(), "", updateType, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to send a authorization list to a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("SendAuthorizationList command not able to parse the payload, is your json correctly formatted?", ex); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext); }
RequestSendAuthorizationListJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStationId csId = new ChargingStationId(chargingStationId); if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RequestSendAuthorizationListCommand.class); } try { Set<IdentifyingToken> authorizationList = Sets.newHashSet(); SendAuthorizationListApiCommand command = gson.fromJson(commandObject, SendAuthorizationListApiCommand.class); authorizationList.addAll(command.getItems()); AuthorizationListUpdateType updateType = AuthorizationListUpdateType.valueOf(command.getUpdateType()); ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.communicationAllowed()) { commandGateway.send(new RequestSendAuthorizationListCommand(csId, authorizationList, command.getListVersion(), "", updateType, identityContext), new CorrelationToken()); } else { throw new IllegalStateException("It is not possible to send a authorization list to a charging station that is not registered"); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("SendAuthorizationList command not able to parse the payload, is your json correctly formatted?", ex); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext);  }