updated alarm comment deletion
This commit is contained in:
parent
d9b1e97bbb
commit
210aae6a86
@ -48,15 +48,7 @@ public class DefaultTbAlarmCommentService extends AbstractTbEntityService implem
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAlarmComment(Alarm alarm, AlarmComment alarmComment, User user) {
|
public void deleteAlarmComment(Alarm alarm, AlarmComment alarmComment, User user) {
|
||||||
alarmCommentService.deleteAlarmComment(alarm.getTenantId(), alarmComment.getId());
|
alarmCommentService.deleteAlarmComment(alarm.getTenantId(), alarmComment, user);
|
||||||
notificationEntityService.notifyAlarmComment(alarm, alarmComment, ActionType.DELETED_COMMENT, user);
|
notificationEntityService.notifyAlarmComment(alarm, alarmComment, ActionType.DELETED_COMMENT, user);
|
||||||
|
|
||||||
AlarmComment.AlarmCommentBuilder commentDeletedComment = AlarmComment.builder()
|
|
||||||
.alarmId(alarm.getId())
|
|
||||||
.type(AlarmCommentType.SYSTEM)
|
|
||||||
.comment(JacksonUtil.newObjectNode().put("text",
|
|
||||||
String.format("User %s deleted his comment", user.getName())));
|
|
||||||
|
|
||||||
alarmCommentService.createOrUpdateAlarmComment(alarm.getTenantId(), commentDeletedComment.build());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,10 +86,11 @@ public class DefaultTbAlarmCommentServiceTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testDelete() {
|
public void testDelete() {
|
||||||
var alarmId = new AlarmId(UUID.randomUUID());
|
var alarmId = new AlarmId(UUID.randomUUID());
|
||||||
var alarmCommentId = new AlarmCommentId(UUID.randomUUID());
|
var alarmComment = new AlarmComment();
|
||||||
|
alarmComment.setAlarmId(alarmId);
|
||||||
|
|
||||||
doNothing().when(alarmCommentService).deleteAlarmComment(Mockito.any(), eq(alarmCommentId));
|
doNothing().when(alarmCommentService).deleteAlarmComment(Mockito.any(), eq(alarmComment), Mockito.any());
|
||||||
service.deleteAlarmComment(new Alarm(alarmId), new AlarmComment(alarmCommentId), new User());
|
service.deleteAlarmComment(new Alarm(alarmId), new AlarmComment(), new User());
|
||||||
|
|
||||||
verify(notificationEntityService, times(1)).notifyAlarmComment(any(), any(), any(), any());
|
verify(notificationEntityService, times(1)).notifyAlarmComment(any(), any(), any(), any());
|
||||||
}
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.dao.alarm;
|
package org.thingsboard.server.dao.alarm;
|
||||||
|
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
|
import org.thingsboard.server.common.data.User;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmComment;
|
import org.thingsboard.server.common.data.alarm.AlarmComment;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmCommentInfo;
|
import org.thingsboard.server.common.data.alarm.AlarmCommentInfo;
|
||||||
import org.thingsboard.server.common.data.id.AlarmCommentId;
|
import org.thingsboard.server.common.data.id.AlarmCommentId;
|
||||||
@ -27,7 +28,7 @@ import org.thingsboard.server.common.data.page.PageLink;
|
|||||||
public interface AlarmCommentService {
|
public interface AlarmCommentService {
|
||||||
AlarmComment createOrUpdateAlarmComment(TenantId tenantId, AlarmComment alarmComment);
|
AlarmComment createOrUpdateAlarmComment(TenantId tenantId, AlarmComment alarmComment);
|
||||||
|
|
||||||
void deleteAlarmComment(TenantId tenantId, AlarmCommentId alarmCommentId);
|
void deleteAlarmComment(TenantId tenantId, AlarmComment alarmComment, User user);
|
||||||
|
|
||||||
PageData<AlarmCommentInfo> findAlarmComments(TenantId tenantId, AlarmId alarmId, PageLink pageLink);
|
PageData<AlarmCommentInfo> findAlarmComments(TenantId tenantId, AlarmId alarmId, PageLink pageLink);
|
||||||
|
|
||||||
|
|||||||
@ -22,12 +22,16 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
|
import org.thingsboard.server.common.data.User;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmComment;
|
import org.thingsboard.server.common.data.alarm.AlarmComment;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmCommentInfo;
|
import org.thingsboard.server.common.data.alarm.AlarmCommentInfo;
|
||||||
import org.thingsboard.server.common.data.alarm.AlarmCommentType;
|
import org.thingsboard.server.common.data.alarm.AlarmCommentType;
|
||||||
import org.thingsboard.server.common.data.id.AlarmCommentId;
|
import org.thingsboard.server.common.data.id.AlarmCommentId;
|
||||||
import org.thingsboard.server.common.data.id.AlarmId;
|
import org.thingsboard.server.common.data.id.AlarmId;
|
||||||
|
import org.thingsboard.server.common.data.id.CustomerId;
|
||||||
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.page.PageData;
|
import org.thingsboard.server.common.data.page.PageData;
|
||||||
import org.thingsboard.server.common.data.page.PageLink;
|
import org.thingsboard.server.common.data.page.PageLink;
|
||||||
import org.thingsboard.server.dao.entity.AbstractEntityService;
|
import org.thingsboard.server.dao.entity.AbstractEntityService;
|
||||||
@ -58,9 +62,20 @@ public class BaseAlarmCommentService extends AbstractEntityService implements Al
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deleteAlarmComment(TenantId tenantId, AlarmCommentId alarmCommentId) {
|
public void deleteAlarmComment(TenantId tenantId, AlarmComment alarmComment, User user) {
|
||||||
log.debug("Deleting Alarm Comment with id: {}", alarmCommentId);
|
log.debug("Deleting Alarm Comment: {}", alarmComment);
|
||||||
alarmCommentDao.deleteAlarmComment(tenantId, alarmCommentId);
|
|
||||||
|
if (alarmComment.getType() == AlarmCommentType.OTHER) {
|
||||||
|
alarmComment.setType(AlarmCommentType.SYSTEM);
|
||||||
|
alarmComment.setUserId(null);
|
||||||
|
alarmComment.setComment(JacksonUtil.newObjectNode().put("text",
|
||||||
|
String.format("User %s deleted his comment",
|
||||||
|
(user.getFirstName() == null || user.getLastName() == null) ? user.getName() : user.getFirstName() + " " + user.getLastName())));
|
||||||
|
alarmCommentDao.save(tenantId, alarmComment);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alarmCommentDao.deleteAlarmComment(tenantId, alarmComment.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -155,7 +155,7 @@ public abstract class BaseAlarmCommentServiceTest extends AbstractServiceTest {
|
|||||||
Assert.assertNotNull(createdComment);
|
Assert.assertNotNull(createdComment);
|
||||||
Assert.assertNotNull(createdComment.getId());
|
Assert.assertNotNull(createdComment.getId());
|
||||||
|
|
||||||
alarmCommentService.deleteAlarmComment(tenantId, createdComment.getId());
|
alarmCommentService.deleteAlarmComment(tenantId, createdComment, user);
|
||||||
|
|
||||||
AlarmComment fetched = alarmCommentService.findAlarmCommentByIdAsync(tenantId, createdComment.getId()).get();
|
AlarmComment fetched = alarmCommentService.findAlarmCommentByIdAsync(tenantId, createdComment.getId()).get();
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user