@Test public void handleGrantPermission() throws UserIdentityUnauthorizedException { JsonObject commandObject = gson.fromJson("{'commandClass': 'io.motown.domain.api.chargingstation.CreateChargingStationCommand', 'userIdentity': 'testUser'}", JsonObject.class); handler.handle(CHARGING_STATION_ID_STRING, commandObject, 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(), RevokePermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RevokePermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { RevokePermissionApiCommand command = gson.fromJson(commandObject, RevokePermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new RevokePermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Revoke permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Revoke permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } }
RevokePermissionJsonCommandHandler 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(), RevokePermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RevokePermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { RevokePermissionApiCommand command = gson.fromJson(commandObject, RevokePermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new RevokePermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Revoke permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Revoke permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } } }
RevokePermissionJsonCommandHandler 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(), RevokePermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RevokePermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { RevokePermissionApiCommand command = gson.fromJson(commandObject, RevokePermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new RevokePermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Revoke permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Revoke permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } }  }
RevokePermissionJsonCommandHandler 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(), RevokePermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RevokePermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { RevokePermissionApiCommand command = gson.fromJson(commandObject, RevokePermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new RevokePermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Revoke permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Revoke permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext); }
RevokePermissionJsonCommandHandler 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(), RevokePermissionCommand.class)) { throw new UserIdentityUnauthorizedException(chargingStationId, identityContext.getUserIdentity(), RevokePermissionCommand.class); } try { ChargingStation chargingStation = repository.findOne(chargingStationId); if (chargingStation != null && chargingStation.isAccepted()) { RevokePermissionApiCommand command = gson.fromJson(commandObject, RevokePermissionApiCommand.class); Class commandClass = Class.forName(command.getCommandClass()); UserIdentity userIdentity = new SimpleUserIdentity(command.getUserIdentity()); commandGateway.send(new RevokePermissionCommand(csId, userIdentity, commandClass, identityContext)); } } catch (JsonSyntaxException ex) { throw new IllegalArgumentException("Revoke permission command not able to parse the payload, is your json correctly formatted?", ex); } catch (ClassNotFoundException e) { throw new IllegalArgumentException("Revoke permission command cannot instantiate class object for command class, is the passed command class value a valid class?", e); } }  @Override String getCommandName(); @Override void handle(String chargingStationId, JsonObject commandObject, IdentityContext identityContext);  }