@Test public void testHandleComplete() throws UserIdentityUnauthorizedException { JsonObject commandObject = gson.fromJson("{'configuration' : {'evses' : [{'evseId' : 1, 'connectors' : [{'maxAmp': 32, 'phase': 3, 'voltage': 230, 'chargingProtocol': 'MODE3', 'current': 'AC', 'connectorType': 'TESLA'}]}], 'settings' : {'key':'value', 'key2':'value2'}}}", JsonObject.class); handler.handle(OperatorApiJsonTestUtils.UNREGISTERED_CHARGING_STATION_ID_STRING, commandObject, ROOT_IDENTITY_CONTEXT); }
@Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStation chargingStation = repository.findOne(chargingStationId); ChargingStationId csId = new ChargingStationId(chargingStationId); if (chargingStation == null) { if (!userIdentitiesWithAllPermissions.contains(identityContext.getUserIdentity())) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), CreateAndAcceptChargingStationCommand.class); } commandGateway.send(new CreateAndAcceptChargingStationCommand(csId, userIdentitiesWithAllPermissions, identityContext)); } else if (!chargingStation.isAccepted()) { if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class); } commandGateway.send(new AcceptChargingStationCommand(csId, identityContext)); } else { throw new IllegalStateException(String.format("Charging station { %s } is already in accepted state, you can't register this station", chargingStationId)); } }
AcceptChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStation chargingStation = repository.findOne(chargingStationId); ChargingStationId csId = new ChargingStationId(chargingStationId); if (chargingStation == null) { if (!userIdentitiesWithAllPermissions.contains(identityContext.getUserIdentity())) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), CreateAndAcceptChargingStationCommand.class); } commandGateway.send(new CreateAndAcceptChargingStationCommand(csId, userIdentitiesWithAllPermissions, identityContext)); } else if (!chargingStation.isAccepted()) { if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class); } commandGateway.send(new AcceptChargingStationCommand(csId, identityContext)); } else { throw new IllegalStateException(String.format("Charging station { %s } is already in accepted state, you can't register this station", chargingStationId)); } } }
AcceptChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStation chargingStation = repository.findOne(chargingStationId); ChargingStationId csId = new ChargingStationId(chargingStationId); if (chargingStation == null) { if (!userIdentitiesWithAllPermissions.contains(identityContext.getUserIdentity())) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), CreateAndAcceptChargingStationCommand.class); } commandGateway.send(new CreateAndAcceptChargingStationCommand(csId, userIdentitiesWithAllPermissions, identityContext)); } else if (!chargingStation.isAccepted()) { if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class); } commandGateway.send(new AcceptChargingStationCommand(csId, identityContext)); } else { throw new IllegalStateException(String.format("Charging station { %s } is already in accepted state, you can't register this station", chargingStationId)); } }  }
AcceptChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStation chargingStation = repository.findOne(chargingStationId); ChargingStationId csId = new ChargingStationId(chargingStationId); if (chargingStation == null) { if (!userIdentitiesWithAllPermissions.contains(identityContext.getUserIdentity())) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), CreateAndAcceptChargingStationCommand.class); } commandGateway.send(new CreateAndAcceptChargingStationCommand(csId, userIdentitiesWithAllPermissions, identityContext)); } else if (!chargingStation.isAccepted()) { if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class); } commandGateway.send(new AcceptChargingStationCommand(csId, identityContext)); } else { throw new IllegalStateException(String.format("Charging station { %s } is already in accepted state, you can't register this station", chargingStationId)); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext); void setUserIdentitiesWithAllPermissions(Set<UserIdentity> userIdentitiesWithAllPermissions); }
AcceptChargingStationJsonCommandHandler extends JsonCommandHandler { @Override public void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext) throws UserIdentityUnauthorizedException { ChargingStation chargingStation = repository.findOne(chargingStationId); ChargingStationId csId = new ChargingStationId(chargingStationId); if (chargingStation == null) { if (!userIdentitiesWithAllPermissions.contains(identityContext.getUserIdentity())) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), CreateAndAcceptChargingStationCommand.class); } commandGateway.send(new CreateAndAcceptChargingStationCommand(csId, userIdentitiesWithAllPermissions, identityContext)); } else if (!chargingStation.isAccepted()) { if (!commandAuthorizationService.isAuthorized(csId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), AcceptChargingStationCommand.class); } commandGateway.send(new AcceptChargingStationCommand(csId, identityContext)); } else { throw new IllegalStateException(String.format("Charging station { %s } is already in accepted state, you can't register this station", chargingStationId)); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext); void setUserIdentitiesWithAllPermissions(Set<UserIdentity> userIdentitiesWithAllPermissions);  }