edge profile processors - set default rule chains and dashboards moved to subclasses
This commit is contained in:
parent
439d3e131a
commit
c6bba789a4
@ -28,6 +28,8 @@ import org.thingsboard.server.common.data.asset.AssetProfile;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEvent;
|
||||
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.msg.TbMsgType;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
@ -129,4 +131,21 @@ public class AssetProfileEdgeProcessor extends BaseAssetProfileProcessor {
|
||||
}
|
||||
return downlinkMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultRuleChainId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg) {
|
||||
// do nothing on cloud
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultEdgeRuleChainId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg) {
|
||||
UUID defaultEdgeRuleChainUUID = safeGetUUID(assetProfileUpdateMsg.getDefaultRuleChainIdMSB(), assetProfileUpdateMsg.getDefaultRuleChainIdLSB());
|
||||
assetProfile.setDefaultEdgeRuleChainId(defaultEdgeRuleChainUUID != null ? new RuleChainId(defaultEdgeRuleChainUUID) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultDashboardId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg) {
|
||||
UUID defaultDashboardUUID = safeGetUUID(assetProfileUpdateMsg.getDefaultDashboardIdMSB(), assetProfileUpdateMsg.getDefaultDashboardIdLSB());
|
||||
assetProfile.setDefaultDashboardId(defaultDashboardUUID != null ? new DashboardId(defaultDashboardUUID) : null);
|
||||
}
|
||||
}
|
||||
|
||||
@ -29,7 +29,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class BaseAssetProfileProcessor extends BaseEdgeProcessor {
|
||||
public abstract class BaseAssetProfileProcessor extends BaseEdgeProcessor {
|
||||
|
||||
protected boolean saveOrUpdateAssetProfile(TenantId tenantId, AssetProfileId assetProfileId, AssetProfileUpdateMsg assetProfileUpdateMsg) {
|
||||
boolean created = false;
|
||||
@ -50,11 +50,9 @@ public class BaseAssetProfileProcessor extends BaseEdgeProcessor {
|
||||
assetProfile.setImage(assetProfileUpdateMsg.hasImage()
|
||||
? new String(assetProfileUpdateMsg.getImage().toByteArray(), StandardCharsets.UTF_8) : null);
|
||||
|
||||
UUID defaultRuleChainUUID = safeGetUUID(assetProfileUpdateMsg.getDefaultRuleChainIdMSB(), assetProfileUpdateMsg.getDefaultRuleChainIdLSB());
|
||||
assetProfile.setDefaultRuleChainId(defaultRuleChainUUID != null ? new RuleChainId(defaultRuleChainUUID) : null);
|
||||
|
||||
UUID defaultDashboardUUID = safeGetUUID(assetProfileUpdateMsg.getDefaultDashboardIdMSB(), assetProfileUpdateMsg.getDefaultDashboardIdLSB());
|
||||
assetProfile.setDefaultDashboardId(defaultDashboardUUID != null ? new DashboardId(defaultDashboardUUID) : null);
|
||||
setDefaultRuleChainId(assetProfile, assetProfileUpdateMsg);
|
||||
setDefaultEdgeRuleChainId(assetProfile, assetProfileUpdateMsg);
|
||||
setDefaultDashboardId(assetProfile, assetProfileUpdateMsg);
|
||||
|
||||
assetProfileValidator.validate(assetProfile, AssetProfile::getTenantId);
|
||||
if (created) {
|
||||
@ -66,4 +64,10 @@ public class BaseAssetProfileProcessor extends BaseEdgeProcessor {
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
protected abstract void setDefaultRuleChainId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg);
|
||||
|
||||
protected abstract void setDefaultEdgeRuleChainId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg);
|
||||
|
||||
protected abstract void setDefaultDashboardId(AssetProfile assetProfile, AssetProfileUpdateMsg assetProfileUpdateMsg);
|
||||
}
|
||||
|
||||
@ -24,10 +24,8 @@ import org.thingsboard.server.common.data.DeviceProfileType;
|
||||
import org.thingsboard.server.common.data.DeviceTransportType;
|
||||
import org.thingsboard.server.common.data.StringUtils;
|
||||
import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.OtaPackageId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.gen.edge.v1.DeviceProfileUpdateMsg;
|
||||
import org.thingsboard.server.queue.util.DataDecodingEncodingService;
|
||||
@ -38,7 +36,7 @@ import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
public class BaseDeviceProfileProcessor extends BaseEdgeProcessor {
|
||||
public abstract class BaseDeviceProfileProcessor extends BaseEdgeProcessor {
|
||||
|
||||
@Autowired
|
||||
private DataDecodingEncodingService dataDecodingEncodingService;
|
||||
@ -72,11 +70,9 @@ public class BaseDeviceProfileProcessor extends BaseEdgeProcessor {
|
||||
dataDecodingEncodingService.decode(deviceProfileUpdateMsg.getProfileDataBytes().toByteArray());
|
||||
deviceProfile.setProfileData(profileDataOpt.orElse(null));
|
||||
|
||||
UUID defaultRuleChainUUID = safeGetUUID(deviceProfileUpdateMsg.getDefaultRuleChainIdMSB(), deviceProfileUpdateMsg.getDefaultRuleChainIdLSB());
|
||||
deviceProfile.setDefaultRuleChainId(defaultRuleChainUUID != null ? new RuleChainId(defaultRuleChainUUID) : null);
|
||||
|
||||
UUID defaultDashboardUUID = safeGetUUID(deviceProfileUpdateMsg.getDefaultDashboardIdMSB(), deviceProfileUpdateMsg.getDefaultDashboardIdLSB());
|
||||
deviceProfile.setDefaultDashboardId(defaultDashboardUUID != null ? new DashboardId(defaultDashboardUUID) : null);
|
||||
setDefaultRuleChainId(deviceProfile, deviceProfileUpdateMsg);
|
||||
setDefaultEdgeRuleChainId(deviceProfile, deviceProfileUpdateMsg);
|
||||
setDefaultDashboardId(deviceProfile, deviceProfileUpdateMsg);
|
||||
|
||||
String defaultQueueName = StringUtils.isNotBlank(deviceProfileUpdateMsg.getDefaultQueueName())
|
||||
? deviceProfileUpdateMsg.getDefaultQueueName() : null;
|
||||
@ -88,7 +84,6 @@ public class BaseDeviceProfileProcessor extends BaseEdgeProcessor {
|
||||
UUID softwareUUID = safeGetUUID(deviceProfileUpdateMsg.getSoftwareIdMSB(), deviceProfileUpdateMsg.getSoftwareIdLSB());
|
||||
deviceProfile.setSoftwareId(softwareUUID != null ? new OtaPackageId(softwareUUID) : null);
|
||||
|
||||
|
||||
deviceProfileValidator.validate(deviceProfile, DeviceProfile::getTenantId);
|
||||
if (created) {
|
||||
deviceProfile.setId(deviceProfileId);
|
||||
@ -99,4 +94,10 @@ public class BaseDeviceProfileProcessor extends BaseEdgeProcessor {
|
||||
}
|
||||
return created;
|
||||
}
|
||||
|
||||
protected abstract void setDefaultRuleChainId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg);
|
||||
|
||||
protected abstract void setDefaultEdgeRuleChainId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg);
|
||||
|
||||
protected abstract void setDefaultDashboardId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg);
|
||||
}
|
||||
|
||||
@ -27,7 +27,9 @@ import org.thingsboard.server.common.data.DeviceProfile;
|
||||
import org.thingsboard.server.common.data.EdgeUtils;
|
||||
import org.thingsboard.server.common.data.edge.Edge;
|
||||
import org.thingsboard.server.common.data.edge.EdgeEvent;
|
||||
import org.thingsboard.server.common.data.id.DashboardId;
|
||||
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||
import org.thingsboard.server.common.data.id.RuleChainId;
|
||||
import org.thingsboard.server.common.data.id.TenantId;
|
||||
import org.thingsboard.server.common.data.msg.TbMsgType;
|
||||
import org.thingsboard.server.common.msg.TbMsg;
|
||||
@ -130,4 +132,21 @@ public class DeviceProfileEdgeProcessor extends BaseDeviceProfileProcessor {
|
||||
}
|
||||
return downlinkMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultRuleChainId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg) {
|
||||
// do nothing on cloud
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultEdgeRuleChainId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg) {
|
||||
UUID defaultEdgeRuleChainUUID = safeGetUUID(deviceProfileUpdateMsg.getDefaultRuleChainIdMSB(), deviceProfileUpdateMsg.getDefaultRuleChainIdLSB());
|
||||
deviceProfile.setDefaultEdgeRuleChainId(defaultEdgeRuleChainUUID != null ? new RuleChainId(defaultEdgeRuleChainUUID) : null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setDefaultDashboardId(DeviceProfile deviceProfile, DeviceProfileUpdateMsg deviceProfileUpdateMsg) {
|
||||
UUID defaultDashboardUUID = safeGetUUID(deviceProfileUpdateMsg.getDefaultDashboardIdMSB(), deviceProfileUpdateMsg.getDefaultDashboardIdLSB());
|
||||
deviceProfile.setDefaultDashboardId(defaultDashboardUUID != null ? new DashboardId(defaultDashboardUUID) : null);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user