use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseEdgeControllerTest method testAssignUnassignEdgeToCustomer.
@Test
public void testAssignUnassignEdgeToCustomer() throws Exception {
Edge edge = constructEdge("My edge", "default");
Edge savedEdge = doPost("/api/edge", edge, Edge.class);
Customer customer = new Customer();
customer.setTitle("My customer");
Customer savedCustomer = doPost("/api/customer", customer, Customer.class);
Edge assignedEdge = doPost("/api/customer/" + savedCustomer.getId().getId().toString() + "/edge/" + savedEdge.getId().getId().toString(), Edge.class);
Assert.assertEquals(savedCustomer.getId(), assignedEdge.getCustomerId());
Edge foundEdge = doGet("/api/edge/" + savedEdge.getId().getId().toString(), Edge.class);
Assert.assertEquals(savedCustomer.getId(), foundEdge.getCustomerId());
Edge unassignedEdge = doDelete("/api/customer/edge/" + savedEdge.getId().getId().toString(), Edge.class);
Assert.assertEquals(ModelConstants.NULL_UUID, unassignedEdge.getCustomerId().getId());
foundEdge = doGet("/api/edge/" + savedEdge.getId().getId().toString(), Edge.class);
Assert.assertEquals(ModelConstants.NULL_UUID, foundEdge.getCustomerId().getId());
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseDashboardControllerTest method testAssignDashboardToEdge.
@Test
public void testAssignDashboardToEdge() throws Exception {
Edge edge = constructEdge("My edge", "default");
Edge savedEdge = doPost("/api/edge", edge, Edge.class);
Dashboard dashboard = new Dashboard();
dashboard.setTitle("My dashboard");
Dashboard savedDashboard = doPost("/api/dashboard", dashboard, Dashboard.class);
doPost("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class);
PageData<Dashboard> pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", new TypeReference<PageData<Dashboard>>() {
}, new PageLink(100));
Assert.assertEquals(1, pageData.getData().size());
doDelete("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboard/" + savedDashboard.getId().getId().toString(), Dashboard.class);
pageData = doGetTypedWithPageLink("/api/edge/" + savedEdge.getId().getId().toString() + "/dashboards?", new TypeReference<PageData<Dashboard>>() {
}, 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 BaseRuleChainService method deleteRuleChainById.
@Override
@Transactional
public void deleteRuleChainById(TenantId tenantId, RuleChainId ruleChainId) {
Validator.validateId(ruleChainId, "Incorrect rule chain id for delete request.");
RuleChain ruleChain = ruleChainDao.findById(tenantId, ruleChainId.getId());
if (ruleChain != null) {
if (ruleChain.isRoot()) {
throw new DataValidationException("Deletion of Root Tenant Rule Chain is prohibited!");
}
if (RuleChainType.EDGE.equals(ruleChain.getType())) {
PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
PageData<Edge> pageData;
do {
pageData = edgeService.findEdgesByTenantIdAndEntityId(tenantId, ruleChainId, pageLink);
if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
for (Edge edge : pageData.getData()) {
if (edge.getRootRuleChainId() != null && edge.getRootRuleChainId().equals(ruleChainId)) {
throw new DataValidationException("Can't delete rule chain that is root for edge [" + edge.getName() + "]. Please assign another root rule chain first to the edge!");
}
}
if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink();
}
}
} while (pageData != null && pageData.hasNext());
}
}
checkRuleNodesAndDelete(tenantId, ruleChainId);
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class BaseRuleChainService method assignRuleChainToEdge.
@Override
public RuleChain assignRuleChainToEdge(TenantId tenantId, RuleChainId ruleChainId, EdgeId edgeId) {
RuleChain ruleChain = findRuleChainById(tenantId, ruleChainId);
Edge edge = edgeService.findEdgeById(tenantId, edgeId);
if (edge == null) {
throw new DataValidationException("Can't assign ruleChain to non-existent edge!");
}
if (!edge.getTenantId().equals(ruleChain.getTenantId())) {
throw new DataValidationException("Can't assign ruleChain to edge from different tenant!");
}
if (!RuleChainType.EDGE.equals(ruleChain.getType())) {
throw new DataValidationException("Can't assign non EDGE ruleChain to edge!");
}
try {
createRelation(tenantId, new EntityRelation(edgeId, ruleChainId, EntityRelation.CONTAINS_TYPE, RelationTypeGroup.EDGE));
} catch (Exception e) {
log.warn("[{}] Failed to create ruleChain relation. Edge Id: [{}]", ruleChainId, edgeId);
throw new RuntimeException(e);
}
return ruleChain;
}
use of org.thingsboard.server.common.data.edge.Edge in project thingsboard by thingsboard.
the class EdgeController method getEdgesByIds.
@ApiOperation(value = "Get Edges By Ids (getEdgesByIds)", notes = "Requested edges must be owned by tenant or assigned to customer which user is performing the request." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/edges", params = { "edgeIds" }, method = RequestMethod.GET)
@ResponseBody
public List<Edge> getEdgesByIds(@ApiParam(value = "A list of edges ids, separated by comma ','", required = true) @RequestParam("edgeIds") String[] strEdgeIds) throws ThingsboardException {
checkArrayParameter("edgeIds", strEdgeIds);
try {
SecurityUser user = getCurrentUser();
TenantId tenantId = user.getTenantId();
CustomerId customerId = user.getCustomerId();
List<EdgeId> edgeIds = new ArrayList<>();
for (String strEdgeId : strEdgeIds) {
edgeIds.add(new EdgeId(toUUID(strEdgeId)));
}
ListenableFuture<List<Edge>> edgesFuture;
if (customerId == null || customerId.isNullUid()) {
edgesFuture = edgeService.findEdgesByTenantIdAndIdsAsync(tenantId, edgeIds);
} else {
edgesFuture = edgeService.findEdgesByTenantIdCustomerIdAndIdsAsync(tenantId, customerId, edgeIds);
}
List<Edge> edges = edgesFuture.get();
return checkNotNull(edges);
} catch (Exception e) {
throw handleException(e);
}
}
Aggregations