mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-27 14:23:56 +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 class CommandConstants {
|
||||||
|
|
||||||
|
public static final String COMMAND_CHANNEL_GROUP_KEY = "command";
|
||||||
|
|
||||||
private CommandConstants() {
|
private CommandConstants() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ public class ChannelGroupCommandManagementServiceBean implements ChannelGroupCom
|
|||||||
AChannelGroupCommand channelGroupCommand = AChannelGroupCommand
|
AChannelGroupCommand channelGroupCommand = AChannelGroupCommand
|
||||||
.builder()
|
.builder()
|
||||||
.command(command)
|
.command(command)
|
||||||
|
.server(group.getServer())
|
||||||
.group(group)
|
.group(group)
|
||||||
.enabled(false)
|
.enabled(false)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -19,6 +19,8 @@ import org.springframework.stereotype.Component;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static dev.sheldan.abstracto.core.command.CommandConstants.COMMAND_CHANNEL_GROUP_KEY;
|
||||||
|
|
||||||
@Component
|
@Component
|
||||||
public class ChannelGroupServiceBean implements ChannelGroupService {
|
public class ChannelGroupServiceBean implements ChannelGroupService {
|
||||||
|
|
||||||
@@ -95,10 +97,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
|
|||||||
@Override
|
@Override
|
||||||
public void disableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
public void disableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
||||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
|
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
|
||||||
if(channelGroup == null) {
|
|
||||||
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
|
|
||||||
}
|
|
||||||
ACommand command = commandManagementService.findCommandByName(commandName);
|
ACommand command = commandManagementService.findCommandByName(commandName);
|
||||||
if(command == null) {
|
if(command == null) {
|
||||||
throw new CommandNotFoundException();
|
throw new CommandNotFoundException();
|
||||||
@@ -109,10 +108,7 @@ public class ChannelGroupServiceBean implements ChannelGroupService {
|
|||||||
@Override
|
@Override
|
||||||
public void enableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
public void enableCommandInChannelGroup(String commandName, String channelGroupName, Long serverId) {
|
||||||
AServer server = serverManagementService.loadOrCreate(serverId);
|
AServer server = serverManagementService.loadOrCreate(serverId);
|
||||||
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServer(channelGroupName, server);
|
AChannelGroup channelGroup = channelGroupManagementService.findByNameAndServerAndType(channelGroupName, server, COMMAND_CHANNEL_GROUP_KEY);
|
||||||
if(channelGroup == null) {
|
|
||||||
throw new ChannelGroupNotFoundException(channelGroupName, channelGroupManagementService.getAllAvailableAsString(server));
|
|
||||||
}
|
|
||||||
ACommand command = commandManagementService.findCommandByName(commandName);
|
ACommand command = commandManagementService.findCommandByName(commandName);
|
||||||
if(command == null) {
|
if(command == null) {
|
||||||
throw new CommandNotFoundException();
|
throw new CommandNotFoundException();
|
||||||
|
|||||||
@@ -139,9 +139,13 @@ public class ChannelGroupManagementServiceBean implements ChannelGroupManagement
|
|||||||
public AChannelGroup findByNameAndServerAndType(String name, AServer server, String expectedType) {
|
public AChannelGroup findByNameAndServerAndType(String name, AServer server, String expectedType) {
|
||||||
String lowerName = name.toLowerCase();
|
String lowerName = name.toLowerCase();
|
||||||
Optional<AChannelGroup> channelOptional = channelGroupRepository.findByGroupNameAndServerAndChannelGroupType_GroupTypeKey(lowerName, server, expectedType);
|
Optional<AChannelGroup> channelOptional = channelGroupRepository.findByGroupNameAndServerAndChannelGroupType_GroupTypeKey(lowerName, server, expectedType);
|
||||||
return channelOptional.orElseThrow( () -> {
|
return channelOptional.orElseThrow(() -> {
|
||||||
List<String> channelGroupNames = extractChannelGroupNames(findAllInServerWithType(server.getId(), expectedType));
|
if(channelGroupRepository.existsByGroupNameAndServer(lowerName, server)) {
|
||||||
return new ChannelGroupNotFoundException(name.toLowerCase(), channelGroupNames);
|
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-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
<include file="1.0-templating/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.1-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
|
<include file="1.2-core/collection.xml" relativeToChangelogFile="true"/>
|
||||||
</databaseChangeLog>
|
</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;
|
||||||
|
}
|
||||||
@@ -12,7 +12,7 @@ fi
|
|||||||
if [ "x$EXECUTE_TEMPLATES" = 'xtrue' ]; then
|
if [ "x$EXECUTE_TEMPLATES" = 'xtrue' ]; then
|
||||||
DEPLOY_TEMPLATES=yes
|
DEPLOY_TEMPLATES=yes
|
||||||
fi
|
fi
|
||||||
exit_code = 0
|
exit_code=0
|
||||||
if [ "x$EXECUTE_DEPLOYMENT" = 'xtrue' ]; then
|
if [ "x$EXECUTE_DEPLOYMENT" = 'xtrue' ]; then
|
||||||
python3 -u python/main.py $DEPLOY_TEMPLATES $DEPLOY_LIQUIBASE
|
python3 -u python/main.py $DEPLOY_TEMPLATES $DEPLOY_LIQUIBASE
|
||||||
exit_code=$?
|
exit_code=$?
|
||||||
|
|||||||
Reference in New Issue
Block a user