mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-31 23:32:26 +00:00
[AB-167] adding warning created events and infraction counter
adding disabling of post targets adding some logging for message sending failure consumer
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package dev.sheldan.abstracto.core.commands.channels;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class DisablePostTarget extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String targetName = (String) commandContext.getParameters().getParameters().get(0);
|
||||
if(!postTargetService.validPostTarget(targetName)) {
|
||||
throw new PostTargetNotValidException(targetName, postTargetService.getAvailablePostTargets());
|
||||
}
|
||||
postTargetService.disablePostTarget(targetName, commandContext.getGuild().getIdLong());
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter postTargetName = Parameter
|
||||
.builder()
|
||||
.name("name")
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
List<Parameter> parameters = Arrays.asList(postTargetName);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("disablePosttarget")
|
||||
.module(ChannelsModuleDefinition.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package dev.sheldan.abstracto.core.commands.channels;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.condition.AbstractConditionableCommand;
|
||||
import dev.sheldan.abstracto.core.command.config.CommandConfiguration;
|
||||
import dev.sheldan.abstracto.core.command.config.HelpInfo;
|
||||
import dev.sheldan.abstracto.core.command.config.Parameter;
|
||||
import dev.sheldan.abstracto.core.command.config.features.CoreFeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandContext;
|
||||
import dev.sheldan.abstracto.core.command.execution.CommandResult;
|
||||
import dev.sheldan.abstracto.core.config.FeatureDefinition;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
|
||||
import dev.sheldan.abstracto.core.service.PostTargetService;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@Component
|
||||
public class EnablePostTarget extends AbstractConditionableCommand {
|
||||
|
||||
@Autowired
|
||||
private PostTargetService postTargetService;
|
||||
|
||||
@Override
|
||||
public CommandResult execute(CommandContext commandContext) {
|
||||
String targetName = (String) commandContext.getParameters().getParameters().get(0);
|
||||
if(!postTargetService.validPostTarget(targetName)) {
|
||||
throw new PostTargetNotValidException(targetName, postTargetService.getAvailablePostTargets());
|
||||
}
|
||||
postTargetService.enablePostTarget(targetName, commandContext.getGuild().getIdLong());
|
||||
return CommandResult.fromSuccess();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommandConfiguration getConfiguration() {
|
||||
Parameter postTargetName = Parameter
|
||||
.builder()
|
||||
.name("name")
|
||||
.type(String.class)
|
||||
.templated(true)
|
||||
.build();
|
||||
List<Parameter> parameters = Arrays.asList(postTargetName);
|
||||
HelpInfo helpInfo = HelpInfo
|
||||
.builder()
|
||||
.templated(true)
|
||||
.build();
|
||||
return CommandConfiguration.builder()
|
||||
.name("enablePosttarget")
|
||||
.module(ChannelsModuleDefinition.CHANNELS)
|
||||
.parameters(parameters)
|
||||
.supportsEmbedException(true)
|
||||
.help(helpInfo)
|
||||
.templated(true)
|
||||
.causesReaction(true)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public FeatureDefinition getFeature() {
|
||||
return CoreFeatureDefinition.CORE_FEATURE;
|
||||
}
|
||||
}
|
||||
@@ -62,14 +62,25 @@ public class PostTargetCommand extends AbstractConditionableCommand {
|
||||
List<PostTargetModelEntry> postTargetEntries = posttargetDisplayModel.getPostTargets();
|
||||
postTargets.forEach(target -> {
|
||||
Optional<TextChannel> channelFromAChannel = channelService.getChannelFromAChannel(target.getChannelReference());
|
||||
PostTargetModelEntry targetEntry = PostTargetModelEntry.builder().channel(channelFromAChannel.orElse(null)).postTarget(target).build();
|
||||
PostTargetModelEntry targetEntry = PostTargetModelEntry
|
||||
.builder()
|
||||
.channel(channelFromAChannel.orElse(null))
|
||||
.disabled(target.getDisabled())
|
||||
.postTarget(target).build();
|
||||
postTargetEntries.add(targetEntry);
|
||||
});
|
||||
List<String> postTargetConfigs = postTargetService.getPostTargetsOfEnabledFeatures(server);
|
||||
postTargetConfigs.forEach(postTargetName -> {
|
||||
if(postTargetEntries.stream().noneMatch(postTargetModelEntry -> postTargetModelEntry.getPostTarget().getName().equalsIgnoreCase(postTargetName))) {
|
||||
PostTarget fakeEntry = PostTarget.builder().name(postTargetName).build();
|
||||
PostTargetModelEntry postTargetEntry = PostTargetModelEntry.builder().postTarget(fakeEntry).build();
|
||||
PostTarget fakeEntry = PostTarget
|
||||
.builder()
|
||||
.name(postTargetName)
|
||||
.build();
|
||||
PostTargetModelEntry postTargetEntry = PostTargetModelEntry
|
||||
.builder()
|
||||
.postTarget(fakeEntry)
|
||||
.disabled(false)
|
||||
.build();
|
||||
postTargetEntries.add(postTargetEntry);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -4,6 +4,7 @@ import dev.sheldan.abstracto.core.config.FeatureConfig;
|
||||
import dev.sheldan.abstracto.core.config.PostTargetEnum;
|
||||
import dev.sheldan.abstracto.core.exception.ChannelNotInGuildException;
|
||||
import dev.sheldan.abstracto.core.exception.GuildNotFoundException;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetNotUsableException;
|
||||
import dev.sheldan.abstracto.core.exception.PostTargetNotValidException;
|
||||
import dev.sheldan.abstracto.core.models.database.AServer;
|
||||
import dev.sheldan.abstracto.core.models.database.PostTarget;
|
||||
@@ -22,6 +23,7 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
|
||||
@@ -52,15 +54,25 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTarget target) {
|
||||
log.debug("Sending text to post target {}.", target.getName());
|
||||
return channelService.sendTextToAChannel(text, target.getChannelReference());
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
log.debug("Sending text to post target {}.", target.getName());
|
||||
return channelService.sendTextToAChannel(text, target.getChannelReference());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTarget target) {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
log.debug("Sending message embed to post target {}.", target.getName());
|
||||
return channelService.sendEmbedToChannel(embed, textChannelForPostTarget);
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
log.debug("Sending message embed to post target {}.", target.getName());
|
||||
return channelService.sendEmbedToChannel(embed, textChannelForPostTarget);
|
||||
}
|
||||
}
|
||||
|
||||
private TextChannel getTextChannelForPostTarget(PostTarget target) {
|
||||
@@ -81,110 +93,145 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendTextInPostTarget(String text, PostTargetEnum postTargetEnum, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetEnum, serverId);
|
||||
return this.sendTextInPostTarget(text, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetEnum, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return this.sendTextInPostTarget(text, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendEmbedInPostTarget(MessageEmbed embed, PostTargetEnum postTargetName, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetName, serverId);
|
||||
return this.sendEmbedInPostTarget(embed, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return this.sendEmbedInPostTarget(embed, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageInPostTarget(Message message, PostTargetEnum postTargetName, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetName, serverId);
|
||||
return sendMessageInPostTarget(message, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return CompletableFuture.completedFuture(null);
|
||||
}
|
||||
return sendMessageInPostTarget(message, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Message> sendMessageInPostTarget(Message message, PostTarget target) {
|
||||
log.debug("Send message {} towards post target {}.", message.getId(), target.getName());
|
||||
return channelService.sendMessageToAChannel(message, target.getChannelReference());
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return CompletableFuture.completedFuture(null);
|
||||
} else {
|
||||
log.debug("Send message {} towards post target {}.", message.getId(), target.getName());
|
||||
return channelService.sendMessageToAChannel(message, target.getChannelReference());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetName, serverId);
|
||||
return this.sendEmbedInPostTarget(message, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return this.sendEmbedInPostTarget(message, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> sendEmbedInPostTarget(MessageToSend message, PostTarget target) {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
log.debug("Send messageToSend towards post target {}.", target.getName());
|
||||
return channelService.sendMessageToSendToChannel(message, textChannelForPostTarget);
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
log.debug("Send messageToSend towards post target {}.", target.getName());
|
||||
return channelService.sendMessageToSendToChannel(message, textChannelForPostTarget);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTarget target) {
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
// always takes the first one, only applicable for this scenario
|
||||
String messageText = message.getMessages().get(0);
|
||||
if(StringUtils.isBlank(messageText)) {
|
||||
log.debug("Editing embeds of message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), textChannelForPostTarget, messageId));
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
log.debug("Editing message text and potentially text for message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), textChannelForPostTarget, messageId));
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
// always takes the first one, only applicable for this scenario
|
||||
String messageText = message.getMessages().get(0);
|
||||
if(StringUtils.isBlank(messageText)) {
|
||||
log.debug("Editing embeds of message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editEmbedMessageInAChannel(message.getEmbeds().get(0), textChannelForPostTarget, messageId));
|
||||
} else {
|
||||
log.debug("Editing message text and potentially text for message {} in post target {}.", messageId, target.getName());
|
||||
return Arrays.asList(channelService.editTextMessageInAChannel(messageText, message.getEmbeds().get(0), textChannelForPostTarget, messageId));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTarget target) {
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
CompletableFuture<Message> messageEditFuture = new CompletableFuture<>();
|
||||
futures.add(messageEditFuture);
|
||||
if(StringUtils.isBlank(messageToSend.getMessages().get(0).trim())) {
|
||||
channelService.retrieveMessageInChannel(textChannelForPostTarget, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message embeds in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when upserting message embeds for message {} in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
if(target.getDisabled()) {
|
||||
log.info("Post target {} has been disabled in server {} - not sending message.", target.getName(), target.getServerReference().getId());
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
} else {
|
||||
List<CompletableFuture<Message>> futures = new ArrayList<>();
|
||||
TextChannel textChannelForPostTarget = getTextChannelForPostTarget(target);
|
||||
CompletableFuture<Message> messageEditFuture = new CompletableFuture<>();
|
||||
futures.add(messageEditFuture);
|
||||
if (StringUtils.isBlank(messageToSend.getMessages().get(0).trim())) {
|
||||
channelService.retrieveMessageInChannel(textChannelForPostTarget, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message embeds in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when upserting message embeds for message {} in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
} else {
|
||||
channelService.retrieveMessageInChannel(textChannelForPostTarget, messageId).thenAccept(message -> {
|
||||
} else {
|
||||
channelService.retrieveMessageInChannel(textChannelForPostTarget, messageId).thenAccept(message -> {
|
||||
log.debug("Editing existing message {} when upserting message in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
messageService.editMessage(message, messageToSend.getMessages().get(0), messageToSend.getEmbeds().get(0))
|
||||
.queue(messageEditFuture::complete, messageEditFuture::completeExceptionally);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when trying to upsert a message {} in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
}).exceptionally(throwable -> {
|
||||
log.debug("Creating new message when trying to upsert a message {} in channel {} in server {}.",
|
||||
messageId, textChannelForPostTarget.getIdLong(), textChannelForPostTarget.getGuild().getId());
|
||||
sendEmbedInPostTarget(messageToSend, target).get(0)
|
||||
.thenAccept(messageEditFuture::complete).exceptionally(innerThrowable -> {
|
||||
log.error("Failed to send message to create a message.", innerThrowable);
|
||||
messageEditFuture.completeExceptionally(innerThrowable);
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
return null;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return futures;
|
||||
return futures;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editOrCreatedInPostTarget(Long messageId, MessageToSend messageToSend, PostTargetEnum postTargetName, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetName, serverId);
|
||||
return this.editOrCreatedInPostTarget(messageId, messageToSend, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return this.editOrCreatedInPostTarget(messageId, messageToSend, postTargetOptional.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void throwIfPostTargetIsNotDefined(PostTargetEnum name, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(name, serverId);
|
||||
if(postTarget == null) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
throw new PostTargetNotValidException(name.getKey(), defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
}
|
||||
}
|
||||
@@ -196,12 +243,15 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
|
||||
@Override
|
||||
public List<CompletableFuture<Message>> editEmbedInPostTarget(Long messageId, MessageToSend message, PostTargetEnum postTargetName, Long serverId) {
|
||||
PostTarget postTarget = getPostTarget(postTargetName, serverId);
|
||||
return editEmbedInPostTarget(messageId, message, postTarget);
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(postTargetName, serverId);
|
||||
if(!postTargetOptional.isPresent()) {
|
||||
return Arrays.asList(CompletableFuture.completedFuture(null));
|
||||
}
|
||||
return editEmbedInPostTarget(messageId, message, postTargetOptional.get());
|
||||
}
|
||||
|
||||
private PostTarget getPostTarget(PostTargetEnum postTargetEnum, Long serverId) {
|
||||
return postTargetManagement.getPostTarget(postTargetEnum.getKey(), serverId);
|
||||
private Optional<PostTarget> getPostTarget(PostTargetEnum postTargetEnum, Long serverId) {
|
||||
return postTargetManagement.getPostTargetOptional(postTargetEnum.getKey(), serverId);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -210,6 +260,19 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
return possiblePostTargets.contains(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validatePostTarget(PostTargetEnum name, Long serverId) {
|
||||
if(!postTargetUsableInServer(name, serverId)) {
|
||||
throw new PostTargetNotUsableException(name.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean postTargetUsableInServer(PostTargetEnum name, Long serverId) {
|
||||
Optional<PostTarget> postTargetOptional = getPostTarget(name, serverId);
|
||||
return postTargetOptional.isPresent() && !postTargetOptional.get().getDisabled();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<PostTarget> getPostTargets(AServer server) {
|
||||
return postTargetManagement.getPostTargetsInServer(server);
|
||||
@@ -231,4 +294,16 @@ public class PostTargetServiceBean implements PostTargetService {
|
||||
});
|
||||
return postTargets;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void disablePostTarget(String name, Long serverId) {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
|
||||
postTarget.setDisabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void enablePostTarget(String name, Long serverId) {
|
||||
PostTarget postTarget = postTargetManagement.getPostTarget(name, serverId);
|
||||
postTarget.setDisabled(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,13 @@ public class PostTargetManagementBean implements PostTargetManagement {
|
||||
throw new PostTargetNotValidException(name, defaultPostTargetManagementService.getDefaultPostTargetKeys());
|
||||
}
|
||||
log.info("Creating post target {} pointing towards {} on server {}.", name, targetChannel.getId(), targetChannel.getServer().getId());
|
||||
PostTarget createdPostTarget = PostTarget.builder().name(name).channelReference(targetChannel).serverReference(targetChannel.getServer()).build();
|
||||
PostTarget createdPostTarget = PostTarget
|
||||
.builder()
|
||||
.name(name)
|
||||
.channelReference(targetChannel)
|
||||
.serverReference(targetChannel.getServer())
|
||||
.disabled(false)
|
||||
.build();
|
||||
return postTargetRepository.save(createdPostTarget);
|
||||
}
|
||||
|
||||
@@ -75,7 +81,8 @@ public class PostTargetManagementBean implements PostTargetManagement {
|
||||
|
||||
@Override
|
||||
public PostTarget getPostTarget(String name, AServer server) {
|
||||
return postTargetRepository.findPostTargetByNameAndServerReference(name, server).orElseThrow(() -> new PostTargetNotFoundException(name));
|
||||
return postTargetRepository.findPostTargetByNameAndServerReference(name, server)
|
||||
.orElseThrow(() -> new PostTargetNotFoundException(name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,4 +7,5 @@
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd">
|
||||
<include file="seedData/data.xml" relativeToChangelogFile="true"/>
|
||||
<include file="tables/tables.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<property name="coreFeature" value="(SELECT id FROM feature WHERE key = 'core')"/>
|
||||
<property name="channelsModule" value="(SELECT id FROM module WHERE name = 'channels')"/>
|
||||
<changeSet author="Sheldan" id="disable_posttarget-command" >
|
||||
<insert tableName="command">
|
||||
<column name="name" value="disablePosttarget"/>
|
||||
<column name="module_id" valueComputed="${channelsModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
</insert>
|
||||
<insert tableName="command">
|
||||
<column name="name" value="enablePosttarget"/>
|
||||
<column name="module_id" valueComputed="${channelsModule}"/>
|
||||
<column name="feature_id" valueComputed="${coreFeature}"/>
|
||||
</insert>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -7,4 +7,5 @@
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="confirmationCleanupJob.xml" relativeToChangelogFile="true"/>
|
||||
<include file="command.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<changeSet author="Sheldan" id="post_target-addDisabled">
|
||||
<addColumn tableName="posttarget">
|
||||
<column name="disabled" type="BOOLEAN" defaultValueBoolean="false"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.1" encoding="UTF-8" standalone="no"?>
|
||||
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
|
||||
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
|
||||
xmlns:pro="http://www.liquibase.org/xml/ns/pro"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext dbchangelog.xsd
|
||||
http://www.liquibase.org/xml/ns/pro dbchangelog.xsd" >
|
||||
<include file="post_target.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
Reference in New Issue
Block a user