53 changed files with 964 additions and 200 deletions
@ -0,0 +1,138 @@ |
|||||
|
/** |
||||
|
* 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 com.google.common.util.concurrent.Futures; |
||||
|
import com.google.common.util.concurrent.ListenableFuture; |
||||
|
import lombok.RequiredArgsConstructor; |
||||
|
import org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.common.data.alarm.Alarm; |
||||
|
import org.thingsboard.server.common.data.id.NotificationRuleId; |
||||
|
import org.thingsboard.server.common.data.id.NotificationTargetId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationInfo; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationRequest; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationRequestConfig; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationRequestStatus; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationSeverity; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NonConfirmedNotificationEscalation; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
||||
|
import org.thingsboard.server.dao.notification.NotificationRuleService; |
||||
|
import org.thingsboard.server.dao.notification.NotificationService; |
||||
|
import org.thingsboard.server.queue.util.TbCoreComponent; |
||||
|
import org.thingsboard.server.service.executors.DbCallbackExecutorService; |
||||
|
|
||||
|
import java.util.List; |
||||
|
|
||||
|
@Service |
||||
|
@TbCoreComponent |
||||
|
@RequiredArgsConstructor |
||||
|
public class DefaultNotificationRuleProcessingService implements NotificationRuleProcessingService { |
||||
|
|
||||
|
private final NotificationRuleService notificationRuleService; |
||||
|
private final NotificationService notificationService; |
||||
|
private final NotificationSubscriptionService notificationSubscriptionService; |
||||
|
private final DbCallbackExecutorService dbCallbackExecutorService; |
||||
|
|
||||
|
@Override |
||||
|
public ListenableFuture<?> onAlarmCreatedOrUpdated(TenantId tenantId, Alarm alarm) { |
||||
|
return processAlarmUpdate(tenantId, alarm); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public ListenableFuture<?> onAlarmAcknowledged(TenantId tenantId, Alarm alarm) { |
||||
|
return processAlarmUpdate(tenantId, alarm); |
||||
|
} |
||||
|
|
||||
|
private ListenableFuture<?> processAlarmUpdate(TenantId tenantId, Alarm alarm) { |
||||
|
if (alarm.getNotificationRuleId() == null) return Futures.immediateFuture(null); |
||||
|
return dbCallbackExecutorService.submit(() -> { |
||||
|
onAlarmUpdate(tenantId, alarm.getNotificationRuleId(), alarm); |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
private void onAlarmUpdate(TenantId tenantId, NotificationRuleId notificationRuleId, Alarm alarm) { |
||||
|
List<NotificationRequest> notificationRequests = notificationService.findNotificationRequestsByRuleIdAndAlarmId(tenantId, notificationRuleId, alarm.getId()); |
||||
|
NotificationRule notificationRule = notificationRuleService.findNotificationRuleById(tenantId, notificationRuleId); |
||||
|
|
||||
|
if (notificationRequests.isEmpty()) { // in case it is first notification for alarm, or it was previously acked and now we need to send notifications again
|
||||
|
NotificationTargetId initialNotificationTargetId = notificationRule.getInitialNotificationTargetId(); |
||||
|
submitNotificationRequest(tenantId, initialNotificationTargetId, notificationRule, alarm, 0); |
||||
|
|
||||
|
for (NonConfirmedNotificationEscalation escalation : notificationRule.getEscalations()) { |
||||
|
submitNotificationRequest(tenantId, escalation.getNotificationTargetId(), notificationRule, alarm, escalation.getDelayInMinutes()); |
||||
|
} |
||||
|
} else { |
||||
|
if (alarmAcknowledged(alarm)) { |
||||
|
for (NotificationRequest notificationRequest : notificationRequests) { |
||||
|
if (notificationRequest.getStatus() == NotificationRequestStatus.SCHEDULED) { |
||||
|
// using regular service due to no need to send an update to subscription manager
|
||||
|
notificationService.deleteNotificationRequestById(tenantId, notificationRequest.getId()); |
||||
|
} else { |
||||
|
notificationSubscriptionService.deleteNotificationRequest(tenantId, notificationRequest.getId()); |
||||
|
// todo: or should we mark already sent notifications as read?
|
||||
|
} |
||||
|
} |
||||
|
} else { |
||||
|
NotificationInfo newNotificationInfo = constructNotificationInfo(alarm, notificationRule); |
||||
|
for (NotificationRequest notificationRequest : notificationRequests) { |
||||
|
NotificationInfo previousNotificationInfo = notificationRequest.getNotificationInfo(); |
||||
|
if (!previousNotificationInfo.equals(newNotificationInfo)) { |
||||
|
notificationRequest.setNotificationInfo(newNotificationInfo); |
||||
|
notificationSubscriptionService.updateNotificationRequest(tenantId, notificationRequest); |
||||
|
} |
||||
|
// fixme: no need to send an update event for scheduled requests, only for sent
|
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private boolean alarmAcknowledged(Alarm alarm) { // todo: decide when to consider the alarm processed by notification target (not to escalate then)
|
||||
|
return alarm.getStatus().isAck() && alarm.getStatus().isCleared(); |
||||
|
} |
||||
|
|
||||
|
private void submitNotificationRequest(TenantId tenantId, NotificationTargetId targetId, NotificationRule notificationRule, Alarm alarm, int delayInMinutes) { |
||||
|
NotificationRequestConfig config = new NotificationRequestConfig(); |
||||
|
if (delayInMinutes > 0) { |
||||
|
config.setSendingDelayInMinutes(delayInMinutes); |
||||
|
} |
||||
|
NotificationInfo notificationInfo = constructNotificationInfo(alarm, notificationRule); |
||||
|
|
||||
|
NotificationRequest notificationRequest = NotificationRequest.builder() |
||||
|
.tenantId(tenantId) |
||||
|
.targetId(targetId) |
||||
|
.notificationReason("Alarm") |
||||
|
.textTemplate(notificationRule.getNotificationTextTemplate()) // todo: format with alarm vars
|
||||
|
.notificationInfo(notificationInfo) |
||||
|
.notificationSeverity(NotificationSeverity.NORMAL) // todo: from alarm severity
|
||||
|
.additionalConfig(config) |
||||
|
.ruleId(notificationRule.getId()) |
||||
|
.alarmId(alarm.getId()) |
||||
|
.build(); |
||||
|
notificationSubscriptionService.processNotificationRequest(tenantId, notificationRequest); |
||||
|
} |
||||
|
|
||||
|
private NotificationInfo constructNotificationInfo(Alarm alarm, NotificationRule notificationRule) { |
||||
|
return NotificationInfo.builder() |
||||
|
.alarmId(alarm.getId()) |
||||
|
.alarmType(alarm.getType()) |
||||
|
.alarmOriginator(alarm.getOriginator()) |
||||
|
.alarmSeverity(alarm.getSeverity()) |
||||
|
.alarmStatus(alarm.getStatus()) |
||||
|
.build(); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,28 @@ |
|||||
|
/** |
||||
|
* 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 com.google.common.util.concurrent.ListenableFuture; |
||||
|
import org.thingsboard.server.common.data.alarm.Alarm; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
|
||||
|
public interface NotificationRuleProcessingService { |
||||
|
|
||||
|
ListenableFuture<?> onAlarmCreatedOrUpdated(TenantId tenantId, Alarm alarm); |
||||
|
|
||||
|
ListenableFuture<?> onAlarmAcknowledged(TenantId tenantId, Alarm alarm); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
/** |
||||
|
* 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.ws.notification.sub; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Builder; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import org.thingsboard.server.common.data.id.NotificationRequestId; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationInfo; |
||||
|
|
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
@Builder |
||||
|
public class NotificationRequestUpdate { |
||||
|
private NotificationRequestId notificationRequestId; |
||||
|
private NotificationInfo notificationInfo; |
||||
|
private boolean deleted; |
||||
|
} |
||||
@ -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.service.ws.notification.sub; |
||||
|
|
||||
|
import lombok.AllArgsConstructor; |
||||
|
import lombok.Builder; |
||||
|
import lombok.Data; |
||||
|
import lombok.NoArgsConstructor; |
||||
|
import org.thingsboard.server.common.data.notification.Notification; |
||||
|
|
||||
|
@Data |
||||
|
@NoArgsConstructor |
||||
|
@AllArgsConstructor |
||||
|
@Builder |
||||
|
public class NotificationUpdate { |
||||
|
private Notification notification; |
||||
|
private boolean isNew; |
||||
|
} |
||||
@ -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.notification; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.id.NotificationRuleId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
||||
|
|
||||
|
public interface NotificationRuleService { |
||||
|
|
||||
|
NotificationRule findNotificationRuleById(TenantId tenantId, NotificationRuleId notificationRuleId); |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,36 @@ |
|||||
|
/** |
||||
|
* 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 com.fasterxml.jackson.annotation.JsonProperty; |
||||
|
import org.thingsboard.server.common.data.EntityType; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
public class NotificationRuleId extends UUIDBased { |
||||
|
|
||||
|
@JsonCreator |
||||
|
public NotificationRuleId(@JsonProperty("id") UUID id) { |
||||
|
super(id); |
||||
|
} |
||||
|
|
||||
|
// @Override
|
||||
|
// public EntityType getEntityType() {
|
||||
|
// return EntityType.NOTIFICATION_TARGET;
|
||||
|
// }
|
||||
|
|
||||
|
} |
||||
@ -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 NotificationRequestStatus { |
||||
|
PROCESSED, |
||||
|
SCHEDULED |
||||
|
} |
||||
@ -0,0 +1,65 @@ |
|||||
|
/** |
||||
|
* 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 lombok.Data; |
||||
|
import lombok.EqualsAndHashCode; |
||||
|
import org.hibernate.annotations.TypeDef; |
||||
|
import org.thingsboard.server.common.data.id.NotificationRuleId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
||||
|
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_RULE_TABLE_NAME) |
||||
|
public class NotificationRuleEntity extends BaseSqlEntity<NotificationRule> { |
||||
|
|
||||
|
@Column(name = ModelConstants.TENANT_ID_PROPERTY, nullable = false) |
||||
|
private UUID tenantId; |
||||
|
|
||||
|
@Column(name = ModelConstants.NAME_PROPERTY, nullable = false) |
||||
|
private String name; |
||||
|
|
||||
|
|
||||
|
public NotificationRuleEntity() {} |
||||
|
|
||||
|
public NotificationRuleEntity(NotificationRule notificationRule) { |
||||
|
setId(notificationRule.getUuidId()); |
||||
|
setCreatedTime(notificationRule.getCreatedTime()); |
||||
|
setTenantId(getUuid(notificationRule.getTenantId())); |
||||
|
setName(notificationRule.getName()); |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
public NotificationRule toData() { |
||||
|
NotificationRule notificationRule = new NotificationRule(); |
||||
|
notificationRule.setId(new NotificationRuleId(id)); |
||||
|
notificationRule.setCreatedTime(createdTime); |
||||
|
notificationRule.setTenantId(createId(tenantId, TenantId::fromUUID)); |
||||
|
notificationRule.setName(name); |
||||
|
return notificationRule; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -0,0 +1,35 @@ |
|||||
|
/** |
||||
|
* 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 org.springframework.stereotype.Service; |
||||
|
import org.thingsboard.server.common.data.id.NotificationRuleId; |
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.notification.rule.NotificationRule; |
||||
|
|
||||
|
@Service |
||||
|
@RequiredArgsConstructor |
||||
|
public class DefaultNotificationRuleService implements NotificationRuleService { |
||||
|
|
||||
|
private final NotificationRuleDao notificationRuleDao; |
||||
|
|
||||
|
@Override |
||||
|
public NotificationRule findNotificationRuleById(TenantId tenantId, NotificationRuleId notificationRuleId) { |
||||
|
return notificationRuleDao.findById(tenantId, notificationRuleId.getId()); |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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.rule.NotificationRule; |
||||
|
import org.thingsboard.server.dao.Dao; |
||||
|
|
||||
|
public interface NotificationRuleDao extends Dao<NotificationRule> { |
||||
|
} |
||||
@ -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.rule.NotificationRule; |
||||
|
import org.thingsboard.server.dao.model.sql.NotificationRuleEntity; |
||||
|
import org.thingsboard.server.dao.notification.NotificationRuleDao; |
||||
|
import org.thingsboard.server.dao.sql.JpaAbstractDao; |
||||
|
import org.thingsboard.server.dao.util.SqlDao; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
@Component |
||||
|
@SqlDao |
||||
|
@RequiredArgsConstructor |
||||
|
public class JpaNotificationRuleDao extends JpaAbstractDao<NotificationRuleEntity, NotificationRule> implements NotificationRuleDao { |
||||
|
|
||||
|
private final NotificationRuleRepository notificationRuleRepository; |
||||
|
|
||||
|
@Override |
||||
|
protected Class<NotificationRuleEntity> getEntityClass() { |
||||
|
return NotificationRuleEntity.class; |
||||
|
} |
||||
|
|
||||
|
@Override |
||||
|
protected JpaRepository<NotificationRuleEntity, UUID> getRepository() { |
||||
|
return notificationRuleRepository; |
||||
|
} |
||||
|
|
||||
|
} |
||||
@ -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.NotificationRuleEntity; |
||||
|
|
||||
|
import java.util.UUID; |
||||
|
|
||||
|
@Repository |
||||
|
public interface NotificationRuleRepository extends JpaRepository<NotificationRuleEntity, UUID> { |
||||
|
} |
||||
@ -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.rule.engine.api; |
||||
|
|
||||
|
import org.thingsboard.server.common.data.id.TenantId; |
||||
|
import org.thingsboard.server.common.data.notification.NotificationRequest; |
||||
|
|
||||
|
public interface RuleEngineNotificationService { |
||||
|
|
||||
|
NotificationRequest processNotificationRequest(TenantId tenantId, NotificationRequest notificationRequest); |
||||
|
|
||||
|
} |
||||
Loading…
Reference in new issue