Search in sources :

Example 11 with RuleChainId

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

the class RuleChainController method getRuleChainMetaData.

@ApiOperation(value = "Get Rule Chain (getRuleChainById)", notes = "Fetch the Rule Chain Metadata object based on the provided Rule Chain Id. " + RULE_CHAIN_METADATA_DESCRIPTION + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAnyAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/ruleChain/{ruleChainId}/metadata", method = RequestMethod.GET)
@ResponseBody
public RuleChainMetaData getRuleChainMetaData(@ApiParam(value = RULE_CHAIN_ID_PARAM_DESCRIPTION) @PathVariable(RULE_CHAIN_ID) String strRuleChainId) throws ThingsboardException {
    checkParameter(RULE_CHAIN_ID, strRuleChainId);
    try {
        RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
        checkRuleChain(ruleChainId, Operation.READ);
        return ruleChainService.loadRuleChainMetaData(getTenantId(), ruleChainId);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 12 with RuleChainId

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

the class RuleChainController method unsetAutoAssignToEdgeRuleChain.

@ApiOperation(value = "Unset Auto Assign To Edge Rule Chain (unsetAutoAssignToEdgeRuleChain)", notes = "Removes the rule chain from the list of rule chains that are going to be automatically assigned for any new edge that will be created. " + "Does not unassign this rule chain for already assigned edges. " + TENANT_AUTHORITY_PARAGRAPH)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/ruleChain/{ruleChainId}/autoAssignToEdge", method = RequestMethod.DELETE)
@ResponseBody
public RuleChain unsetAutoAssignToEdgeRuleChain(@ApiParam(value = RULE_CHAIN_ID_PARAM_DESCRIPTION) @PathVariable(RULE_CHAIN_ID) String strRuleChainId) throws ThingsboardException {
    checkParameter(RULE_CHAIN_ID, strRuleChainId);
    try {
        RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
        RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.WRITE);
        ruleChainService.unsetAutoAssignToEdgeRuleChain(getTenantId(), ruleChainId);
        return ruleChain;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.RULE_CHAIN), null, null, ActionType.UPDATED, e, strRuleChainId);
        throw handleException(e);
    }
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 13 with RuleChainId

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

the class RuleChainController method unassignRuleChainFromEdge.

@ApiOperation(value = "Unassign rule chain from edge (unassignRuleChainFromEdge)", notes = "Clears assignment of the rule chain to the edge. " + EDGE_UNASSIGN_ASYNC_FIRST_STEP_DESCRIPTION + "Second, remote edge service will receive an 'unassign' command to remove rule chain " + EDGE_UNASSIGN_RECEIVE_STEP_DESCRIPTION + "Third, once 'unassign' command will be delivered to edge service, it's going to remove rule chain locally." + TENANT_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/edge/{edgeId}/ruleChain/{ruleChainId}", method = RequestMethod.DELETE)
@ResponseBody
public RuleChain unassignRuleChainFromEdge(@PathVariable("edgeId") String strEdgeId, @PathVariable(RULE_CHAIN_ID) String strRuleChainId) throws ThingsboardException {
    checkParameter("edgeId", strEdgeId);
    checkParameter(RULE_CHAIN_ID, strRuleChainId);
    try {
        EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
        Edge edge = checkEdgeId(edgeId, Operation.WRITE);
        RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
        RuleChain ruleChain = checkRuleChain(ruleChainId, Operation.READ);
        RuleChain savedRuleChain = checkNotNull(ruleChainService.unassignRuleChainFromEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId, false));
        logEntityAction(ruleChainId, ruleChain, null, ActionType.UNASSIGNED_FROM_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
        sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.UNASSIGNED_FROM_EDGE);
        return savedRuleChain;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.RULE_CHAIN), null, null, ActionType.UNASSIGNED_FROM_EDGE, e, strRuleChainId, strEdgeId);
        throw handleException(e);
    }
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) EdgeId(org.thingsboard.server.common.data.id.EdgeId) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) Edge(org.thingsboard.server.common.data.edge.Edge) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 14 with RuleChainId

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

the class RuleChainController method assignRuleChainToEdge.

@ApiOperation(value = "Assign rule chain to edge (assignRuleChainToEdge)", notes = "Creates assignment of an existing rule chain to an instance of The Edge. " + EDGE_ASSIGN_ASYNC_FIRST_STEP_DESCRIPTION + "Second, remote edge service will receive a copy of assignment rule chain " + EDGE_ASSIGN_RECEIVE_STEP_DESCRIPTION + "Third, once rule chain will be delivered to edge service, it's going to start processing messages locally. " + "\n\nOnly rule chain with type 'EDGE' can be assigned to edge." + TENANT_AUTHORITY_PARAGRAPH, produces = MediaType.APPLICATION_JSON_VALUE)
@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/edge/{edgeId}/ruleChain/{ruleChainId}", method = RequestMethod.POST)
@ResponseBody
public RuleChain assignRuleChainToEdge(@PathVariable("edgeId") String strEdgeId, @PathVariable(RULE_CHAIN_ID) String strRuleChainId) throws ThingsboardException {
    checkParameter("edgeId", strEdgeId);
    checkParameter(RULE_CHAIN_ID, strRuleChainId);
    try {
        EdgeId edgeId = new EdgeId(toUUID(strEdgeId));
        Edge edge = checkEdgeId(edgeId, Operation.WRITE);
        RuleChainId ruleChainId = new RuleChainId(toUUID(strRuleChainId));
        checkRuleChain(ruleChainId, Operation.READ);
        RuleChain savedRuleChain = checkNotNull(ruleChainService.assignRuleChainToEdge(getCurrentUser().getTenantId(), ruleChainId, edgeId));
        logEntityAction(ruleChainId, savedRuleChain, null, ActionType.ASSIGNED_TO_EDGE, null, strRuleChainId, strEdgeId, edge.getName());
        sendEntityAssignToEdgeNotificationMsg(getTenantId(), edgeId, savedRuleChain.getId(), EdgeEventActionType.ASSIGNED_TO_EDGE);
        return savedRuleChain;
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.RULE_CHAIN), null, null, ActionType.ASSIGNED_TO_EDGE, e, strRuleChainId, strEdgeId);
        throw handleException(e);
    }
}
Also used : RuleChain(org.thingsboard.server.common.data.rule.RuleChain) EdgeId(org.thingsboard.server.common.data.id.EdgeId) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) Edge(org.thingsboard.server.common.data.edge.Edge) ThingsboardException(org.thingsboard.server.common.data.exception.ThingsboardException) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 15 with RuleChainId

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

the class EdgeServiceImpl method findMissingToRelatedRuleChains.

@Override
public String findMissingToRelatedRuleChains(TenantId tenantId, EdgeId edgeId) {
    List<RuleChain> edgeRuleChains = findEdgeRuleChains(tenantId, edgeId);
    List<RuleChainId> edgeRuleChainIds = edgeRuleChains.stream().map(IdBased::getId).collect(Collectors.toList());
    ObjectNode result = mapper.createObjectNode();
    for (RuleChain edgeRuleChain : edgeRuleChains) {
        List<RuleChainConnectionInfo> connectionInfos = ruleChainService.loadRuleChainMetaData(edgeRuleChain.getTenantId(), edgeRuleChain.getId()).getRuleChainConnections();
        if (connectionInfos != null && !connectionInfos.isEmpty()) {
            List<RuleChainId> connectedRuleChains = connectionInfos.stream().map(RuleChainConnectionInfo::getTargetRuleChainId).collect(Collectors.toList());
            List<String> missingRuleChains = new ArrayList<>();
            for (RuleChainId connectedRuleChain : connectedRuleChains) {
                if (!edgeRuleChainIds.contains(connectedRuleChain)) {
                    RuleChain ruleChainById = ruleChainService.findRuleChainById(tenantId, connectedRuleChain);
                    missingRuleChains.add(ruleChainById.getName());
                }
            }
            if (!missingRuleChains.isEmpty()) {
                ArrayNode array = mapper.createArrayNode();
                for (String missingRuleChain : missingRuleChains) {
                    array.add(missingRuleChain);
                }
                result.set(edgeRuleChain.getName(), array);
            }
        }
    }
    return result.toString();
}
Also used : ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) RuleChain(org.thingsboard.server.common.data.rule.RuleChain) ArrayList(java.util.ArrayList) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) Validator.validateString(org.thingsboard.server.dao.service.Validator.validateString) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) RuleChainConnectionInfo(org.thingsboard.server.common.data.rule.RuleChainConnectionInfo)

Aggregations

RuleChainId (org.thingsboard.server.common.data.id.RuleChainId)60 RuleChain (org.thingsboard.server.common.data.rule.RuleChain)22 RuleNodeId (org.thingsboard.server.common.data.id.RuleNodeId)20 Test (org.junit.Test)17 TbMsg (org.thingsboard.server.common.msg.TbMsg)16 ThingsboardException (org.thingsboard.server.common.data.exception.ThingsboardException)12 EntityId (org.thingsboard.server.common.data.id.EntityId)12 ApiOperation (io.swagger.annotations.ApiOperation)11 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)11 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)11 TenantId (org.thingsboard.server.common.data.id.TenantId)11 TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)11 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)10 DeviceId (org.thingsboard.server.common.data.id.DeviceId)9 RuleNode (org.thingsboard.server.common.data.rule.RuleNode)8 Futures (com.google.common.util.concurrent.Futures)7 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)7 IOException (java.io.IOException)7 Uuids (com.datastax.oss.driver.api.core.uuid.Uuids)6 JsonNode (com.fasterxml.jackson.databind.JsonNode)6