|
|
@ -15,9 +15,6 @@ |
|
|
*/ |
|
|
*/ |
|
|
package org.thingsboard.server.service.entitiy.alarm; |
|
|
package org.thingsboard.server.service.entitiy.alarm; |
|
|
|
|
|
|
|
|
import com.google.common.util.concurrent.FutureCallback; |
|
|
|
|
|
import com.google.common.util.concurrent.Futures; |
|
|
|
|
|
import com.google.common.util.concurrent.ListenableFuture; |
|
|
|
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.AllArgsConstructor; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import lombok.extern.slf4j.Slf4j; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
import org.springframework.beans.factory.annotation.Autowired; |
|
|
@ -32,7 +29,6 @@ import org.thingsboard.server.common.data.alarm.AlarmComment; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmCommentType; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmCommentType; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmCreateOrUpdateActiveRequest; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmCreateOrUpdateActiveRequest; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmInfo; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmInfo; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmQueryV2; |
|
|
|
|
|
import org.thingsboard.server.common.data.alarm.AlarmUpdateRequest; |
|
|
import org.thingsboard.server.common.data.alarm.AlarmUpdateRequest; |
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
import org.thingsboard.server.common.data.audit.ActionType; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
|
|
import org.thingsboard.server.common.data.exception.ThingsboardErrorCode; |
|
|
@ -40,8 +36,6 @@ import org.thingsboard.server.common.data.exception.ThingsboardException; |
|
|
import org.thingsboard.server.common.data.id.EdgeId; |
|
|
import org.thingsboard.server.common.data.id.EdgeId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.TenantId; |
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
import org.thingsboard.server.common.data.id.UserId; |
|
|
import org.thingsboard.server.common.data.page.PageData; |
|
|
|
|
|
import org.thingsboard.server.common.data.page.TimePageLink; |
|
|
|
|
|
import org.thingsboard.server.service.entitiy.AbstractTbEntityService; |
|
|
import org.thingsboard.server.service.entitiy.AbstractTbEntityService; |
|
|
|
|
|
|
|
|
import java.util.List; |
|
|
import java.util.List; |
|
|
@ -216,47 +210,6 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb |
|
|
return alarmInfo; |
|
|
return alarmInfo; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
public ListenableFuture<Void> unassignUserAlarms(TenantId tenantId, User user, long unassignTs) { |
|
|
|
|
|
AlarmQueryV2 alarmQuery = AlarmQueryV2.builder().assigneeId(user.getId()).pageLink(new TimePageLink(Integer.MAX_VALUE)).build(); |
|
|
|
|
|
ListenableFuture<PageData<AlarmInfo>> foundUserAlarmsFuture = alarmService.findAlarmsV2(tenantId, alarmQuery); |
|
|
|
|
|
FutureCallback<PageData<AlarmInfo>> callback = new FutureCallback<>() { |
|
|
|
|
|
public void onSuccess(PageData<AlarmInfo> alarmsData) { |
|
|
|
|
|
for (AlarmInfo alarm : alarmsData.getData()) { |
|
|
|
|
|
unassignUserAlarm(tenantId, user, unassignTs, alarm); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void onFailure(Throwable t) { |
|
|
|
|
|
log.error("Cannot get alarms for user {}", user.getId(), t); |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
Futures.addCallback(foundUserAlarmsFuture, callback, dbExecutor); |
|
|
|
|
|
return Futures.transform(foundUserAlarmsFuture, alarms -> null, dbExecutor); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void unassignUserAlarm(TenantId tenantId, User user, long unassignTs, AlarmInfo alarm) { |
|
|
|
|
|
AlarmApiCallResult result = alarmSubscriptionService.unassignAlarm(tenantId, alarm.getId(), getOrDefault(unassignTs)); |
|
|
|
|
|
if (!result.isSuccessful()) { |
|
|
|
|
|
return; |
|
|
|
|
|
} |
|
|
|
|
|
if (result.isModified()) { |
|
|
|
|
|
AlarmComment alarmComment = AlarmComment.builder() |
|
|
|
|
|
.alarmId(alarm.getId()) |
|
|
|
|
|
.type(AlarmCommentType.SYSTEM) |
|
|
|
|
|
.comment(JacksonUtil.newObjectNode().put("text", String.format("Alarm was unassigned because user %s - was deleted", |
|
|
|
|
|
(user.getFirstName() == null || user.getLastName() == null) ? user.getName() : user.getFirstName() + " " + user.getLastName())) |
|
|
|
|
|
.put("userId", user.getId().toString()) |
|
|
|
|
|
.put("subtype", "ASSIGN")) |
|
|
|
|
|
.build(); |
|
|
|
|
|
try { |
|
|
|
|
|
alarmCommentService.saveAlarmComment(alarm, alarmComment, user); |
|
|
|
|
|
} catch (ThingsboardException e) { |
|
|
|
|
|
log.error("Failed to save alarm comment", e); |
|
|
|
|
|
} |
|
|
|
|
|
notificationEntityService.notifyCreateOrUpdateAlarm(result.getAlarm(), ActionType.ALARM_UNASSIGNED, user); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
@Override |
|
|
public Boolean delete(Alarm alarm, User user) { |
|
|
public Boolean delete(Alarm alarm, User user) { |
|
|
|