Browse Source

Initial notification system structures and dao layer

pull/7511/head
ViacheslavKlimov 4 years ago
parent
commit
fa934f647e
  1. 56
      application/src/main/java/org/thingsboard/server/controller/NotificationTargetController.java
  2. 98
      application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationProcessingService.java
  3. 25
      application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingService.java
  4. 3
      application/src/main/java/org/thingsboard/server/service/security/permission/Resource.java
  5. 2
      application/src/main/java/org/thingsboard/server/service/telemetry/AbstractSubscriptionService.java
  6. 2
      application/src/main/java/org/thingsboard/server/service/telemetry/DefaultAlarmSubscriptionService.java
  7. 39
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationService.java
  8. 37
      common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java
  9. 27
      common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationId.java
  10. 27
      common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationRequestId.java
  11. 27
      common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationTargetId.java
  12. 51
      common/data/src/main/java/org/thingsboard/server/common/data/notification/Notification.java
  13. 53
      common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationRequest.java
  14. 20
      common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationSettings.java
  15. 22
      common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationSeverity.java
  16. 21
      common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationStatus.java
  17. 23
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NonConfirmedNotificationEscalation.java
  18. 38
      common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java
  19. 39
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTarget.java
  20. 32
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTargetConfig.java
  21. 23
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTargetConfigType.java
  22. 31
      common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/SingleUserNotificationTargetConfig.java
  23. 19
      dao/src/main/java/org/thingsboard/server/dao/model/BaseSqlEntity.java
  24. 9
      dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java
  25. 29
      dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationEntity.java
  26. 29
      dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRequestEntity.java
  27. 77
      dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationTargetEntity.java
  28. 76
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationService.java
  29. 75
      dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java
  30. 22
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationDao.java
  31. 22
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestDao.java
  32. 22
      dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetDao.java
  33. 46
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationDao.java
  34. 46
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRequestDao.java
  35. 46
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTargetDao.java
  36. 26
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRepository.java
  37. 26
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRequestRepository.java
  38. 26
      dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTargetRepository.java

56
application/src/main/java/org/thingsboard/server/controller/NotificationTargetController.java

@ -0,0 +1,56 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.controller;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.thingsboard.server.common.data.exception.ThingsboardException;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.queue.util.TbCoreComponent;
import org.thingsboard.server.service.security.model.SecurityUser;
@RestController
@TbCoreComponent
@RequestMapping("/api/notification")
@RequiredArgsConstructor
@Slf4j
public class NotificationTargetController extends BaseController {
private final NotificationTargetService notificationTargetService;
@PostMapping("/target")
@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
public NotificationTarget saveNotificationTarget(NotificationTarget notificationTarget) throws Exception {
SecurityUser user = getCurrentUser();
// fixme: permission check, log action
return notificationTargetService.saveNotificationTarget(user.getTenantId(), notificationTarget);
}
@GetMapping("/targets")
public PageData<NotificationTarget> getNotificationTargets(@AuthenticationPrincipal SecurityUser user) throws ThingsboardException {
// notificationTargetService.findNotificationTargetsByTenantIdAndPageLink()
return null;
}
}

98
application/src/main/java/org/thingsboard/server/service/notification/DefaultNotificationProcessingService.java

@ -0,0 +1,98 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.service.notification;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.thingsboard.server.cluster.TbClusterService;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.dao.notification.NotificationService;
import org.thingsboard.server.dao.notification.NotificationTargetService;
import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.queue.discovery.PartitionService;
import org.thingsboard.server.service.executors.DbCallbackExecutorService;
import org.thingsboard.server.service.security.model.SecurityUser;
import org.thingsboard.server.service.security.permission.AccessControlService;
import org.thingsboard.server.service.telemetry.AbstractSubscriptionService;
import java.util.List;
@Service
@Slf4j
public class DefaultNotificationProcessingService extends AbstractSubscriptionService implements NotificationProcessingService {
private final NotificationTargetService notificationTargetService;
private final NotificationService notificationService;
private final UserService userService;
private final AccessControlService accessControlService;
private final DbCallbackExecutorService dbCallbackExecutorService;
public DefaultNotificationProcessingService(TbClusterService clusterService, PartitionService partitionService,
NotificationTargetService notificationTargetService,
NotificationService notificationService, UserService userService,
AccessControlService accessControlService,
DbCallbackExecutorService dbCallbackExecutorService) {
super(clusterService, partitionService);
this.notificationTargetService = notificationTargetService;
this.notificationService = notificationService;
this.userService = userService;
this.accessControlService = accessControlService;
this.dbCallbackExecutorService = dbCallbackExecutorService;
}
@Override
public void processNotificationRequest(SecurityUser user, NotificationRequest notificationRequest) {
TenantId tenantId = user.getTenantId();
notificationRequest = notificationService.createNotificationRequest(tenantId, notificationRequest);
List<UserId> recipients = notificationTargetService.findRecipientsForNotificationTarget(tenantId, notificationRequest.getTargetId());
for (UserId recipientId : recipients) {
try {
// todo: check read permission for recipientId
Notification notification = Notification.builder()
.tenantId(tenantId)
.requestId(notificationRequest.getId())
.status(null)
.recipientId(recipientId)
.text(formatNotificationText(notificationRequest.getTextTemplate(), null))
.severity(notificationRequest.getSeverity())
.senderId(notificationRequest.getSenderId())
.build();
notification = notificationService.createNotification(tenantId, notification);
onNewNotification(notification);
} catch (Exception e) {
// fixme: handle
}
}
}
private void onNewNotification(Notification notification) {
}
private String formatNotificationText(String template, Object context) {
return template;
}
@Override
protected String getExecutorPrefix() {
return "notification";
}
}

25
application/src/main/java/org/thingsboard/server/service/notification/NotificationProcessingService.java

@ -0,0 +1,25 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.service.notification;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.service.security.model.SecurityUser;
public interface NotificationProcessingService {
void processNotificationRequest(SecurityUser user, NotificationRequest notificationRequest);
}

3
application/src/main/java/org/thingsboard/server/service/security/permission/Resource.java

@ -43,7 +43,8 @@ public enum Resource {
EDGE(EntityType.EDGE),
RPC(EntityType.RPC),
QUEUE(EntityType.QUEUE),
VERSION_CONTROL;
VERSION_CONTROL,
NOTIFICATION;
private final EntityType entityType;

2
application/src/main/java/org/thingsboard/server/service/telemetry/AbstractSubscriptionService.java

@ -64,7 +64,7 @@ public abstract class AbstractSubscriptionService extends TbApplicationEventList
this.subscriptionManagerService = subscriptionManagerService;
}
abstract String getExecutorPrefix();
protected abstract String getExecutorPrefix();
@PostConstruct
public void initExecutor() {

2
application/src/main/java/org/thingsboard/server/service/telemetry/DefaultAlarmSubscriptionService.java

@ -81,7 +81,7 @@ public class DefaultAlarmSubscriptionService extends AbstractSubscriptionService
}
@Override
String getExecutorPrefix() {
protected String getExecutorPrefix() {
return "alarm";
}

39
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationService.java

@ -0,0 +1,39 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import org.thingsboard.server.common.data.id.NotificationId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.common.data.notification.NotificationStatus;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
public interface NotificationService {
NotificationRequest createNotificationRequest(TenantId tenantId, NotificationRequest notificationRequest);
PageData<NotificationRequest> findNotificationRequestsByTenantIdAndPageLink(TenantId tenantId, PageLink pageLink);
Notification createNotification(TenantId tenantId, Notification notification);
void updateNotificationStatus(TenantId tenantId, NotificationId notificationId, NotificationStatus status);
PageData<Notification> findNotificationsByUserIdAndPageLink(TenantId tenantId, UserId userId, PageLink pageLink);
}

37
common/dao-api/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetService.java

@ -0,0 +1,37 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import java.util.List;
public interface NotificationTargetService {
NotificationTarget saveNotificationTarget(TenantId tenantId, NotificationTarget notificationTarget);
NotificationTarget findNotificationTargetById(TenantId tenantId, NotificationTargetId id);
PageData<NotificationTarget> findNotificationTargetsByTenantIdAndPageLink(TenantId tenantId, PageLink pageLink);
List<UserId> findRecipientsForNotificationTarget(TenantId tenantId, NotificationTargetId notificationTargetId);
}

27
common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationId.java

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.id;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.UUID;
public class NotificationId extends UUIDBased {
@JsonCreator
public NotificationId(UUID id) {
super(id);
}
}

27
common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationRequestId.java

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.id;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.UUID;
public class NotificationRequestId extends UUIDBased {
@JsonCreator
public NotificationRequestId(UUID id) {
super(id);
}
}

27
common/data/src/main/java/org/thingsboard/server/common/data/id/NotificationTargetId.java

@ -0,0 +1,27 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.id;
import com.fasterxml.jackson.annotation.JsonCreator;
import java.util.UUID;
public class NotificationTargetId extends UUIDBased {
@JsonCreator
public NotificationTargetId(UUID id) {
super(id);
}
}

51
common/data/src/main/java/org/thingsboard/server/common/data/notification/Notification.java

@ -0,0 +1,51 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;
import org.thingsboard.server.common.data.SearchTextBased;
import org.thingsboard.server.common.data.id.NotificationId;
import org.thingsboard.server.common.data.id.NotificationRequestId;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import java.util.UUID;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@EqualsAndHashCode(callSuper = true)
public class Notification extends SearchTextBased<NotificationId> {
private NotificationRequestId requestId;
private TenantId tenantId;
private UserId recipientId;
private String text;
private NotificationSeverity severity;
private NotificationStatus status;
private UserId senderId;
@Override
public String getSearchText() {
return text;
}
}

53
common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationRequest.java

@ -0,0 +1,53 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.SearchTextBased;
import org.thingsboard.server.common.data.id.NotificationId;
import org.thingsboard.server.common.data.id.NotificationRequestId;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import java.util.UUID;
@Data
@EqualsAndHashCode(callSuper = true)
public class NotificationRequest extends SearchTextBased<NotificationRequestId> {
private NotificationTargetId targetId;
private String textTemplate; // html with params?
private Object notificationType; // ALARM, ADMIN,
private Object notificationInfo; // for alarms: alarm details, link to dashboard etc.
private NotificationSeverity severity;
private TenantId tenantId;
private UserId senderId;
@Override
public String getSearchText() {
return textTemplate;
}
// todo: scheduling
}
/*
* NotificationService - manages NotificationRequest and Notification entities
* NotificationTargetService - manages NotificationTarget
* */

20
common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationSettings.java

@ -0,0 +1,20 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification;
public class NotificationSettings {
// location on the screen, shown notifications count, timings of displaying
}

22
common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationSeverity.java

@ -0,0 +1,22 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification;
public enum NotificationSeverity {
NORMAL,
CRITICAL,
URGENT // send pop-up error
}

21
common/data/src/main/java/org/thingsboard/server/common/data/notification/NotificationStatus.java

@ -0,0 +1,21 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification;
public enum NotificationStatus {
DELIVERED,
READ
}

23
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NonConfirmedNotificationEscalation.java

@ -0,0 +1,23 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.rule;
import java.util.UUID;
public class NonConfirmedNotificationEscalation {
private long delayMs; // delay since initial notification request // if no one from previous escalation item has read the notification, send notifications after this time to other recipients
private UUID notificationTargetId;
}

38
common/data/src/main/java/org/thingsboard/server/common/data/notification/rule/NotificationRule.java

@ -0,0 +1,38 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.rule;
import lombok.Data;
import java.util.List;
import java.util.Map;
import java.util.UUID;
@Data
public class NotificationRule {
// we may choose it in the alarm rule config, or maybe it's better to configure evrth in the triggers?
private UUID id; // NotificationRuleId id;
private String name;
private Map<String, Object> triggers; // or maybe bad idea
// Map<NotificationTriggerType, NotificationTriggerConfig> - concrete alarmRule or alarm rule search (e.g. alarm rule of device profiles of particular transport type with certain severity)
// triggerConfiguration (??) - alarm filter: severity, specific device profile, alarm rule
private UUID initialNotificationTargetId;
private List<NonConfirmedNotificationEscalation> escalations;
}

39
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTarget.java

@ -0,0 +1,39 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.targets;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.thingsboard.server.common.data.HasName;
import org.thingsboard.server.common.data.HasTenantId;
import org.thingsboard.server.common.data.SearchTextBased;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
@Data
@EqualsAndHashCode(callSuper = true)
public class NotificationTarget extends SearchTextBased<NotificationTargetId> implements HasTenantId, HasName {
private TenantId tenantId;
private String name;
private NotificationTargetConfig configuration;
@Override
public String getSearchText() {
return name;
}
}

32
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTargetConfig.java

@ -0,0 +1,32 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.targets;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonSubTypes.Type;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "type")
@JsonSubTypes({
@Type(value = SingleUserNotificationTargetConfig.class, name = "SINGLE_USER")
})
public interface NotificationTargetConfig {
NotificationTargetConfigType getType();
}

23
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/NotificationTargetConfigType.java

@ -0,0 +1,23 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.targets;
public enum NotificationTargetConfigType {
SINGLE_USER,
USER_GROUP,
USERS_WITH_ROLE,
QUERY // ?
}

31
common/data/src/main/java/org/thingsboard/server/common/data/notification/targets/SingleUserNotificationTargetConfig.java

@ -0,0 +1,31 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.common.data.notification.targets;
import lombok.Data;
import org.thingsboard.server.common.data.id.UserId;
@Data
public class SingleUserNotificationTargetConfig implements NotificationTargetConfig {
private UserId userId;
@Override
public NotificationTargetConfigType getType() {
return NotificationTargetConfigType.SINGLE_USER;
}
}

19
dao/src/main/java/org/thingsboard/server/dao/model/BaseSqlEntity.java

@ -16,11 +16,13 @@
package org.thingsboard.server.dao.model;
import lombok.Data;
import org.thingsboard.server.common.data.id.UUIDBased;
import javax.persistence.Column;
import javax.persistence.Id;
import javax.persistence.MappedSuperclass;
import java.util.UUID;
import java.util.function.Function;
/**
* Created by ashvayka on 13.07.17.
@ -56,4 +58,21 @@ public abstract class BaseSqlEntity<D> implements BaseEntity<D> {
this.createdTime = createdTime;
}
}
protected static UUID getUuid(UUIDBased uuidBased) {
if (uuidBased != null) {
return uuidBased.getId();
} else {
return null;
}
}
protected static <I> I createId(UUID uuid, Function<UUID, I> creator) {
if (uuid != null) {
return creator.apply(uuid);
} else {
return null;
}
}
}

9
dao/src/main/java/org/thingsboard/server/dao/model/ModelConstants.java

@ -43,6 +43,7 @@ public class ModelConstants {
public static final String CUSTOMER_ID_PROPERTY = "customer_id";
public static final String DEVICE_ID_PROPERTY = "device_id";
public static final String TITLE_PROPERTY = "title";
public static final String NAME_PROPERTY = "name";
public static final String ALIAS_PROPERTY = "alias";
public static final String SEARCH_TEXT_PROPERTY = "search_text";
public static final String ADDITIONAL_INFO_PROPERTY = "additional_info";
@ -644,6 +645,14 @@ public class ModelConstants {
public static final String QUEUE_ADDITIONAL_INFO_PROPERTY = ADDITIONAL_INFO_PROPERTY;
/**
* Notification constants
* */
public static final String NOTIFICATION_TARGET_TABLE_NAME = "notification_target";
public static final String NOTIFICATION_TARGET_CONFIGURATION_PROPERTY = "configuration";
protected static final String[] NONE_AGGREGATION_COLUMNS = new String[]{LONG_VALUE_COLUMN, DOUBLE_VALUE_COLUMN, BOOLEAN_VALUE_COLUMN, STRING_VALUE_COLUMN, JSON_VALUE_COLUMN, KEY_COLUMN, TS_COLUMN};
protected static final String[] COUNT_AGGREGATION_COLUMNS = new String[]{count(LONG_VALUE_COLUMN), count(DOUBLE_VALUE_COLUMN), count(BOOLEAN_VALUE_COLUMN), count(STRING_VALUE_COLUMN), count(JSON_VALUE_COLUMN), max(TS_COLUMN)};

29
dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationEntity.java

@ -0,0 +1,29 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.model.sql;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.dao.model.BaseSqlEntity;
import javax.persistence.Entity;
@Entity
public class NotificationEntity extends BaseSqlEntity<Notification> {
@Override
public Notification toData() {
return null;
}
}

29
dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationRequestEntity.java

@ -0,0 +1,29 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.model.sql;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.dao.model.BaseSqlEntity;
import javax.persistence.Entity;
@Entity
public class NotificationRequestEntity extends BaseSqlEntity<NotificationRequest> {
@Override
public NotificationRequest toData() {
return null;
}
}

77
dao/src/main/java/org/thingsboard/server/dao/model/sql/NotificationTargetEntity.java

@ -0,0 +1,77 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.model.sql;
import com.fasterxml.jackson.databind.JsonNode;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.notification.targets.NotificationTargetConfig;
import org.thingsboard.server.dao.model.BaseSqlEntity;
import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.util.mapping.JsonStringType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;
import java.util.UUID;
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@TypeDef(name = "json", typeClass = JsonStringType.class)
@Table(name = ModelConstants.NOTIFICATION_TARGET_TABLE_NAME)
public class NotificationTargetEntity extends BaseSqlEntity<NotificationTarget> {
@Column(name = ModelConstants.TENANT_ID_PROPERTY)
private UUID tenantId;
@Column(name = ModelConstants.NAME_PROPERTY)
private String name;
@Type(type = "json")
@Column(name = ModelConstants.NOTIFICATION_TARGET_CONFIGURATION_PROPERTY)
private JsonNode configuration;
public NotificationTargetEntity() {}
public NotificationTargetEntity(NotificationTarget notificationTarget) {
setId(notificationTarget.getUuidId());
setCreatedTime(notificationTarget.getCreatedTime());
setTenantId(getUuid(notificationTarget.getTenantId()));
setName(notificationTarget.getName());
setConfiguration(JacksonUtil.valueToTree(notificationTarget.getConfiguration()));
}
@Override
public NotificationTarget toData() {
NotificationTarget notificationTarget = new NotificationTarget();
notificationTarget.setId(new NotificationTargetId(id));
notificationTarget.setCreatedTime(createdTime);
notificationTarget.setTenantId(createId(tenantId, TenantId::fromUUID));
notificationTarget.setName(name);
if (configuration != null) {
notificationTarget.setConfiguration(JacksonUtil.treeToValue(configuration, NotificationTargetConfig.class));
}
return notificationTarget;
}
}

76
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationService.java

@ -0,0 +1,76 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.id.NotificationId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.common.data.notification.NotificationStatus;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.service.DataValidator;
@Service
@Slf4j
@RequiredArgsConstructor
public class DefaultNotificationService implements NotificationService {
private final NotificationRequestDao notificationRequestDao;
private final NotificationDao notificationDao;
private final NotificationTargetService notificationTargetService;
private final NotificationRequestValidator notificationRequestValidator = new NotificationRequestValidator();
@Override
public NotificationRequest createNotificationRequest(TenantId tenantId, NotificationRequest notificationRequest) {
if (notificationRequest.getId() != null) {
throw new IllegalArgumentException();
}
notificationRequestValidator.validate(notificationRequest, NotificationRequest::getTenantId);
return notificationRequestDao.save(tenantId, notificationRequest);
}
@Override
public PageData<NotificationRequest> findNotificationRequestsByTenantIdAndPageLink(TenantId tenantId, PageLink pageLink) {
return null;
}
@Override
public Notification createNotification(TenantId tenantId, Notification notification) {
if (notification.getId() != null) {
throw new IllegalArgumentException();
}
return notificationDao.save(tenantId, notification);
}
@Override
public void updateNotificationStatus(TenantId tenantId, NotificationId notificationId, NotificationStatus status) {
}
@Override
public PageData<Notification> findNotificationsByUserIdAndPageLink(TenantId tenantId, UserId userId, PageLink pageLink) {
return null;
}
private static class NotificationRequestValidator extends DataValidator<NotificationRequest> {
}
}

75
dao/src/main/java/org/thingsboard/server/dao/notification/DefaultNotificationTargetService.java

@ -0,0 +1,75 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.id.NotificationTargetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.common.data.notification.targets.NotificationTargetConfig;
import org.thingsboard.server.common.data.notification.targets.SingleUserNotificationTargetConfig;
import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.service.DataValidator;
import java.util.ArrayList;
import java.util.List;
@Service
@Slf4j
@RequiredArgsConstructor
public class DefaultNotificationTargetService implements NotificationTargetService {
private final NotificationTargetDao notificationTargetDao;
private final NotificationTargetValidator validator = new NotificationTargetValidator();
@Override
public NotificationTarget saveNotificationTarget(TenantId tenantId, NotificationTarget notificationTarget) {
validator.validate(notificationTarget, NotificationTarget::getTenantId);
return notificationTargetDao.save(tenantId, notificationTarget);
}
@Override
public NotificationTarget findNotificationTargetById(TenantId tenantId, NotificationTargetId id) {
return null;
}
@Override
public PageData<NotificationTarget> findNotificationTargetsByTenantIdAndPageLink(TenantId tenantId, PageLink pageLink) {
return null;
}
@Override
public List<UserId> findRecipientsForNotificationTarget(TenantId tenantId, NotificationTargetId notificationTargetId) {
NotificationTarget notificationTarget = findNotificationTargetById(tenantId, notificationTargetId);
NotificationTargetConfig configuration = notificationTarget.getConfiguration();
List<UserId> recipients = new ArrayList<>();
switch (configuration.getType()) {
case SINGLE_USER:
SingleUserNotificationTargetConfig singleUserNotificationTargetConfig = (SingleUserNotificationTargetConfig) configuration;
recipients.add(singleUserNotificationTargetConfig.getUserId());
break;
}
return recipients;
}
private static class NotificationTargetValidator extends DataValidator<NotificationTarget> {
}
}

22
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationDao.java

@ -0,0 +1,22 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.dao.Dao;
public interface NotificationDao extends Dao<Notification> {
}

22
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationRequestDao.java

@ -0,0 +1,22 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.dao.Dao;
public interface NotificationRequestDao extends Dao<NotificationRequest> {
}

22
dao/src/main/java/org/thingsboard/server/dao/notification/NotificationTargetDao.java

@ -0,0 +1,22 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.notification;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.dao.Dao;
public interface NotificationTargetDao extends Dao<NotificationTarget> {
}

46
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationDao.java

@ -0,0 +1,46 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.notification.Notification;
import org.thingsboard.server.dao.model.sql.NotificationEntity;
import org.thingsboard.server.dao.notification.NotificationDao;
import org.thingsboard.server.dao.sql.JpaAbstractDao;
import org.thingsboard.server.dao.util.SqlDao;
import java.util.UUID;
@Component
@SqlDao
@RequiredArgsConstructor
public class JpaNotificationDao extends JpaAbstractDao<NotificationEntity, Notification> implements NotificationDao {
private final NotificationRepository notificationRepository;
@Override
protected Class<NotificationEntity> getEntityClass() {
return NotificationEntity.class;
}
@Override
protected JpaRepository<NotificationEntity, UUID> getRepository() {
return notificationRepository;
}
}

46
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationRequestDao.java

@ -0,0 +1,46 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.notification.NotificationRequest;
import org.thingsboard.server.dao.model.sql.NotificationRequestEntity;
import org.thingsboard.server.dao.notification.NotificationRequestDao;
import org.thingsboard.server.dao.sql.JpaAbstractDao;
import org.thingsboard.server.dao.util.SqlDao;
import java.util.UUID;
@Component
@SqlDao
@RequiredArgsConstructor
public class JpaNotificationRequestDao extends JpaAbstractDao<NotificationRequestEntity, NotificationRequest> implements NotificationRequestDao {
private final NotificationRequestRepository notificationRequestRepository;
@Override
protected Class<NotificationRequestEntity> getEntityClass() {
return NotificationRequestEntity.class;
}
@Override
protected JpaRepository<NotificationRequestEntity, UUID> getRepository() {
return notificationRequestRepository;
}
}

46
dao/src/main/java/org/thingsboard/server/dao/sql/notification/JpaNotificationTargetDao.java

@ -0,0 +1,46 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import lombok.RequiredArgsConstructor;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.common.data.notification.targets.NotificationTarget;
import org.thingsboard.server.dao.model.sql.NotificationTargetEntity;
import org.thingsboard.server.dao.notification.NotificationTargetDao;
import org.thingsboard.server.dao.sql.JpaAbstractDao;
import org.thingsboard.server.dao.util.SqlDao;
import java.util.UUID;
@Component
@SqlDao
@RequiredArgsConstructor
public class JpaNotificationTargetDao extends JpaAbstractDao<NotificationTargetEntity, NotificationTarget> implements NotificationTargetDao {
private final NotificationTargetRepository notificationTargetRepository;
@Override
protected Class<NotificationTargetEntity> getEntityClass() {
return NotificationTargetEntity.class;
}
@Override
protected JpaRepository<NotificationTargetEntity, UUID> getRepository() {
return notificationTargetRepository;
}
}

26
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRepository.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.thingsboard.server.dao.model.sql.NotificationEntity;
import java.util.UUID;
@Repository
public interface NotificationRepository extends JpaRepository<NotificationEntity, UUID> {
}

26
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationRequestRepository.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.thingsboard.server.dao.model.sql.NotificationRequestEntity;
import java.util.UUID;
@Repository
public interface NotificationRequestRepository extends JpaRepository<NotificationRequestEntity, UUID> {
}

26
dao/src/main/java/org/thingsboard/server/dao/sql/notification/NotificationTargetRepository.java

@ -0,0 +1,26 @@
/**
* Copyright © 2016-2022 The Thingsboard Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.thingsboard.server.dao.sql.notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;
import org.thingsboard.server.dao.model.sql.NotificationTargetEntity;
import java.util.UUID;
@Repository
public interface NotificationTargetRepository extends JpaRepository<NotificationTargetEntity, UUID> {
}
Loading…
Cancel
Save