mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-01-28 08:38:52 +00:00
[AB-206] fixing missing command channel group type
fixing not setting the server for creating a command in a channel adding exceptions for incorrect channel group type
This commit is contained in:
@@ -2,6 +2,8 @@ package dev.sheldan.abstracto.core.command;
|
||||
|
||||
public class CommandConstants {
|
||||
|
||||
public static final String COMMAND_CHANNEL_GROUP_KEY = "command";
|
||||
|
||||
private CommandConstants() {
|
||||
|
||||
}
|
||||
|
||||
@@ -34,6 +34,7 @@ public class ChannelGroupCommandManagementServiceBean implements ChannelGroupCom
|
||||
AChannelGroupCommand channelGroupCommand = AChannelGroupCommand
|
||||
.builder()
|
||||
.command(command)
|
||||
.server(group.getServer())
|
||||
.group(group)
|
||||
.enabled(false)
|
||||
.build();
|
||||
|
||||
@@ -19,6 +19,8 @@ import org.springframework.stereotype.Component;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static dev.sheldan.abstracto.core.command.CommandConstants.COMMAND_CHANNEL_GROUP_KEY;
|
||||
|
||||
@Component
|
||||
public class ChannelGroupServiceBean implements ChannelGroupService {
|
||||
|
||||
@@ -95,10 +97,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
|
||||
@Override
|
||||
public void disableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
|
||||
if(channelGroup == null) {
|
||||
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
|
||||
}
|
||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
|
||||
ACommand command = commandManagementService.findCommandByName(commandName);
|
||||
if(command == null) {
|
||||
throw new CommandNotFoundException();
|
||||
@@ -109,10 +108,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
|
||||
@Override
|
||||
public void enableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
|
||||
if(channelGroup == null) {
|
||||
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
|
||||
}
|
||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
|
||||
ACommand command = commandManagementService.findCommandByName(commandName);
|
||||
if(command == null) {
|
||||
throw new CommandNotFoundException();
|
||||
|
||||
@@ -139,9 +139,13 @@ public class ChannelGroupManagementServiceBean implements ChannelGroupManagement
|
||||
public AChannelGroup findByNameAndServerAndType(String name, AServer server, String expectedType) {
|
||||
String lowerName = name.toLowerCase();
|
||||
Optional<AChannelGroup> channelOptional = channelGroupRepository.findByGroupNameAndServerAndChannelGroupType_GroupTypeKey(lowerName, server, expectedType);
|
||||
return channelOptional.orElseThrow( () -> {
|
||||
List<String> channelGroupNames = extractChannelGroupNames(findAllInServerWithType(server.getId(), expectedType));
|
||||
return new ChannelGroupNotFoundException(name.toLowerCase(), channelGroupNames);
|
||||
return channelOptional.orElseThrow(() -> {
|
||||
if(channelGroupRepository.existsByGroupNameAndServer(lowerName, server)) {
|
||||
return new ChannelGroupIncorrectTypeException(name.toLowerCase(), expectedType);
|
||||
} else {
|
||||
List<String> channelGroupNames = extractChannelGroupNames(findAllInServerWithType(server.getId(), expectedType));
|
||||
return new ChannelGroupNotFoundException(name.toLowerCase(), channelGroupNames);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../dbchangelog-3.8.xsd" >
|
||||
<include file="core-seedData/data.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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<changeSet author="Sheldan" id="command-channelGroupType-insertion">
|
||||
<insert tableName="channel_group_type">
|
||||
<column name="group_type_key" value="command"/>
|
||||
</insert>
|
||||
</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-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/dbchangelog-ext ../../dbchangelog-3.8.xsd
|
||||
http://www.liquibase.org/xml/ns/pro ../../dbchangelog-3.8.xsd" >
|
||||
<include file="channelGroupType.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -9,4 +9,5 @@
|
||||
<include file="1.0-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.0-templating/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.1-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
|
||||
</databaseChangeLog>
|
||||
@@ -0,0 +1,24 @@
|
||||
package dev.sheldan.abstracto.core.command.exception;
|
||||
|
||||
import dev.sheldan.abstracto.core.command.models.exception.ChannelGroupIncorrectTypeExceptionModel;
|
||||
import dev.sheldan.abstracto.core.exception.AbstractoRunTimeException;
|
||||
import dev.sheldan.abstracto.core.templating.Templatable;
|
||||
|
||||
public class ChannelGroupIncorrectTypeException extends AbstractoRunTimeException implements Templatable {
|
||||
|
||||
private final ChannelGroupIncorrectTypeExceptionModel model;
|
||||
|
||||
public ChannelGroupIncorrectTypeException(String key, String correctType) {
|
||||
super("Channel group has the incorrect type.");
|
||||
this.model = ChannelGroupIncorrectTypeExceptionModel.builder().name(key).correctType(correctType).build();
|
||||
}
|
||||
@Override
|
||||
public String getTemplateName() {
|
||||
return "channel_group_not_found_exception";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getTemplateModel() {
|
||||
return model;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package dev.sheldan.abstracto.core.command.models.exception;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
@Builder
|
||||
public class ChannelGroupIncorrectTypeExceptionModel implements Serializable {
|
||||
private String name;
|
||||
private String correctType;
|
||||
}
|
||||
Reference in New Issue
Block a user