dashboard edge processor - move setAssignedCustomers to abstact method
This commit is contained in:
		
							parent
							
								
									2a3fa05915
								
							
						
					
					
						commit
						ceda871739
					
				@ -16,7 +16,6 @@
 | 
			
		||||
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
 | 
			
		||||
 | 
			
		||||
import com.datastax.oss.driver.api.core.uuid.Uuids;
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import lombok.extern.slf4j.Slf4j;
 | 
			
		||||
import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
import org.thingsboard.server.common.data.Dashboard;
 | 
			
		||||
@ -44,12 +43,8 @@ public abstract class BaseDashboardProcessor extends BaseEdgeProcessor {
 | 
			
		||||
        dashboard.setTitle(dashboardUpdateMsg.getTitle());
 | 
			
		||||
        dashboard.setImage(dashboardUpdateMsg.hasImage() ? dashboardUpdateMsg.getImage() : null);
 | 
			
		||||
        dashboard.setConfiguration(JacksonUtil.toJsonNode(dashboardUpdateMsg.getConfiguration()));
 | 
			
		||||
        Set<ShortCustomerInfo> assignedCustomers = null;
 | 
			
		||||
        if (dashboardUpdateMsg.hasAssignedCustomers()) {
 | 
			
		||||
            assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() {
 | 
			
		||||
            });
 | 
			
		||||
            dashboard.setAssignedCustomers(assignedCustomers);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Set<ShortCustomerInfo> assignedCustomers = setAssignedCustomers(tenantId, dashboard, dashboardUpdateMsg);
 | 
			
		||||
 | 
			
		||||
        dashboardValidator.validate(dashboard, Dashboard::getTenantId);
 | 
			
		||||
        if (created) {
 | 
			
		||||
@ -68,6 +63,8 @@ public abstract class BaseDashboardProcessor extends BaseEdgeProcessor {
 | 
			
		||||
        return created;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    protected abstract Set<ShortCustomerInfo> setAssignedCustomers(TenantId tenantId, Dashboard dashboard, DashboardUpdateMsg dashboardUpdateMsg);
 | 
			
		||||
 | 
			
		||||
    private void unassignCustomersFromDashboard(TenantId tenantId, Dashboard dashboard) {
 | 
			
		||||
        if (dashboard.getAssignedCustomers() != null && !dashboard.getAssignedCustomers().isEmpty()) {
 | 
			
		||||
            for (ShortCustomerInfo assignedCustomer : dashboard.getAssignedCustomers()) {
 | 
			
		||||
 | 
			
		||||
@ -16,6 +16,7 @@
 | 
			
		||||
package org.thingsboard.server.service.edge.rpc.processor.dashboard;
 | 
			
		||||
 | 
			
		||||
import com.fasterxml.jackson.core.JsonProcessingException;
 | 
			
		||||
import com.fasterxml.jackson.core.type.TypeReference;
 | 
			
		||||
import com.fasterxml.jackson.databind.node.ObjectNode;
 | 
			
		||||
import com.google.common.util.concurrent.Futures;
 | 
			
		||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
			
		||||
@ -25,6 +26,7 @@ import org.thingsboard.common.util.JacksonUtil;
 | 
			
		||||
import org.thingsboard.server.common.data.Dashboard;
 | 
			
		||||
import org.thingsboard.server.common.data.DataConstants;
 | 
			
		||||
import org.thingsboard.server.common.data.EdgeUtils;
 | 
			
		||||
import org.thingsboard.server.common.data.ShortCustomerInfo;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.Edge;
 | 
			
		||||
import org.thingsboard.server.common.data.edge.EdgeEvent;
 | 
			
		||||
import org.thingsboard.server.common.data.id.CustomerId;
 | 
			
		||||
@ -41,6 +43,7 @@ import org.thingsboard.server.queue.TbQueueCallback;
 | 
			
		||||
import org.thingsboard.server.queue.TbQueueMsgMetadata;
 | 
			
		||||
import org.thingsboard.server.queue.util.TbCoreComponent;
 | 
			
		||||
 | 
			
		||||
import java.util.Set;
 | 
			
		||||
import java.util.UUID;
 | 
			
		||||
 | 
			
		||||
@Component
 | 
			
		||||
@ -145,4 +148,14 @@ public class DashboardEdgeProcessor extends BaseDashboardProcessor {
 | 
			
		||||
        }
 | 
			
		||||
        return downlinkMsg;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Override
 | 
			
		||||
    protected Set<ShortCustomerInfo> setAssignedCustomers(TenantId tenantId, Dashboard dashboard, DashboardUpdateMsg dashboardUpdateMsg) {
 | 
			
		||||
        Set<ShortCustomerInfo> assignedCustomers = null;
 | 
			
		||||
        if (dashboardUpdateMsg.hasAssignedCustomers()) {
 | 
			
		||||
            assignedCustomers = JacksonUtil.fromString(dashboardUpdateMsg.getAssignedCustomers(), new TypeReference<>() {});
 | 
			
		||||
            dashboard.setAssignedCustomers(assignedCustomers);
 | 
			
		||||
        }
 | 
			
		||||
        return assignedCustomers;
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -303,21 +303,21 @@ public class DeviceProfileEdgeTest extends AbstractEdgeTest {
 | 
			
		||||
        UplinkResponseMsg latestResponseMsg = edgeImitator.getLatestResponseMsg();
 | 
			
		||||
        Assert.assertTrue(latestResponseMsg.getSuccess());
 | 
			
		||||
 | 
			
		||||
        AssetProfile assetProfile = doGet("/api/deviceProfile/" + uuid, AssetProfile.class);
 | 
			
		||||
        Assert.assertNotNull(assetProfile);
 | 
			
		||||
        Assert.assertEquals("Device Profile On Edge", assetProfile.getName());
 | 
			
		||||
        AssetProfile deviceProfile = doGet("/api/deviceProfile/" + uuid, AssetProfile.class);
 | 
			
		||||
        Assert.assertNotNull(deviceProfile);
 | 
			
		||||
        Assert.assertEquals("Device Profile On Edge", deviceProfile.getName());
 | 
			
		||||
 | 
			
		||||
        // delete profile
 | 
			
		||||
        edgeImitator.expectMessageAmount(1);
 | 
			
		||||
        doDelete("/api/deviceProfile/" + assetProfile.getUuidId())
 | 
			
		||||
        doDelete("/api/deviceProfile/" + deviceProfile.getUuidId())
 | 
			
		||||
                .andExpect(status().isOk());
 | 
			
		||||
        Assert.assertTrue(edgeImitator.waitForMessages());
 | 
			
		||||
        AbstractMessage latestMessage = edgeImitator.getLatestMessage();
 | 
			
		||||
        Assert.assertTrue(latestMessage instanceof DeviceProfileUpdateMsg);
 | 
			
		||||
        DeviceProfileUpdateMsg deviceProfileUpdateMsg = (DeviceProfileUpdateMsg) latestMessage;
 | 
			
		||||
        Assert.assertEquals(UpdateMsgType.ENTITY_DELETED_RPC_MESSAGE, deviceProfileUpdateMsg.getMsgType());
 | 
			
		||||
        Assert.assertEquals(assetProfile.getUuidId().getMostSignificantBits(), deviceProfileUpdateMsg.getIdMSB());
 | 
			
		||||
        Assert.assertEquals(assetProfile.getUuidId().getLeastSignificantBits(), deviceProfileUpdateMsg.getIdLSB());
 | 
			
		||||
        Assert.assertEquals(deviceProfile.getUuidId().getMostSignificantBits(), deviceProfileUpdateMsg.getIdMSB());
 | 
			
		||||
        Assert.assertEquals(deviceProfile.getUuidId().getLeastSignificantBits(), deviceProfileUpdateMsg.getIdLSB());
 | 
			
		||||
 | 
			
		||||
        // cleanup
 | 
			
		||||
        unAssignFromEdgeAndDeleteDashboard(dashboardId);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user