refactoring: RuleChainController comments1
This commit is contained in:
parent
a778305b03
commit
a6a58a3256
@ -43,6 +43,7 @@ import org.thingsboard.server.actors.tenant.DebugTbRateLimits;
|
|||||||
import org.thingsboard.server.common.data.DataConstants;
|
import org.thingsboard.server.common.data.DataConstants;
|
||||||
import org.thingsboard.server.common.data.Event;
|
import org.thingsboard.server.common.data.Event;
|
||||||
import org.thingsboard.server.common.data.StringUtils;
|
import org.thingsboard.server.common.data.StringUtils;
|
||||||
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.edge.Edge;
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.EdgeId;
|
import org.thingsboard.server.common.data.id.EdgeId;
|
||||||
@ -66,7 +67,6 @@ import org.thingsboard.server.common.msg.TbMsgMetaData;
|
|||||||
import org.thingsboard.server.dao.event.EventService;
|
import org.thingsboard.server.dao.event.EventService;
|
||||||
import org.thingsboard.server.queue.util.TbCoreComponent;
|
import org.thingsboard.server.queue.util.TbCoreComponent;
|
||||||
import org.thingsboard.server.service.entitiy.ruleChain.TbRuleChainNotifyService;
|
import org.thingsboard.server.service.entitiy.ruleChain.TbRuleChainNotifyService;
|
||||||
import org.thingsboard.server.service.install.InstallScripts;
|
|
||||||
import org.thingsboard.server.service.rule.TbRuleChainService;
|
import org.thingsboard.server.service.rule.TbRuleChainService;
|
||||||
import org.thingsboard.server.service.script.JsInvokeService;
|
import org.thingsboard.server.service.script.JsInvokeService;
|
||||||
import org.thingsboard.server.service.script.RuleNodeJsScriptEngine;
|
import org.thingsboard.server.service.script.RuleNodeJsScriptEngine;
|
||||||
@ -142,9 +142,6 @@ public class RuleChainController extends BaseController {
|
|||||||
@Autowired
|
@Autowired
|
||||||
protected TbRuleChainService tbRuleChainService;
|
protected TbRuleChainService tbRuleChainService;
|
||||||
|
|
||||||
@Autowired
|
|
||||||
private InstallScripts installScripts;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private EventService eventService;
|
private EventService eventService;
|
||||||
|
|
||||||
@ -260,7 +257,7 @@ public class RuleChainController extends BaseController {
|
|||||||
|
|
||||||
checkNotNull(request);
|
checkNotNull(request);
|
||||||
checkParameter(request.getName(), "name");
|
checkParameter(request.getName(), "name");
|
||||||
return tbRuleChainNotifyService.saveRuleChain(getTenantId(), request, getCurrentUser());
|
return tbRuleChainNotifyService.saveDefaultByName(getTenantId(), request, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Set Root Rule Chain (setRootRuleChain)",
|
@ApiOperation(value = "Set Root Rule Chain (setRootRuleChain)",
|
||||||
@ -540,9 +537,10 @@ public class RuleChainController extends BaseController {
|
|||||||
Edge edge = checkEdgeId(edgeId, Operation.WRITE);
|
Edge edge = checkEdgeId(edgeId, Operation.WRITE);
|
||||||
|
|
||||||
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
||||||
checkRuleChain(ruleChainId, Operation.READ);
|
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.READ);
|
||||||
|
|
||||||
return tbRuleChainNotifyService.assignRuleChainToEdge(getTenantId(), ruleChainId, edge, getCurrentUser());
|
return tbRuleChainNotifyService.assignUnassignRuleChainToEdge(getTenantId(), ruleChain, edge,
|
||||||
|
ActionType.ASSIGNED_TO_EDGE, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unassign rule chain from edge (unassignRuleChainFromEdge)",
|
@ApiOperation(value = "Unassign rule chain from edge (unassignRuleChainFromEdge)",
|
||||||
@ -564,7 +562,8 @@ public class RuleChainController extends BaseController {
|
|||||||
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
||||||
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.READ);
|
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.READ);
|
||||||
|
|
||||||
return tbRuleChainNotifyService.unassignRuleChainFromEdge(getTenantId(), ruleChain, edge, getCurrentUser());
|
return tbRuleChainNotifyService.assignUnassignRuleChainToEdge(getTenantId(), ruleChain, edge,
|
||||||
|
ActionType.UNASSIGNED_FROM_EDGE, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Get Edge Rule Chains (getEdgeRuleChains)",
|
@ApiOperation(value = "Get Edge Rule Chains (getEdgeRuleChains)",
|
||||||
@ -608,7 +607,7 @@ public class RuleChainController extends BaseController {
|
|||||||
checkParameter(RULE_CHAIN_ID, strRuleChainId);
|
checkParameter(RULE_CHAIN_ID, strRuleChainId);
|
||||||
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
||||||
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.WRITE);
|
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.WRITE);
|
||||||
return tbRuleChainNotifyService.setEdgeRuleChain(getTenantId(), ruleChain, getCurrentUser(), true);
|
return tbRuleChainNotifyService.setEdgeTemplateRootRuleChain(getTenantId(), ruleChain, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Set Auto Assign To Edge Rule Chain (setAutoAssignToEdgeRuleChain)",
|
@ApiOperation(value = "Set Auto Assign To Edge Rule Chain (setAutoAssignToEdgeRuleChain)",
|
||||||
@ -622,7 +621,7 @@ public class RuleChainController extends BaseController {
|
|||||||
checkParameter(RULE_CHAIN_ID, strRuleChainId);
|
checkParameter(RULE_CHAIN_ID, strRuleChainId);
|
||||||
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
|
||||||
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.WRITE);
|
RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.WRITE);
|
||||||
return tbRuleChainNotifyService.setEdgeRuleChain(getTenantId(), ruleChain, getCurrentUser(), false);
|
return tbRuleChainNotifyService.setAutoAssignToEdgeRuleChain(getTenantId(), ruleChain, getCurrentUser());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ApiOperation(value = "Unset Auto Assign To Edge Rule Chain (unsetAutoAssignToEdgeRuleChain)",
|
@ApiOperation(value = "Unset Auto Assign To Edge Rule Chain (unsetAutoAssignToEdgeRuleChain)",
|
||||||
|
|||||||
@ -77,7 +77,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
CustomerId customerId, ActionType actionType,
|
CustomerId customerId, ActionType actionType,
|
||||||
List<EdgeId> relatedEdgeIds,
|
List<EdgeId> relatedEdgeIds,
|
||||||
SecurityUser user, Object... additionalInfo) {
|
SecurityUser user, Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, null, additionalInfo);
|
||||||
sendDeleteNotificationMsg(tenantId, entityId, entity, relatedEdgeIds);
|
sendDeleteNotificationMsg(tenantId, entityId, entity, relatedEdgeIds);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,15 +86,15 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
List<EdgeId> relatedEdgeIds,
|
List<EdgeId> relatedEdgeIds,
|
||||||
SecurityUser user,
|
SecurityUser user,
|
||||||
String body, Object... additionalInfo) {
|
String body, Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, originatorId, alarm, customerId, ActionType.DELETED, user, additionalInfo);
|
logEntityAction(tenantId, originatorId, alarm, customerId, ActionType.DELETED, user, null, additionalInfo);
|
||||||
sendAlarmDeleteNotificationMsg(tenantId, alarm, relatedEdgeIds, body);
|
sendAlarmDeleteNotificationMsg(tenantId, alarm, relatedEdgeIds, body);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyDeleteRuleChane(TenantId tenantId, RuleChain ruleChain,
|
public void notifyDeleteRuleChain(TenantId tenantId, RuleChain ruleChain,
|
||||||
List<EdgeId> relatedEdgeIds, SecurityUser user) {
|
List<EdgeId> relatedEdgeIds, SecurityUser user) {
|
||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
logEntityAction(tenantId, ruleChainId, ruleChain, null, ActionType.DELETED, user, ruleChainId.toString());
|
logEntityAction(tenantId, ruleChainId, ruleChain, null, ActionType.DELETED, user, null, ruleChainId.toString());
|
||||||
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
||||||
sendDeleteNotificationMsg(tenantId, ruleChainId, relatedEdgeIds, null);
|
sendDeleteNotificationMsg(tenantId, ruleChainId, relatedEdgeIds, null);
|
||||||
}
|
}
|
||||||
@ -108,7 +108,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
RuleChain updatedRuleChain = (RuleChain)others[0];
|
RuleChain updatedRuleChain = (RuleChain)others[0];
|
||||||
RuleChainMetaData updatedRuleChainMetaData = (RuleChainMetaData)others[1];
|
RuleChainMetaData updatedRuleChainMetaData = (RuleChainMetaData)others[1];
|
||||||
SecurityUser user = (SecurityUser)others[2];
|
SecurityUser user = (SecurityUser)others[2];
|
||||||
logEntityAction(tenantId, updatedRuleChain.getId(), updatedRuleChain, null, ActionType.UPDATED, user, updatedRuleChainMetaData);
|
logEntityAction(tenantId, updatedRuleChain.getId(), updatedRuleChain, null, ActionType.UPDATED, user, null, updatedRuleChainMetaData);
|
||||||
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
|
||||||
sendEntityNotificationMsg(updatedRuleChain.getTenantId(), updatedRuleChain.getId(), EdgeEventActionType.UPDATED);
|
sendEntityNotificationMsg(updatedRuleChain.getTenantId(), updatedRuleChain.getId(), EdgeEventActionType.UPDATED);
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
EdgeEventActionType edgeActionType,
|
EdgeEventActionType edgeActionType,
|
||||||
SecurityUser user, boolean sendToEdge,
|
SecurityUser user, boolean sendToEdge,
|
||||||
Object... additionalInfo) {
|
Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, null, additionalInfo);
|
||||||
|
|
||||||
if (sendToEdge) {
|
if (sendToEdge) {
|
||||||
sendEntityAssignToCustomerNotificationMsg(tenantId, entityId, customerId, edgeActionType);
|
sendEntityAssignToCustomerNotificationMsg(tenantId, entityId, customerId, edgeActionType);
|
||||||
@ -134,7 +134,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
CustomerId customerId, EdgeId edgeId,
|
CustomerId customerId, EdgeId edgeId,
|
||||||
E entity, ActionType actionType,
|
E entity, ActionType actionType,
|
||||||
SecurityUser user, Object... additionalInfo) {
|
SecurityUser user, Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, null, additionalInfo);
|
||||||
sendEntityAssignToEdgeNotificationMsg(tenantId, edgeId, entityId, edgeTypeByActionType(actionType));
|
sendEntityAssignToEdgeNotificationMsg(tenantId, edgeId, entityId, edgeTypeByActionType(actionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,7 +155,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
Device device, Device oldDevice, ActionType actionType,
|
Device device, Device oldDevice, ActionType actionType,
|
||||||
SecurityUser user, Object... additionalInfo) {
|
SecurityUser user, Object... additionalInfo) {
|
||||||
tbClusterService.onDeviceUpdated(device, oldDevice);
|
tbClusterService.onDeviceUpdated(device, oldDevice);
|
||||||
logEntityAction(tenantId, deviceId, device, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, deviceId, device, customerId, actionType, user, null, additionalInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -172,19 +172,19 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
DeviceCredentials deviceCredentials, SecurityUser user) {
|
DeviceCredentials deviceCredentials, SecurityUser user) {
|
||||||
tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(tenantId, deviceCredentials.getDeviceId(), deviceCredentials), null);
|
tbClusterService.pushMsgToCore(new DeviceCredentialsUpdateNotificationMsg(tenantId, deviceCredentials.getDeviceId(), deviceCredentials), null);
|
||||||
sendEntityNotificationMsg(tenantId, deviceId, EdgeEventActionType.CREDENTIALS_UPDATED);
|
sendEntityNotificationMsg(tenantId, deviceId, EdgeEventActionType.CREDENTIALS_UPDATED);
|
||||||
logEntityAction(tenantId, deviceId, device, customerId, ActionType.CREDENTIALS_UPDATED, user, deviceCredentials);
|
logEntityAction(tenantId, deviceId, device, customerId, ActionType.CREDENTIALS_UPDATED, user, null, deviceCredentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyAssignDeviceToTenant(TenantId tenantId, TenantId newTenantId, DeviceId deviceId, CustomerId customerId,
|
public void notifyAssignDeviceToTenant(TenantId tenantId, TenantId newTenantId, DeviceId deviceId, CustomerId customerId,
|
||||||
Device device, Tenant tenant, SecurityUser user, Object... additionalInfo) {
|
Device device, Tenant tenant, SecurityUser user, Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, deviceId, device, customerId, ActionType.ASSIGNED_TO_TENANT, user, additionalInfo);
|
logEntityAction(tenantId, deviceId, device, customerId, ActionType.ASSIGNED_TO_TENANT, user, null, additionalInfo);
|
||||||
pushAssignedFromNotification(tenant, newTenantId, device);
|
pushAssignedFromNotification(tenant, newTenantId, device);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends HasName, I extends EntityId> void notifyCreateOrUpdateEntity(TenantId tenantId, I entityId, E entity, CustomerId customerId, ActionType actionType, SecurityUser user, Object... additionalInfo) {
|
public <E extends HasName, I extends EntityId> void notifyCreateOrUpdateEntity(TenantId tenantId, I entityId, E entity, CustomerId customerId, ActionType actionType, SecurityUser user, Object... additionalInfo) {
|
||||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, null, additionalInfo);
|
||||||
if (actionType == ActionType.UPDATED) {
|
if (actionType == ActionType.UPDATED) {
|
||||||
sendEntityNotificationMsg(tenantId, entityId, EdgeEventActionType.UPDATED);
|
sendEntityNotificationMsg(tenantId, entityId, EdgeEventActionType.UPDATED);
|
||||||
}
|
}
|
||||||
@ -218,7 +218,7 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
}
|
}
|
||||||
|
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(tenantId, edgeId, lifecycleEvent);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, edgeId, lifecycleEvent);
|
||||||
logEntityAction(tenantId, edgeId, edge, customerId, actionType, user, additionalInfo);
|
logEntityAction(tenantId, edgeId, edge, customerId, actionType, user, null, additionalInfo);
|
||||||
|
|
||||||
//Send notification to edge
|
//Send notification to edge
|
||||||
if (edgeEventActionType != null) {
|
if (edgeEventActionType != null) {
|
||||||
@ -228,17 +228,17 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void notifyCreateOrUpdateAlarm(Alarm alarm, ActionType actionType, SecurityUser user, Object... additionalInfo) {
|
public void notifyCreateOrUpdateAlarm(Alarm alarm, ActionType actionType, SecurityUser user, Object... additionalInfo) {
|
||||||
logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarm, alarm.getCustomerId(), actionType, user, additionalInfo);
|
logEntityAction(alarm.getTenantId(), alarm.getOriginator(), alarm, alarm.getCustomerId(), actionType, user, null, additionalInfo);
|
||||||
sendEntityNotificationMsg(alarm.getTenantId(), alarm.getId(), edgeTypeByActionType(actionType));
|
sendEntityNotificationMsg(alarm.getTenantId(), alarm.getId(), edgeTypeByActionType(actionType));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <E extends HasName, I extends EntityId> void notifyCreateOrUpdateOrDelete(TenantId tenantId, CustomerId customerId,
|
public <E extends HasName, I extends EntityId> void notifyCreateOrUpdateOrDelete(TenantId tenantId, CustomerId customerId,
|
||||||
I entityId, E entity, SecurityUser user,
|
I entityId, E entity, SecurityUser user,
|
||||||
ActionType actionType, boolean isSendMsg, Exception e,
|
ActionType actionType, boolean sendNotifyMsgToEdge, Exception e,
|
||||||
Object... additionalInfo) {
|
Object... additionalInfo) {
|
||||||
notifyEntity(tenantId, entityId, entity, customerId, actionType, user, e, additionalInfo);
|
notifyEntity(tenantId, entityId, entity, customerId, actionType, user, e, additionalInfo);
|
||||||
if (isSendMsg) {
|
if (sendNotifyMsgToEdge) {
|
||||||
sendEntityNotificationMsg(tenantId, entityId, edgeTypeByActionType(actionType));
|
sendEntityNotificationMsg(tenantId, entityId, edgeTypeByActionType(actionType));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -263,11 +263,6 @@ public class DefaultTbNotificationEntityService implements TbNotificationEntityS
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private <E extends HasName, I extends EntityId> void logEntityAction(TenantId tenantId, I entityId, E entity, CustomerId customerId,
|
|
||||||
ActionType actionType, SecurityUser user, Object... additionalInfo) {
|
|
||||||
logEntityAction(tenantId, entityId, entity, customerId, actionType, user, null, additionalInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <E extends HasName, I extends EntityId> void logEntityAction(TenantId tenantId, I entityId, E entity, CustomerId customerId,
|
private <E extends HasName, I extends EntityId> void logEntityAction(TenantId tenantId, I entityId, E entity, CustomerId customerId,
|
||||||
ActionType actionType, SecurityUser user, Exception e, Object... additionalInfo) {
|
ActionType actionType, SecurityUser user, Exception e, Object... additionalInfo) {
|
||||||
if (user != null) {
|
if (user != null) {
|
||||||
|
|||||||
@ -54,8 +54,8 @@ public interface TbNotificationEntityService {
|
|||||||
CustomerId customerId, List<EdgeId> relatedEdgeIds,
|
CustomerId customerId, List<EdgeId> relatedEdgeIds,
|
||||||
SecurityUser user, String body, Object... additionalInfo);
|
SecurityUser user, String body, Object... additionalInfo);
|
||||||
|
|
||||||
void notifyDeleteRuleChane(TenantId tenantId, RuleChain ruleChain,
|
void notifyDeleteRuleChain(TenantId tenantId, RuleChain ruleChain,
|
||||||
List<EdgeId> relatedEdgeIds, SecurityUser user);
|
List<EdgeId> relatedEdgeIds, SecurityUser user);
|
||||||
|
|
||||||
void notifySaveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, Object... others);
|
void notifySaveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, Object... others);
|
||||||
|
|
||||||
@ -95,7 +95,7 @@ public interface TbNotificationEntityService {
|
|||||||
|
|
||||||
<E extends HasName, I extends EntityId> void notifyCreateOrUpdateOrDelete(TenantId tenantId, CustomerId customerId,
|
<E extends HasName, I extends EntityId> void notifyCreateOrUpdateOrDelete(TenantId tenantId, CustomerId customerId,
|
||||||
I entityId, E entity, SecurityUser user,
|
I entityId, E entity, SecurityUser user,
|
||||||
ActionType actionType, boolean isSendMsg, Exception e,
|
ActionType actionType, boolean sendNotifyMsgToEdge, Exception e,
|
||||||
Object... additionalInfo);
|
Object... additionalInfo);
|
||||||
|
|
||||||
void notifyCreateOrUpdateOrDeleteRelation(TenantId tenantId, CustomerId customerId,
|
void notifyCreateOrUpdateOrDeleteRelation(TenantId tenantId, CustomerId customerId,
|
||||||
|
|||||||
@ -72,8 +72,6 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
TenantId tenantId = ruleChain.getTenantId();
|
TenantId tenantId = ruleChain.getTenantId();
|
||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
|
|
||||||
List<RuleNode> referencingRuleNodes = ruleChainService.getReferencingRuleChainNodes(tenantId, ruleChainId);
|
List<RuleNode> referencingRuleNodes = ruleChainService.getReferencingRuleChainNodes(tenantId, ruleChainId);
|
||||||
|
|
||||||
Set<RuleChainId> referencingRuleChainIds = referencingRuleNodes.stream().map(RuleNode::getRuleChainId).collect(Collectors.toSet());
|
Set<RuleChainId> referencingRuleChainIds = referencingRuleNodes.stream().map(RuleNode::getRuleChainId).collect(Collectors.toSet());
|
||||||
@ -94,16 +92,16 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
tbClusterService.broadcastEntityStateChangeEvent(tenantId, ruleChain.getId(), ComponentLifecycleEvent.DELETED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, ruleChain.getId(), ComponentLifecycleEvent.DELETED);
|
||||||
}
|
}
|
||||||
|
|
||||||
notificationEntityService.notifyDeleteRuleChane(tenantId, ruleChain, relatedEdgeIds, user);
|
notificationEntityService.notifyDeleteRuleChain(tenantId, ruleChain, relatedEdgeIds, user);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
||||||
null, user, ActionType.DELETED, false, e, ruleChainId.toString());
|
null, user, ActionType.DELETED, false, e, ruleChainId.toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleChain saveRuleChain(TenantId tenantId, DefaultRuleChainCreateRequest request, SecurityUser user) throws ThingsboardException {
|
public RuleChain saveDefaultByName(TenantId tenantId, DefaultRuleChainCreateRequest request, SecurityUser user) throws ThingsboardException {
|
||||||
try {
|
try {
|
||||||
RuleChain savedRuleChain = installScripts.createDefaultRuleChain(tenantId, request.getName());
|
RuleChain savedRuleChain = installScripts.createDefaultRuleChain(tenantId, request.getName());
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(tenantId, savedRuleChain.getId(), ComponentLifecycleEvent.CREATED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, savedRuleChain.getId(), ComponentLifecycleEvent.CREATED);
|
||||||
@ -144,7 +142,7 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
return ruleChain;
|
return ruleChain;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
||||||
ruleChain, user, ActionType.UPDATED, false, e, ruleChainId.toString());
|
ruleChain, user, ActionType.UPDATED, false, e, ruleChainId.toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -153,24 +151,24 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
public RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, RuleChainMetaData ruleChainMetaData,
|
public RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, RuleChainMetaData ruleChainMetaData,
|
||||||
boolean updateRelated, SecurityUser user) throws ThingsboardException {
|
boolean updateRelated, SecurityUser user) throws ThingsboardException {
|
||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
|
RuleChainId ruleChainMetaDataId = ruleChainMetaData.getRuleChainId();
|
||||||
try {
|
try {
|
||||||
|
|
||||||
RuleChainUpdateResult result = ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData);
|
RuleChainUpdateResult result = ruleChainService.saveRuleChainMetaData(tenantId, ruleChainMetaData);
|
||||||
checkNotNull(result.isSuccess() ? true : null);
|
checkNotNull(result.isSuccess() ? true : null);
|
||||||
|
|
||||||
List<RuleChain> updatedRuleChains;
|
List<RuleChain> updatedRuleChains;
|
||||||
if (updateRelated && result.isSuccess()) {
|
if (updateRelated && result.isSuccess()) {
|
||||||
updatedRuleChains = tbRuleChainService.updateRelatedRuleChains(tenantId, ruleChainMetaData.getRuleChainId(), result);
|
updatedRuleChains = tbRuleChainService.updateRelatedRuleChains(tenantId, ruleChainMetaDataId, result);
|
||||||
} else {
|
} else {
|
||||||
updatedRuleChains = Collections.emptyList();
|
updatedRuleChains = Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaData.getRuleChainId()));
|
RuleChainMetaData savedRuleChainMetaData = checkNotNull(ruleChainService.loadRuleChainMetaData(tenantId, ruleChainMetaDataId));
|
||||||
|
|
||||||
if (RuleChainType.CORE.equals(ruleChain.getType())) {
|
if (RuleChainType.CORE.equals(ruleChain.getType())) {
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(ruleChain.getTenantId(), ruleChain.getId(), ComponentLifecycleEvent.UPDATED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, ruleChainId, ComponentLifecycleEvent.UPDATED);
|
||||||
updatedRuleChains.forEach(updatedRuleChain -> {
|
updatedRuleChains.forEach(updatedRuleChain -> {
|
||||||
tbClusterService.broadcastEntityStateChangeEvent(updatedRuleChain.getTenantId(), updatedRuleChain.getId(), ComponentLifecycleEvent.UPDATED);
|
tbClusterService.broadcastEntityStateChangeEvent(tenantId, updatedRuleChain.getId(), ComponentLifecycleEvent.UPDATED);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -191,56 +189,51 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
return savedRuleChainMetaData;
|
return savedRuleChainMetaData;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
||||||
null, user, ActionType.ADDED, false, e, ruleChainMetaData);
|
null, user, ActionType.ADDED, false, e, ruleChainMetaData);
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleChain assignRuleChainToEdge(TenantId tenantId, RuleChainId ruleChainId, Edge edge, SecurityUser user) throws ThingsboardException {
|
public RuleChain assignUnassignRuleChainToEdge(TenantId tenantId, RuleChain ruleChain, Edge edge, ActionType actionType, SecurityUser user) throws ThingsboardException {
|
||||||
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
try {
|
try {
|
||||||
RuleChain savedRuleChain = checkNotNull(ruleChainService.assignRuleChainToEdge(tenantId, ruleChainId, edge.getId()));
|
RuleChain savedRuleChain = checkNotNull(ruleChainService.assignRuleChainToEdge(tenantId, ruleChainId, edge.getId()));
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, ruleChainId,
|
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, ruleChainId,
|
||||||
null, edge.getId(),
|
null, edge.getId(),
|
||||||
savedRuleChain, ActionType.ASSIGNED_TO_EDGE,
|
savedRuleChain, actionType,
|
||||||
user, ruleChainId.toString(), edge.getId().toString(), edge.getName());
|
user, ruleChainId.toString(), edge.getId().toString(), edge.getName());
|
||||||
return savedRuleChain;
|
return savedRuleChain;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
||||||
null, user, ActionType.ASSIGNED_TO_EDGE, false, e, ruleChainId.toString(), edge.getId().toString());
|
null, user, actionType, false, e, ruleChainId.toString(), edge.getId().toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleChain unassignRuleChainFromEdge(TenantId tenantId, RuleChain ruleChain, Edge edge, SecurityUser user) throws ThingsboardException {
|
public RuleChain setEdgeTemplateRootRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException {
|
||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
EdgeId edgeId = edge.getId();
|
|
||||||
try {
|
try {
|
||||||
RuleChain savedRuleChain = checkNotNull(ruleChainService.unassignRuleChainFromEdge(tenantId, ruleChainId, edgeId, false));
|
ruleChainService.setEdgeTemplateRootRuleChain(tenantId, ruleChainId);
|
||||||
notificationEntityService.notifyAssignOrUnassignEntityToEdge(tenantId, ruleChainId,
|
|
||||||
null, edge.getId(),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, ruleChainId,
|
||||||
savedRuleChain, ActionType.UNASSIGNED_FROM_EDGE,
|
ruleChain, user, ActionType.UPDATED, false, null);
|
||||||
user, ruleChainId.toString(), edge.getId().toString(), edge.getName());
|
return ruleChain;
|
||||||
return savedRuleChain;
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, emptyId(EntityType.RULE_CHAIN),
|
||||||
null, user, ActionType.UNASSIGNED_FROM_EDGE, false, e, ruleChainId.toString(), edge.getId().toString());
|
null, user, ActionType.UPDATED, false, e, ruleChainId.toString());
|
||||||
throw handleException(e);
|
throw handleException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public RuleChain setEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user, boolean isSetEdgeTemplateRootRuleChain) throws ThingsboardException {
|
public RuleChain setAutoAssignToEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException {
|
||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
try {
|
try {
|
||||||
if (isSetEdgeTemplateRootRuleChain) {
|
ruleChainService.setAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
|
||||||
ruleChainService.setEdgeTemplateRootRuleChain(tenantId, ruleChainId);
|
|
||||||
} else {
|
|
||||||
ruleChainService.setAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
|
|
||||||
}
|
|
||||||
|
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, ruleChainId,
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, ruleChainId,
|
||||||
ruleChain, user, ActionType.UPDATED, false, null);
|
ruleChain, user, ActionType.UPDATED, false, null);
|
||||||
return ruleChain;
|
return ruleChain;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
@ -255,7 +248,7 @@ public class DefaultTbRuleChainNotifyService extends AbstractTbEntityService imp
|
|||||||
RuleChainId ruleChainId = ruleChain.getId();
|
RuleChainId ruleChainId = ruleChain.getId();
|
||||||
try {
|
try {
|
||||||
ruleChainService.unsetAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
|
ruleChainService.unsetAutoAssignToEdgeRuleChain(tenantId, ruleChainId);
|
||||||
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, ruleChainId,
|
notificationEntityService.notifyCreateOrUpdateOrDelete(tenantId, null, ruleChainId,
|
||||||
ruleChain, user, ActionType.UPDATED, false, null);
|
ruleChain, user, ActionType.UPDATED, false, null);
|
||||||
return ruleChain;
|
return ruleChain;
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|||||||
@ -15,9 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
package org.thingsboard.server.service.entitiy.ruleChain;
|
package org.thingsboard.server.service.entitiy.ruleChain;
|
||||||
|
|
||||||
|
import org.thingsboard.server.common.data.audit.ActionType;
|
||||||
import org.thingsboard.server.common.data.edge.Edge;
|
import org.thingsboard.server.common.data.edge.Edge;
|
||||||
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
import org.thingsboard.server.common.data.exception.ThingsboardException;
|
||||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
import org.thingsboard.server.common.data.rule.DefaultRuleChainCreateRequest;
|
import org.thingsboard.server.common.data.rule.DefaultRuleChainCreateRequest;
|
||||||
import org.thingsboard.server.common.data.rule.RuleChain;
|
import org.thingsboard.server.common.data.rule.RuleChain;
|
||||||
@ -27,18 +27,19 @@ import org.thingsboard.server.service.security.model.SecurityUser;
|
|||||||
|
|
||||||
public interface TbRuleChainNotifyService extends SimpleTbEntityService<RuleChain> {
|
public interface TbRuleChainNotifyService extends SimpleTbEntityService<RuleChain> {
|
||||||
|
|
||||||
RuleChain saveRuleChain(TenantId tenantId, DefaultRuleChainCreateRequest request, SecurityUser user) throws ThingsboardException;
|
RuleChain saveDefaultByName(TenantId tenantId, DefaultRuleChainCreateRequest request, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChain setRootRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
RuleChain setRootRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, RuleChainMetaData ruleChainMetaData,
|
RuleChainMetaData saveRuleChainMetaData(TenantId tenantId, RuleChain ruleChain, RuleChainMetaData ruleChainMetaData,
|
||||||
boolean updateRelated, SecurityUser user) throws ThingsboardException;
|
boolean updateRelated, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChain assignRuleChainToEdge(TenantId tenantId, RuleChainId ruleChainId, Edge edge, SecurityUser user) throws ThingsboardException;
|
RuleChain assignUnassignRuleChainToEdge(TenantId tenantId, RuleChain ruleChain, Edge edge, ActionType actionType,
|
||||||
|
SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChain unassignRuleChainFromEdge(TenantId tenantId, RuleChain ruleChain, Edge edge, SecurityUser user) throws ThingsboardException;
|
RuleChain setEdgeTemplateRootRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChain setEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user, boolean isSetEdgeTemplateRootRuleChain) throws ThingsboardException;
|
RuleChain setAutoAssignToEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
||||||
|
|
||||||
RuleChain unsetAutoAssignToEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
RuleChain unsetAutoAssignToEdgeRuleChain(TenantId tenantId, RuleChain ruleChain, SecurityUser user) throws ThingsboardException;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user