use of me.retrodaredevil.solarthing.packets.collection.PacketCollection in project solarthing by wildmountainfarms.
the class CancelCommandChatBotHandler method cancelCommand.
private void cancelCommand(MessageSender messageSender, UUID schedulingId) {
List<VersionedPacket<StoredAlterPacket>> packets = alterPacketsProvider.getPackets();
if (packets == null) {
messageSender.sendMessage("Unable to cancel commands, as we are unable to reach the alter database.");
return;
}
List<VersionedPacket<StoredAlterPacket>> targets = findStoredPacketsWithSchedulingIdOrNull(packets.stream(), schedulingId);
if (targets.isEmpty()) {
messageSender.sendMessage("Unable to find a scheduled command that was scheduled with the ID of " + schedulingId);
} else if (targets.size() > 1) {
messageSender.sendMessage("Multiple packets corresponded to ID: " + schedulingId + ". Please report this error.");
} else {
VersionedPacket<StoredAlterPacket> target = targets.get(0);
messageSender.sendMessage("Going request cancel of " + target.getPacket().getDbId());
CommandOpenPacket packet = new ImmutableDeleteAlterPacket(target.getPacket().getDbId(), target.getUpdateToken());
PacketCollectionCreator creator = commandHelper.getCommandManager().makeCreator(sourceId, zoneId, null, packet, PacketCollectionIdGenerator.Defaults.UNIQUE_GENERATOR);
executorService.execute(() -> {
Instant now = Instant.now();
PacketCollection packetCollection = creator.create(now);
boolean success = true;
try {
database.getOpenDatabase().uploadPacketCollection(packetCollection, null);
} catch (SolarThingDatabaseException e) {
LOGGER.error("Could not upload alter delete request", e);
success = false;
}
if (success) {
messageSender.sendMessage("Sent request to delete the scheduled command");
} else {
messageSender.sendMessage("Could not upload request to delete scheduled command. You can try again.");
}
});
}
}
Aggregations