DashboardEdgeProcessor - refactoring to remove duplicates
This commit is contained in:
parent
ceda871739
commit
6566bbc824
@ -16,6 +16,7 @@
|
|||||||
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
|
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
|
||||||
|
|
||||||
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
import com.datastax.oss.driver.api.core.uuid.Uuids;
|
||||||
|
import com.fasterxml.jackson.core.type.TypeReference;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.thingsboard.common.util.JacksonUtil;
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.common.data.Dashboard;
|
import org.thingsboard.server.common.data.Dashboard;
|
||||||
@ -44,7 +45,12 @@ public abstract class BaseDashboardProcessor extends BaseEdgeProcessor {
|
|||||||
dashboard.setImage(dashboardUpdateMsg.hasImage() ? dashboardUpdateMsg.getImage() : null);
|
dashboard.setImage(dashboardUpdateMsg.hasImage() ? dashboardUpdateMsg.getImage() : null);
|
||||||
dashboard.setConfiguration(JacksonUtil.toJsonNode(dashboardUpdateMsg.getConfiguration()));
|
dashboard.setConfiguration(JacksonUtil.toJsonNode(dashboardUpdateMsg.getConfiguration()));
|
||||||
|
|
||||||
Set<ShortCustomerInfo> assignedCustomers = setAssignedCustomers(tenantId, dashboard, dashboardUpdateMsg);
|
Set<ShortCustomerInfo> assignedCustomers = null;
|
||||||
|
if (dashboardUpdateMsg.hasAssignedCustomers()) {
|
||||||
|
assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() {});
|
||||||
|
assignedCustomers = filterNonExistingCustomers(tenantId, assignedCustomers);
|
||||||
|
dashboard.setAssignedCustomers(assignedCustomers);
|
||||||
|
}
|
||||||
|
|
||||||
dashboardValidator.validate(dashboard, Dashboard::getTenantId);
|
dashboardValidator.validate(dashboard, Dashboard::getTenantId);
|
||||||
if (created) {
|
if (created) {
|
||||||
@ -63,7 +69,7 @@ public abstract class BaseDashboardProcessor extends BaseEdgeProcessor {
|
|||||||
return created;
|
return created;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract Set<ShortCustomerInfo> setAssignedCustomers(TenantId tenantId, Dashboard dashboard, DashboardUpdateMsg dashboardUpdateMsg);
|
protected abstract Set<ShortCustomerInfo> filterNonExistingCustomers(TenantId tenantId, Set<ShortCustomerInfo> assignedCustomers);
|
||||||
|
|
||||||
private void unassignCustomersFromDashboard(TenantId tenantId, Dashboard dashboard) {
|
private void unassignCustomersFromDashboard(TenantId tenantId, Dashboard dashboard) {
|
||||||
if (dashboard.getAssignedCustomers() != null && !dashboard.getAssignedCustomers().isEmpty()) {
|
if (dashboard.getAssignedCustomers() != null && !dashboard.getAssignedCustomers().isEmpty()) {
|
||||||
|
|||||||
@ -16,7 +16,6 @@
|
|||||||
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
|
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
import com.fasterxml.jackson.core.type.TypeReference;
|
|
||||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
import com.google.common.util.concurrent.Futures;
|
import com.google.common.util.concurrent.Futures;
|
||||||
import com.google.common.util.concurrent.ListenableFuture;
|
import com.google.common.util.concurrent.ListenableFuture;
|
||||||
@ -150,12 +149,8 @@ public class DashboardEdgeProcessor extends BaseDashboardProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Set<ShortCustomerInfo> setAssignedCustomers(TenantId tenantId, Dashboard dashboard, DashboardUpdateMsg dashboardUpdateMsg) {
|
protected Set<ShortCustomerInfo> filterNonExistingCustomers(TenantId tenantId, Set<ShortCustomerInfo> assignedCustomers) {
|
||||||
Set<ShortCustomerInfo> assignedCustomers = null;
|
// do nothing on cloud
|
||||||
if (dashboardUpdateMsg.hasAssignedCustomers()) {
|
|
||||||
assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() {});
|
|
||||||
dashboard.setAssignedCustomers(assignedCustomers);
|
|
||||||
}
|
|
||||||
return assignedCustomers;
|
return assignedCustomers;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user