use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class CustomerEdgeProcessor method processCustomerNotification.
public void processCustomerNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) {
EdgeEventActionType actionType = EdgeEventActionType.valueOf(edgeNotificationMsg.getAction());
EdgeEventType type = EdgeEventType.valueOf(edgeNotificationMsg.getType());
UUID uuid = new UUID(edgeNotificationMsg.getEntityIdMSB(), edgeNotificationMsg.getEntityIdLSB());
CustomerId customerId = new CustomerId(EntityIdFactory.getByEdgeEventTypeAndUuid(type, uuid).getId());
switch(actionType) {
case UPDATED:
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<Edge> pageData;
do {
pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
for (Edge edge : pageData.getData()) {
saveEdgeEvent(tenantId, edge.getId(), type, actionType, customerId, null);
}
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
break;
case DELETED:
EdgeId edgeId = new EdgeId(new UUID(edgeNotificationMsg.getEdgeIdMSB(), edgeNotificationMsg.getEdgeIdLSB()));
saveEdgeEvent(tenantId, edgeId, type, actionType, customerId, null);
break;
}
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseEdgeProcessor method processActionForAllEdges.
protected void processActionForAllEdges(TenantId tenantId, EdgeEventType type, EdgeEventActionType actionType, EntityId entityId) {
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<Edge> pageData;
do {
pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
for (Edge edge : pageData.getData()) {
saveEdgeEvent(tenantId, edge.getId(), type, actionType, entityId, null);
}
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseDeviceControllerTest method testAssignDeviceToEdge.
@Test
public void testAssignDeviceToEdge() throws Exception {
Edge edge = constructEdge("My edge", "default");
Edge savedEdge = doPost("/api/edge", edge, Edge.class);
Device device = new Device();
device.setName("My device");
device.setType("default");
Device savedDevice = doPost("/api/device", device, Device.class);
doPost("/api/edge/" + savedEdge.getId().getId().toString() + "/device/" + savedDevice.getId().getId().toString(), Device.class);
PageData<Device> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/devices?", new TypeReference<PageData<Device>>() {
}, new PageLink(100));
Assert.assertEquals(1, pageData.getData().size());
doDelete("/api/edge/" + savedEdge.getId().getId().toString() + "/device/" + savedDevice.getId().getId().toString(), Device.class);
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/devices?", new TypeReference<PageData<Device>>() {
}, new PageLink(100));
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseEdgeControllerTest method testSaveEdgeWithEmptyType.
@Test
public void testSaveEdgeWithEmptyType() throws Exception {
Edge edge = constructEdge("My edge", null);
doPost("/api/edge", edge).andExpect(status().isBadRequest()).andExpect(statusReason(containsString("Edge type should be specified")));
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseEdgeControllerTest method testFindTenantEdgesByType.
@Test
public void testFindTenantEdgesByType() throws Exception {
String title1 = "Edge title 1";
String type1 = "typeA";
List<Edge> edgesType1 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
Edge edge = constructEdge(name, type1);
edgesType1.add(doPost("/api/edge", edge, Edge.class));
}
String title2 = "Edge title 2";
String type2 = "typeB";
List<Edge> edgesType2 = new ArrayList<>();
for (int i = 0; i < 75; i++) {
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
Edge edge = constructEdge(name, type2);
edgesType2.add(doPost("/api/edge", edge, Edge.class));
}
List<Edge> loadedEdgesType1 = new ArrayList<>();
PageLink pageLink = new PageLink(15);
PageData<Edge> pageData = null;
do {
pageData = doGetTypedWithPageLink("/api/tenant/edges?type={type}&", new TypeReference<PageData<Edge>>() {
}, pageLink, type1);
loadedEdgesType1.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(edgesType1, idComparator);
Collections.sort(loadedEdgesType1, idComparator);
Assert.assertEquals(edgesType1, loadedEdgesType1);
List<Edge> loadedEdgesType2 = new ArrayList<>();
pageLink = new PageLink(4);
do {
pageData = doGetTypedWithPageLink("/api/tenant/edges?type={type}&", new TypeReference<PageData<Edge>>() {
}, pageLink, type2);
loadedEdgesType2.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(edgesType2, idComparator);
Collections.sort(loadedEdgesType2, idComparator);
Assert.assertEquals(edgesType2, loadedEdgesType2);
for (Edge edge : loadedEdgesType1) {
doDelete("/api/edge/" + edge.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new PageLink(4);
pageData = doGetTypedWithPageLink("/api/tenant/edges?type={type}&", new TypeReference<PageData<Edge>>() {
}, pageLink, type1);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Edge edge : loadedEdgesType2) {
doDelete("/api/edge/" + edge.getId().getId().toString()).andExpect(status().isOk());
}
pageLink = new PageLink(4);
pageData = doGetTypedWithPageLink("/api/tenant/edges?type={type}&", new TypeReference<PageData<Edge>>() {
}, pageLink, type2);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
Aggregations