Browse Source

Refactor SlackNotificationTargetConfig

pull/8046/head
ViacheslavKlimov 4 years ago
parent
commit
63dbd1ef68
  1. 3
      application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationCenter.java
  2. 4
      application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java
  3. 6
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/slack/SlackConversation.java
  4. 10
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/slack/SlackNotificationTargetConfig.java

3
application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationCenter.java

@ -191,8 +191,7 @@ public class DefaultNotificationCenter extends AbstractSubscriptionService imple
} }
case SLACK: { case SLACK: {
SlackNotificationTargetConfig slackTargetConfig = (SlackNotificationTargetConfig) target.getConfiguration(); SlackNotificationTargetConfig slackTargetConfig = (SlackNotificationTargetConfig) target.getConfiguration();
SlackConversation conversation = new SlackConversation(slackTargetConfig.getConversationId(), slackTargetConfig.getConversationName()); recipients = List.of(slackTargetConfig.getConversation());
recipients = List.of(conversation);
break; break;
} }
default: { default: {

4
application/src/test/java/org/thingsboard/server/service/notification/NotificationApiTest.java

@ -43,6 +43,7 @@ import org.thingsboard.server.common.data.notification.targets.platform.AllUsers
import org.thingsboard.server.common.data.notification.targets.platform.CustomerUsersFilter; import org.thingsboard.server.common.data.notification.targets.platform.CustomerUsersFilter;
import org.thingsboard.server.common.data.notification.targets.platform.PlatformUsersNotificationTargetConfig; import org.thingsboard.server.common.data.notification.targets.platform.PlatformUsersNotificationTargetConfig;
import org.thingsboard.server.common.data.notification.targets.platform.UserListFilter; import org.thingsboard.server.common.data.notification.targets.platform.UserListFilter;
import org.thingsboard.server.common.data.notification.targets.slack.SlackConversation;
import org.thingsboard.server.common.data.notification.targets.slack.SlackNotificationTargetConfig; import org.thingsboard.server.common.data.notification.targets.slack.SlackNotificationTargetConfig;
import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate; import org.thingsboard.server.common.data.notification.template.DeliveryMethodNotificationTemplate;
import org.thingsboard.server.common.data.notification.template.EmailDeliveryMethodNotificationTemplate; import org.thingsboard.server.common.data.notification.template.EmailDeliveryMethodNotificationTemplate;
@ -592,8 +593,7 @@ public class NotificationApiTest extends AbstractNotificationApiTest {
notificationTarget.setName(conversationName + " in Slack"); notificationTarget.setName(conversationName + " in Slack");
notificationTarget.setType(NotificationTargetType.SLACK); notificationTarget.setType(NotificationTargetType.SLACK);
SlackNotificationTargetConfig targetConfig = new SlackNotificationTargetConfig(); SlackNotificationTargetConfig targetConfig = new SlackNotificationTargetConfig();
targetConfig.setConversationId(conversationId); targetConfig.setConversation(new SlackConversation(conversationId, conversationName));
targetConfig.setConversationName(conversationName);
notificationTarget.setConfiguration(targetConfig); notificationTarget.setConfiguration(targetConfig);
notificationTarget = saveNotificationTarget(notificationTarget); notificationTarget = saveNotificationTarget(notificationTarget);

6
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/slack/SlackConversation.java

@ -20,10 +20,16 @@ import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import org.thingsboard.server.common.data.notification.targets.NotificationRecipient; import org.thingsboard.server.common.data.notification.targets.NotificationRecipient;
import javax.validation.constraints.NotEmpty;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
@AllArgsConstructor @AllArgsConstructor
public class SlackConversation implements NotificationRecipient { public class SlackConversation implements NotificationRecipient {
@NotEmpty
private String id; private String id;
@NotEmpty
private String name; private String name;
} }

10
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/slack/SlackNotificationTargetConfig.java

@ -20,17 +20,17 @@ import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.notification.targets.NotificationTargetConfig; import org.thingsboard.server.common.data.notification.targets.NotificationTargetConfig;
import org.thingsboard.server.common.data.notification.targets.NotificationTargetType; import org.thingsboard.server.common.data.notification.targets.NotificationTargetType;
import javax.validation.constraints.NotEmpty; import javax.validation.Valid;
import javax.validation.constraints.NotNull;
@Data @Data
@EqualsAndHashCode(callSuper = true) @EqualsAndHashCode(callSuper = true)
public class SlackNotificationTargetConfig extends NotificationTargetConfig { public class SlackNotificationTargetConfig extends NotificationTargetConfig {
private SlackConversationType conversationType; private SlackConversationType conversationType;
@NotEmpty @NotNull
private String conversationId; @Valid
@NotEmpty private SlackConversation conversation;
private String conversationName;
@Override @Override
public NotificationTargetType getType() { public NotificationTargetType getType() {

Loading…
Cancel
Save