refactoring: - Customer controller - fix bug: org.thingsboard.server.edge.sql.EdgeSqlTest.testAlarms(org.thingsboard.server.edge.sql.EdgeSqlTest)
This commit is contained in:
parent
fa9f464810
commit
bc71c22e62
@ -71,9 +71,9 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
||||
public <E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity,
|
||||
CustomerId customerId, ActionType actionType,
|
||||
List<EdgeId> relatedEdgeIds,
|
||||
SecurityUser user, boolean isBody, Object... additionalInfo) {
|
||||
SecurityUser user, Object... additionalInfo) {
|
||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, additionalInfo);
|
||||
sendDeleteNotificationMsg(tenantId, entityId, entity, relatedEdgeIds, isBody);
|
||||
sendDeleteNotificationMsg(tenantId, entityId, entity, relatedEdgeIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -194,10 +194,16 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
||||
sendEntityNotificationMsg(alarm.getTenantId(), alarm.getId(), edgeTypeByActionType (actionType));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDeleteAlarm(Alarm alarm, SecurityUser user, List<EdgeId> relatedEdgeIds) {
|
||||
logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarm, alarm.getCustomerId(), ActionType.ALARM_DELETE, user, null);
|
||||
sendAlarmDeleteNotificationMsg(alarm, relatedEdgeIds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void notifyDeleteCustomer(Customer customer, SecurityUser user, List<EdgeId> edgeIds) {
|
||||
logEntityAction(customer.getTenantId(), customer.getId(), customer, customer.getId(), ActionType.DELETED, user, null);
|
||||
sendDeleteNotificationMsg(customer.getTenantId(), customer.getId(), customer, edgeIds, false);
|
||||
sendDeleteNotificationMsg(customer.getTenantId(), customer.getId(), customer, edgeIds);
|
||||
tbClusterService.broadcastEntityStateChangeEvent(customer.getTenantId(), customer.getId(), ComponentLifecycleEvent.DELETED);
|
||||
}
|
||||
|
||||
@ -227,15 +233,22 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
||||
}
|
||||
}
|
||||
|
||||
protected <E extends HasName, I extends EntityId> void sendDeleteNotificationMsg(TenantId tenantId, I entityId, E entity, List<EdgeId> edgeIds, boolean isBody) {
|
||||
protected <E extends HasName, I extends EntityId> void sendDeleteNotificationMsg(TenantId tenantId, I entityId, E entity, List<EdgeId> edgeIds) {
|
||||
try {
|
||||
String body = isBody ? json.writeValueAsString(entity) : null;
|
||||
sendDeleteNotificationMsg(tenantId, entityId, edgeIds, body);
|
||||
sendDeleteNotificationMsg(tenantId, entityId, edgeIds, null);
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to push delete " + entity.getClass().getName() + " msg to core: {}", entity, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected void sendAlarmDeleteNotificationMsg(Alarm alarm, List<EdgeId> relatedEdgeIds) {
|
||||
try {
|
||||
sendDeleteNotificationMsg(alarm.getTenantId(), alarm.getId(), relatedEdgeIds, json.writeValueAsString(alarm));
|
||||
} catch (Exception e) {
|
||||
log.warn("Failed to push delete alarm msg to core: {}", alarm, e);
|
||||
}
|
||||
}
|
||||
|
||||
private void sendDeleteNotificationMsg(TenantId tenantId, EntityId entityId, List<EdgeId> edgeIds, String body) {
|
||||
if (edgeIds != null && !edgeIds.isEmpty()) {
|
||||
for (EdgeId edgeId : edgeIds) {
|
||||
|
||||
@ -46,7 +46,7 @@ public interface TbNotificationEntityService {
|
||||
|
||||
<E extends HasName, I extends EntityId> void notifyDeleteEntity(TenantId tenantId, I entityId, E entity, CustomerId customerId,
|
||||
ActionType actionType, List<EdgeId> relatedEdgeIds, SecurityUser user,
|
||||
boolean isBody, Object... additionalInfo);
|
||||
Object... additionalInfo);
|
||||
|
||||
<E extends HasName, I extends EntityId> void notifyAssignOrUnassignEntityToCustomer(TenantId tenantId, I entityId,
|
||||
CustomerId customerId, E entity,
|
||||
@ -81,6 +81,7 @@ public interface TbNotificationEntityService {
|
||||
|
||||
void notifyCreateOrUpdateAlarm(Alarm alarm, ActionType actionType, SecurityUser user, Object... additionalInfo);
|
||||
|
||||
void notifyDeleteAlarm(Alarm alarm, SecurityUser user, List<EdgeId> relatedEdgeIds);
|
||||
|
||||
void notifyDeleteCustomer(Customer customer, SecurityUser user, List<EdgeId> relatedEdgeIds);
|
||||
}
|
||||
|
||||
@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.thingsboard.server.service.entitiy.alarm;
|
||||
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
@ -79,8 +78,7 @@ public class DefaultTbAlarmService extends AbstractTbEntityService implements Tb
|
||||
@Override
|
||||
public Boolean delete(Alarm alarm, SecurityUser user) throws ThingsboardException {
|
||||
List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(alarm.getTenantId(), alarm.getOriginator());
|
||||
notificationEntityService.notifyDeleteEntity(alarm.getTenantId(), alarm.getOriginator(), alarm, alarm.getCustomerId(),
|
||||
ActionType.ALARM_DELETE, relatedEdgeIds, user, true);
|
||||
notificationEntityService.notifyDeleteAlarm(alarm, user, relatedEdgeIds);
|
||||
return alarmService.deleteAlarm(alarm.getTenantId(), alarm.getId()).isSuccessful();
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user