added calculated field service to ctx
This commit is contained in:
parent
de5e438c8c
commit
4dbc35273a
@ -62,6 +62,7 @@ import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.audit.AuditLogService;
|
||||
import org.thingsboard.server.dao.cassandra.CassandraCluster;
|
||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.ClaimDevicesService;
|
||||
@ -389,6 +390,10 @@ public class ActorSystemContext {
|
||||
@Getter
|
||||
private SlackService slackService;
|
||||
|
||||
@Autowired
|
||||
@Getter
|
||||
private CalculatedFieldService calculatedFieldService;
|
||||
|
||||
@Lazy
|
||||
@Autowired(required = false)
|
||||
@Getter
|
||||
|
||||
@ -78,6 +78,7 @@ import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.audit.AuditLogService;
|
||||
import org.thingsboard.server.dao.cassandra.CassandraCluster;
|
||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
@ -848,6 +849,11 @@ class DefaultTbContext implements TbContext {
|
||||
return mainCtx.getSlackService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedFieldService getCalculatedFieldService() {
|
||||
return mainCtx.getCalculatedFieldService();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isExternalNodeForceAck() {
|
||||
return mainCtx.isExternalNodeForceAck();
|
||||
|
||||
@ -18,6 +18,7 @@ package org.thingsboard.server.dao.cf;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedField;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedFieldLink;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.dao.entity.EntityDaoService;
|
||||
@ -34,6 +35,8 @@ public interface CalculatedFieldService extends EntityDaoService {
|
||||
|
||||
CalculatedFieldLink saveCalculatedFieldLink(TenantId tenantId, CalculatedFieldLink calculatedFieldLink);
|
||||
|
||||
CalculatedFieldLink findCalculatedFieldLinkById(TenantId tenantId, CalculatedFieldLinkId calculatedFieldLinkId);
|
||||
|
||||
boolean existsByEntityId(TenantId tenantId, EntityId entityId);
|
||||
|
||||
boolean referencedInAnyCalculatedField(TenantId tenantId, EntityId referencedEntityId);
|
||||
|
||||
@ -25,6 +25,7 @@ import org.thingsboard.server.common.data.cf.CalculatedFieldLink;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.EntityId;
|
||||
@ -114,6 +115,14 @@ public class BaseCalculatedFieldService implements CalculatedFieldService {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedFieldLink findCalculatedFieldLinkById(TenantId tenantId, CalculatedFieldLinkId calculatedFieldLinkId) {
|
||||
log.trace("Executing findCalculatedFieldLinkById, tenantId [{}], calculatedFieldLinkId [{}]", tenantId, calculatedFieldLinkId);
|
||||
validateId(tenantId, id -> INCORRECT_TENANT_ID + id);
|
||||
validateId(calculatedFieldLinkId, id -> "Incorrect calculatedFieldLinkId " + id);
|
||||
return calculatedFieldLinkDao.findById(tenantId, calculatedFieldLinkId.getId());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean existsByEntityId(TenantId tenantId, EntityId entityId) {
|
||||
return calculatedFieldDao.existsByTenantIdAndEntityId(tenantId, entityId);
|
||||
|
||||
@ -50,6 +50,7 @@ import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.attributes.AttributesService;
|
||||
import org.thingsboard.server.dao.audit.AuditLogService;
|
||||
import org.thingsboard.server.dao.cassandra.CassandraCluster;
|
||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceCredentialsService;
|
||||
@ -357,6 +358,8 @@ public interface TbContext {
|
||||
|
||||
SlackService getSlackService();
|
||||
|
||||
CalculatedFieldService getCalculatedFieldService();
|
||||
|
||||
boolean isExternalNodeForceAck();
|
||||
|
||||
/**
|
||||
|
||||
@ -18,10 +18,13 @@ package org.thingsboard.rule.engine.util;
|
||||
import org.thingsboard.rule.engine.api.TbContext;
|
||||
import org.thingsboard.server.common.data.EntityType;
|
||||
import org.thingsboard.server.common.data.HasTenantId;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedFieldLink;
|
||||
import org.thingsboard.server.common.data.id.AlarmId;
|
||||
import org.thingsboard.server.common.data.id.ApiUsageStateId;
|
||||
import org.thingsboard.server.common.data.id.AssetId;
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldId;
|
||||
import org.thingsboard.server.common.data.id.CalculatedFieldLinkId;
|
||||
import org.thingsboard.server.common.data.id.CustomerId;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.DeviceId;
|
||||
@ -157,6 +160,17 @@ public class TenantIdLoader {
|
||||
case MOBILE_APP:
|
||||
tenantEntity = ctx.getMobileAppService().findMobileAppById(ctxTenantId, new MobileAppId(id));
|
||||
break;
|
||||
case CALCULATED_FIELD:
|
||||
tenantEntity = ctx.getCalculatedFieldService().findById(ctxTenantId, new CalculatedFieldId(id));
|
||||
break;
|
||||
case CALCULATED_FIELD_LINK:
|
||||
CalculatedFieldLink calculatedFieldLink = ctx.getCalculatedFieldService().findCalculatedFieldLinkById(ctxTenantId, new CalculatedFieldLinkId(id));
|
||||
if (calculatedFieldLink != null) {
|
||||
tenantEntity = ctx.getCalculatedFieldService().findById(ctxTenantId, calculatedFieldLink.getCalculatedFieldId());
|
||||
} else {
|
||||
tenantEntity = null;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected entity type: " + entityId.getEntityType());
|
||||
}
|
||||
|
||||
@ -43,6 +43,8 @@ import org.thingsboard.server.common.data.User;
|
||||
import org.thingsboard.server.common.data.alarm.Alarm;
|
||||
import org.thingsboard.server.common.data.asset.Asset;
|
||||
import org.thingsboard.server.common.data.asset.AssetProfile;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedField;
|
||||
import org.thingsboard.server.common.data.cf.CalculatedFieldLink;
|
||||
import org.thingsboard.server.common.data.domain.Domain;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
@ -66,6 +68,7 @@ import org.thingsboard.server.common.data.rule.RuleNode;
|
||||
import org.thingsboard.server.common.data.widget.WidgetType;
|
||||
import org.thingsboard.server.common.data.widget.WidgetsBundle;
|
||||
import org.thingsboard.server.dao.asset.AssetService;
|
||||
import org.thingsboard.server.dao.cf.CalculatedFieldService;
|
||||
import org.thingsboard.server.dao.customer.CustomerService;
|
||||
import org.thingsboard.server.dao.dashboard.DashboardService;
|
||||
import org.thingsboard.server.dao.device.DeviceService;
|
||||
@ -151,6 +154,8 @@ public class TenantIdLoaderTest {
|
||||
private DomainService domainService;
|
||||
@Mock
|
||||
private MobileAppService mobileAppService;
|
||||
@Mock
|
||||
private CalculatedFieldService calculatedFieldService;
|
||||
|
||||
private TenantId tenantId;
|
||||
private TenantProfileId tenantProfileId;
|
||||
@ -392,6 +397,18 @@ public class TenantIdLoaderTest {
|
||||
when(ctx.getMobileAppService()).thenReturn(mobileAppService);
|
||||
doReturn(mobileApp).when(mobileAppService).findMobileAppById(eq(tenantId), any());
|
||||
break;
|
||||
case CALCULATED_FIELD:
|
||||
CalculatedField calculatedField = new CalculatedField();
|
||||
calculatedField.setTenantId(tenantId);
|
||||
when(ctx.getCalculatedFieldService()).thenReturn(calculatedFieldService);
|
||||
doReturn(calculatedField).when(calculatedFieldService).findById(eq(tenantId), any());
|
||||
break;
|
||||
case CALCULATED_FIELD_LINK:
|
||||
CalculatedFieldLink calculatedFieldLink = new CalculatedFieldLink();
|
||||
calculatedFieldLink.setTenantId(tenantId);
|
||||
when(ctx.getCalculatedFieldService()).thenReturn(calculatedFieldService);
|
||||
doReturn(calculatedFieldLink).when(calculatedFieldService).findCalculatedFieldLinkById(eq(tenantId), any());
|
||||
break;
|
||||
default:
|
||||
throw new RuntimeException("Unexpected originator EntityType " + entityType);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user