/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }
/** * Handle the {@code ProducerSwitchCommand} command. * * @param command */ public ConsumerSwitchResult execute(ConsumerSwitchCommand command) { // query if (command.getStatus() == null) { return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, consumer.getSwitch().getStatus().getValue()); } else if (command.getStatus().equals(SwitchStatus.ON)) { // turn on the switch consumer.getSwitch().turnOn(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.TRUE); } else if (command.getStatus().equals(SwitchStatus.OFF)) { // turn on the switch consumer.getSwitch().turnOff(); // persist the change persist(command.getStatus()); return new ConsumerSwitchResult(command.getId(), Boolean.TRUE, Boolean.FALSE); } else { return new ConsumerSwitchResult(command.getId(), Boolean.FALSE, consumer.getSwitch().getStatus().getValue()); } }