use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseController method createPageLink.
PageLink createPageLink(int pageSize, int page, String textSearch, String sortProperty, String sortOrder) throws ThingsboardException {
if (!StringUtils.isEmpty(sortProperty)) {
SortOrder.Direction direction = SortOrder.Direction.ASC;
if (!StringUtils.isEmpty(sortOrder)) {
try {
direction = SortOrder.Direction.valueOf(sortOrder.toUpperCase());
} catch (IllegalArgumentException e) {
throw new ThingsboardException("Unsupported sort order '" + sortOrder + "'! Only 'ASC' or 'DESC' types are allowed.", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
}
}
SortOrder sort = new SortOrder(sortProperty, direction);
return new PageLink(pageSize, page, textSearch, sort);
} else {
return new PageLink(pageSize, page, textSearch);
}
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class EdgeServiceImpl method findEdgeRuleChains.
private List<RuleChain> findEdgeRuleChains(TenantId tenantId, EdgeId edgeId) {
List<RuleChain> result = new ArrayList<>();
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<RuleChain> pageData;
do {
pageData = ruleChainService.findRuleChainsByTenantIdAndEdgeId(tenantId, edgeId, pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
result.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
return result;
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseEdgeServiceTest method testFindEdgesByTenantIdAndType.
@Test
public void testFindEdgesByTenantIdAndType() {
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(edgeService.saveEdge(edge));
}
String title2 = "Edge title 2";
String type2 = "typeB";
List<Edge> edgesType2 = new ArrayList<>();
for (int i = 0; i < 175; 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(edgeService.saveEdge(edge));
}
List<Edge> loadedEdgesType1 = new ArrayList<>();
PageLink pageLink = new PageLink(15, 0, title1);
PageData<Edge> pageData = null;
do {
pageData = edgeService.findEdgesByTenantIdAndType(tenantId, type1, pageLink);
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, 0, title2);
do {
pageData = edgeService.findEdgesByTenantIdAndType(tenantId, type2, pageLink);
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) {
edgeService.deleteEdge(tenantId, edge.getId());
}
pageLink = new PageLink(4, 0, title1);
pageData = edgeService.findEdgesByTenantIdAndType(tenantId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Edge edge : loadedEdgesType2) {
edgeService.deleteEdge(tenantId, edge.getId());
}
pageLink = new PageLink(4, 0, title2);
pageData = edgeService.findEdgesByTenantIdAndType(tenantId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseEdgeServiceTest method testFindEdgesByTenantId.
@Test
public void testFindEdgesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Edge> edges = new ArrayList<>();
for (int i = 0; i < 178; i++) {
Edge edge = constructEdge(tenantId, "Edge " + i, "default");
edges.add(edgeService.saveEdge(edge));
}
List<Edge> loadedEdges = new ArrayList<>();
PageLink pageLink = new PageLink(23);
PageData<Edge> pageData = null;
do {
pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
loadedEdges.addAll(pageData.getData());
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
} while (pageData.hasNext());
Collections.sort(edges, idComparator);
Collections.sort(loadedEdges, idComparator);
Assert.assertEquals(edges, loadedEdges);
edgeService.deleteEdgesByTenantId(tenantId);
pageLink = new PageLink(33);
pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
}
use of org.thingsboard.server.common.data.page.PageLink in project thingsboard by thingsboard.
the class BaseEdgeServiceTest method testFindEdgesByTenantIdCustomerIdAndType.
@Test
public void testFindEdgesByTenantIdCustomerIdAndType() {
Customer customer = new Customer();
customer.setTitle("Test customer");
customer.setTenantId(tenantId);
customer = customerService.saveCustomer(customer);
CustomerId customerId = customer.getId();
String title1 = "Edge title 1";
String type1 = "typeC";
List<Edge> edgesType1 = new ArrayList<>();
for (int i = 0; i < 175; i++) {
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title1 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
Edge edge = constructEdge(name, type1);
edge = edgeService.saveEdge(edge);
edgesType1.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
}
String title2 = "Edge title 2";
String type2 = "typeD";
List<Edge> edgesType2 = new ArrayList<>();
for (int i = 0; i < 143; i++) {
String suffix = RandomStringUtils.randomAlphanumeric(15);
String name = title2 + suffix;
name = i % 2 == 0 ? name.toLowerCase() : name.toUpperCase();
Edge edge = constructEdge(name, type2);
edge = edgeService.saveEdge(edge);
edgesType2.add(edgeService.assignEdgeToCustomer(tenantId, edge.getId(), customerId));
}
List<Edge> loadedEdgesType1 = new ArrayList<>();
PageLink pageLink = new PageLink(15);
PageData<Edge> pageData = null;
do {
pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
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 = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
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) {
edgeService.deleteEdge(tenantId, edge.getId());
}
pageLink = new PageLink(4);
pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type1, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
for (Edge edge : loadedEdgesType2) {
edgeService.deleteEdge(tenantId, edge.getId());
}
pageLink = new PageLink(4);
pageData = edgeService.findEdgesByTenantIdAndCustomerIdAndType(tenantId, customerId, type2, pageLink);
Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size());
customerService.deleteCustomer(tenantId, customerId);
}
Aggregations