@ -30,8 +30,6 @@ import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.NotificationTemplateId ;
import org.thingsboard.server.common.data.id.TenantId ;
import org.thingsboard.server.common.data.id.UUIDBased ;
import org.thingsboard.server.common.data.id.UserId ;
import org.thingsboard.server.common.data.notification.Notification ;
import org.thingsboard.server.common.data.notification.NotificationDeliveryMethod ;
import org.thingsboard.server.common.data.notification.NotificationRequest ;
import org.thingsboard.server.common.data.notification.NotificationRequestConfig ;
@ -44,18 +42,7 @@ import org.thingsboard.server.common.data.notification.rule.NotificationRuleInfo
import org.thingsboard.server.common.data.notification.rule.trigger.config.NotificationRuleTriggerConfig ;
import org.thingsboard.server.common.data.notification.settings.NotificationDeliveryMethodConfig ;
import org.thingsboard.server.common.data.notification.settings.NotificationSettings ;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget ;
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.UsersFilter ;
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.HasSubject ;
import org.thingsboard.server.common.data.notification.template.MobileAppDeliveryMethodNotificationTemplate ;
import org.thingsboard.server.common.data.notification.template.NotificationTemplate ;
import org.thingsboard.server.common.data.notification.template.NotificationTemplateConfig ;
import org.thingsboard.server.common.data.notification.template.SmsDeliveryMethodNotificationTemplate ;
import org.thingsboard.server.common.data.notification.template.WebDeliveryMethodNotificationTemplate ;
import org.thingsboard.server.common.data.page.PageData ;
import org.thingsboard.server.common.data.page.PageLink ;
import org.thingsboard.server.common.data.security.Authority ;
@ -71,7 +58,6 @@ import org.thingsboard.server.dao.sqlts.insert.sql.SqlPartitioningRepository;
import java.net.URISyntaxException ;
import java.util.Arrays ;
import java.util.HashMap ;
import java.util.List ;
import java.util.concurrent.TimeUnit ;
import java.util.stream.Collectors ;
@ -120,25 +106,6 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
notificationSettingsService . deleteNotificationSettings ( TenantId . SYS_TENANT_ID ) ;
}
protected NotificationTarget createNotificationTarget ( UserId . . . usersIds ) {
UserListFilter filter = new UserListFilter ( ) ;
filter . setUsersIds ( DaoUtil . toUUIDs ( List . of ( usersIds ) ) ) ;
return createNotificationTarget ( filter ) ;
}
protected NotificationTarget createNotificationTarget ( UsersFilter usersFilter ) {
NotificationTarget notificationTarget = new NotificationTarget ( ) ;
notificationTarget . setName ( usersFilter . toString ( ) ) ;
PlatformUsersNotificationTargetConfig targetConfig = new PlatformUsersNotificationTargetConfig ( ) ;
targetConfig . setUsersFilter ( usersFilter ) ;
notificationTarget . setConfiguration ( targetConfig ) ;
return saveNotificationTarget ( notificationTarget ) ;
}
protected NotificationTarget saveNotificationTarget ( NotificationTarget notificationTarget ) {
return doPost ( "/api/notification/target" , notificationTarget , NotificationTarget . class ) ;
}
protected NotificationRequest submitNotificationRequest ( NotificationTargetId targetId , String text , NotificationDeliveryMethod . . . deliveryMethods ) {
return submitNotificationRequest ( targetId , text , 0 , deliveryMethods ) ;
}
@ -178,50 +145,6 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
return findNotificationRequest ( notificationRequestId ) . getStats ( ) ;
}
protected NotificationTemplate createNotificationTemplate ( NotificationType notificationType , String subject ,
String text , NotificationDeliveryMethod . . . deliveryMethods ) {
NotificationTemplate notificationTemplate = new NotificationTemplate ( ) ;
notificationTemplate . setTenantId ( tenantId ) ;
notificationTemplate . setName ( "Notification template: " + text ) ;
notificationTemplate . setNotificationType ( notificationType ) ;
NotificationTemplateConfig config = new NotificationTemplateConfig ( ) ;
config . setDeliveryMethodsTemplates ( new HashMap < > ( ) ) ;
for ( NotificationDeliveryMethod deliveryMethod : deliveryMethods ) {
DeliveryMethodNotificationTemplate deliveryMethodNotificationTemplate ;
switch ( deliveryMethod ) {
case WEB : {
deliveryMethodNotificationTemplate = new WebDeliveryMethodNotificationTemplate ( ) ;
break ;
}
case EMAIL : {
deliveryMethodNotificationTemplate = new EmailDeliveryMethodNotificationTemplate ( ) ;
break ;
}
case SMS : {
deliveryMethodNotificationTemplate = new SmsDeliveryMethodNotificationTemplate ( ) ;
break ;
}
case MOBILE_APP :
deliveryMethodNotificationTemplate = new MobileAppDeliveryMethodNotificationTemplate ( ) ;
break ;
default :
throw new IllegalArgumentException ( "Unsupported delivery method " + deliveryMethod ) ;
}
deliveryMethodNotificationTemplate . setEnabled ( true ) ;
deliveryMethodNotificationTemplate . setBody ( text ) ;
if ( deliveryMethodNotificationTemplate instanceof HasSubject ) {
( ( HasSubject ) deliveryMethodNotificationTemplate ) . setSubject ( subject ) ;
}
config . getDeliveryMethodsTemplates ( ) . put ( deliveryMethod , deliveryMethodNotificationTemplate ) ;
}
notificationTemplate . setConfiguration ( config ) ;
return saveNotificationTemplate ( notificationTemplate ) ;
}
protected NotificationTemplate saveNotificationTemplate ( NotificationTemplate notificationTemplate ) {
return doPost ( "/api/notification/template" , notificationTemplate , NotificationTemplate . class ) ;
}
protected void saveNotificationSettings ( NotificationSettings notificationSettings ) throws Exception {
doPost ( "/api/notification/settings" , notificationSettings ) . andExpect ( status ( ) . isOk ( ) ) ;
}
@ -258,15 +181,6 @@ public abstract class AbstractNotificationApiTest extends AbstractControllerTest
doDelete ( "/api/notification/request/" + id ) ;
}
protected List < Notification > getMyNotifications ( boolean unreadOnly , int limit ) throws Exception {
return getMyNotifications ( NotificationDeliveryMethod . WEB , unreadOnly , limit ) ;
}
protected List < Notification > getMyNotifications ( NotificationDeliveryMethod deliveryMethod , boolean unreadOnly , int limit ) throws Exception {
return doGetTypedWithPageLink ( "/api/notifications?unreadOnly={unreadOnly}&deliveryMethod={deliveryMethod}&" , new TypeReference < PageData < Notification > > ( ) { } ,
new PageLink ( limit , 0 ) , unreadOnly , deliveryMethod ) . getData ( ) ;
}
protected NotificationRule createNotificationRule ( NotificationRuleTriggerConfig triggerConfig , String subject , String text , NotificationTargetId . . . targets ) {
return createNotificationRule ( triggerConfig , subject , text , List . of ( targets ) , NotificationDeliveryMethod . WEB ) ;
}