Search in sources :

Example 36 with EdgeId

use of org.thingsboard.server.common.data.id.EdgeId in project thingsboard by thingsboard.

the class DeviceEdgeProcessor method isDeviceAlreadyExistsOnCloudForThisEdge.

private boolean isDeviceAlreadyExistsOnCloudForThisEdge(TenantId tenantId, Edge edge, Device device) {
    PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
    PageData<EdgeId> pageData;
    do {
        pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, device.getId(), pageLink);
        if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
            if (pageData.getData().contains(edge.getId())) {
                return true;
            }
            if (pageData.hasNext()) {
                pageLink = pageLink.nextPageLink();
            }
        }
    } while (pageData != null && pageData.hasNext());
    return false;
}
Also used : EdgeId(org.thingsboard.server.common.data.id.EdgeId) PageLink(org.thingsboard.server.common.data.page.PageLink)

Example 37 with EdgeId

use of org.thingsboard.server.common.data.id.EdgeId in project thingsboard by thingsboard.

the class RelationEdgeProcessor method findRelatedEdgeIds.

private List<EdgeId> findRelatedEdgeIds(TenantId tenantId, EntityId entityId) {
    List<EdgeId> result = new ArrayList<>();
    PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
    PageData<EdgeId> pageData;
    do {
        pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, entityId, 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;
}
Also used : EdgeId(org.thingsboard.server.common.data.id.EdgeId) ArrayList(java.util.ArrayList) PageLink(org.thingsboard.server.common.data.page.PageLink)

Example 38 with EdgeId

use of org.thingsboard.server.common.data.id.EdgeId in project thingsboard by thingsboard.

the class RelationEdgeProcessor method processRelationNotification.

public void processRelationNotification(TenantId tenantId, TransportProtos.EdgeNotificationMsgProto edgeNotificationMsg) throws JsonProcessingException {
    EntityRelation relation = mapper.readValue(edgeNotificationMsg.getBody(), EntityRelation.class);
    if (!relation.getFrom().getEntityType().equals(EntityType.EDGE) && !relation.getTo().getEntityType().equals(EntityType.EDGE)) {
        Set<EdgeId> uniqueEdgeIds = new HashSet<>();
        uniqueEdgeIds.addAll(findRelatedEdgeIds(tenantId, relation.getTo()));
        uniqueEdgeIds.addAll(findRelatedEdgeIds(tenantId, relation.getFrom()));
        if (!uniqueEdgeIds.isEmpty()) {
            for (EdgeId edgeId : uniqueEdgeIds) {
                saveEdgeEvent(tenantId, edgeId, EdgeEventType.RELATION, EdgeEventActionType.valueOf(edgeNotificationMsg.getAction()), null, mapper.valueToTree(relation));
            }
        }
    }
}
Also used : EntityRelation(org.thingsboard.server.common.data.relation.EntityRelation) EdgeId(org.thingsboard.server.common.data.id.EdgeId) HashSet(java.util.HashSet)

Example 39 with EdgeId

use of org.thingsboard.server.common.data.id.EdgeId in project thingsboard by thingsboard.

the class EntityEdgeProcessor method pushNotificationToAllRelatedEdges.

private void pushNotificationToAllRelatedEdges(TenantId tenantId, EntityId entityId, EdgeEventType type, EdgeEventActionType actionType) {
    PageLink pageLink = new PageLink(DEFAULT_PAGE_SIZE);
    PageData<EdgeId> pageData;
    do {
        pageData = edgeService.findRelatedEdgeIdsByEntityId(tenantId, entityId, pageLink);
        if (pageData != null && pageData.getData() != null && !pageData.getData().isEmpty()) {
            for (EdgeId relatedEdgeId : pageData.getData()) {
                saveEdgeEvent(tenantId, relatedEdgeId, type, actionType, entityId, null);
            }
            if (pageData.hasNext()) {
                pageLink = pageLink.nextPageLink();
            }
        }
    } while (pageData != null && pageData.hasNext());
}
Also used : EdgeId(org.thingsboard.server.common.data.id.EdgeId) PageLink(org.thingsboard.server.common.data.page.PageLink)

Example 40 with EdgeId

use of org.thingsboard.server.common.data.id.EdgeId in project thingsboard by thingsboard.

the class DeviceController method deleteDevice.

@ApiOperation(value = "Delete device (deleteDevice)", notes = "Deletes the device, it's credentials and all the relations (from and to the device). Referencing non-existing device Id will cause an error." + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/device/{deviceId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deleteDevice(@ApiParam(value = DEVICE_ID_PARAM_DESCRIPTION) @PathVariable(DEVICE_ID) String strDeviceId) throws ThingsboardException {
    checkParameter(DEVICE_ID, strDeviceId);
    try {
        DeviceId deviceId = new DeviceId(toUUID(strDeviceId));
        Device device = checkDeviceId(deviceId, Operation.DELETE);
        List<EdgeId> relatedEdgeIds = findRelatedEdgeIds(getTenantId(), deviceId);
        deviceService.deleteDevice(getCurrentUser().getTenantId(), deviceId);
        gatewayNotificationsService.onDeviceDeleted(device);
        tbClusterService.onDeviceDeleted(device, null);
        logEntityAction(deviceId, device, device.getCustomerId(), ActionType.DELETED, null, strDeviceId);
        sendDeleteNotificationMsg(getTenantId(), deviceId, relatedEdgeIds);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.DEVICE), null, null, ActionType.DELETED, e, strDeviceId);
        throw handleException(e);
    }
}
Also used : DeviceId(org.thingsboard.server.common.data.id.DeviceId) Device(org.thingsboard.server.common.data.Device) EdgeId(org.thingsboard.server.common.data.id.EdgeId) IOException(java.io.IOException) IncorrectParameterException(org.thingsboard.server.dao.exception.IncorrectParameterException) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ResponseStatus(org.springframework.web.bind.annotation.ResponseStatus) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

EdgeId (org.thingsboard.server.common.data.id.EdgeId)57 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)33 ApiOperation (io.swagger.annotations.ApiOperation)32 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)32 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)32 Edge (org.thingsboard.server.common.data.edge.Edge)29 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)23 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)22 CustomerId (org.thingsboard.server.common.data.id.CustomerId)14 PageLink (org.thingsboard.server.common.data.page.PageLink)14 IOException (java.io.IOException)13 TenantId (org.thingsboard.server.common.data.id.TenantId)13 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)12 DeviceId (org.thingsboard.server.common.data.id.DeviceId)10 ArrayList (java.util.ArrayList)9 Customer (org.thingsboard.server.common.data.Customer)9 EdgeEventActionType (org.thingsboard.server.common.data.edge.EdgeEventActionType)9 List (java.util.List)8 UUID (java.util.UUID)7 Device (org.thingsboard.server.common.data.Device)7