Search in sources :

Example 61 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class EntityRelationController method deleteRelation.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relation", method = RequestMethod.DELETE, params = { FROM_ID, FROM_TYPE, RELATION_TYPE, TO_ID, TO_TYPE })
@ResponseStatus(value = HttpStatus.OK)
public void deleteRelation(@RequestParam(FROM_ID) String strFromId, @RequestParam(FROM_TYPE) String strFromType, @RequestParam(RELATION_TYPE) String strRelationType, @RequestParam(value = "relationTypeGroup", required = false) String strRelationTypeGroup, @RequestParam(TO_ID) String strToId, @RequestParam(TO_TYPE) String strToType) throws ThingsboardException {
    checkParameter(FROM_ID, strFromId);
    checkParameter(FROM_TYPE, strFromType);
    checkParameter(RELATION_TYPE, strRelationType);
    checkParameter(TO_ID, strToId);
    checkParameter(TO_TYPE, strToType);
    EntityId fromId = EntityIdFactory.getByTypeAndId(strFromType, strFromId);
    EntityId toId = EntityIdFactory.getByTypeAndId(strToType, strToId);
    checkEntityId(fromId);
    checkEntityId(toId);
    RelationTypeGroup relationTypeGroup = parseRelationTypeGroup(strRelationTypeGroup, RelationTypeGroup.COMMON);
    try {
        Boolean found = relationService.deleteRelation(fromId, toId, strRelationType, relationTypeGroup);
        if (!found) {
            throw new ThingsboardException("Requested item wasn't found!", ThingsboardErrorCode.ITEM_NOT_FOUND);
        }
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) RelationTypeGroup(org.thingsboard.server.common.data.relation.RelationTypeGroup) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 62 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class EntityRelationController method deleteRelations.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN','TENANT_ADMIN', 'CUSTOMER_USER')")
@RequestMapping(value = "/relations", method = RequestMethod.DELETE, params = { "id", "type" })
@ResponseStatus(value = HttpStatus.OK)
public void deleteRelations(@RequestParam("entityId") String strId, @RequestParam("entityType") String strType) throws ThingsboardException {
    checkParameter("entityId", strId);
    checkParameter("entityType", strType);
    EntityId entityId = EntityIdFactory.getByTypeAndId(strType, strId);
    checkEntityId(entityId);
    try {
        relationService.deleteEntityRelations(entityId);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : EntityId(org.thingsboard.server.common.data.id.EntityId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 63 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class RuleController method getTenantRules.

@PreAuthorize("hasAuthority('TENANT_ADMIN')")
@RequestMapping(value = "/rule", params = { "limit" }, method = RequestMethod.GET)
@ResponseBody
public TextPageData<RuleMetaData> getTenantRules(@RequestParam int limit, @RequestParam(required = false) String textSearch, @RequestParam(required = false) String idOffset, @RequestParam(required = false) String textOffset) throws ThingsboardException {
    try {
        TenantId tenantId = getCurrentUser().getTenantId();
        TextPageLink pageLink = createPageLink(limit, textSearch, idOffset, textOffset);
        return checkNotNull(ruleService.findTenantRules(tenantId, pageLink));
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) TextPageLink(org.thingsboard.server.common.data.page.TextPageLink) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 64 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class RuleController method deleteRule.

@PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN')")
@RequestMapping(value = "/rule/{ruleId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deleteRule(@PathVariable(RULE_ID) String strRuleId) throws ThingsboardException {
    checkParameter(RULE_ID, strRuleId);
    try {
        RuleId ruleId = new RuleId(toUUID(strRuleId));
        RuleMetaData rule = checkRule(ruleService.findRuleById(ruleId));
        ruleService.deleteRuleById(ruleId);
        actorService.onRuleStateChange(rule.getTenantId(), rule.getId(), ComponentLifecycleEvent.DELETED);
        logEntityAction(ruleId, rule, null, ActionType.DELETED, null, strRuleId);
    } catch (Exception e) {
        logEntityAction(emptyId(EntityType.RULE), null, null, ActionType.DELETED, e, strRuleId);
        throw handleException(e);
    }
}
Also used : RuleId(org.thingsboard.server.common.data.id.RuleId) RuleMetaData(org.thingsboard.server.common.data.rule.RuleMetaData) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Example 65 with ThingsboardException

use of org.thingsboard.server.exception.ThingsboardException in project thingsboard by thingsboard.

the class TenantController method deleteTenant.

@PreAuthorize("hasAuthority('SYS_ADMIN')")
@RequestMapping(value = "/tenant/{tenantId}", method = RequestMethod.DELETE)
@ResponseStatus(value = HttpStatus.OK)
public void deleteTenant(@PathVariable("tenantId") String strTenantId) throws ThingsboardException {
    checkParameter("tenantId", strTenantId);
    try {
        TenantId tenantId = new TenantId(toUUID(strTenantId));
        tenantService.deleteTenant(tenantId);
    } catch (Exception e) {
        throw handleException(e);
    }
}
Also used : TenantId(org.thingsboard.server.common.data.id.TenantId) ThingsboardException(org.thingsboard.server.exception.ThingsboardException) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize)

Aggregations

ThingsboardException (org.thingsboard.server.exception.ThingsboardException)88 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)72 IncorrectParameterException (org.thingsboard.server.dao.exception.IncorrectParameterException)39 TenantId (org.thingsboard.server.common.data.id.TenantId)23 SecurityUser (org.thingsboard.server.service.security.model.SecurityUser)18 CustomerId (org.thingsboard.server.common.data.id.CustomerId)17 TextPageLink (org.thingsboard.server.common.data.page.TextPageLink)11 Customer (org.thingsboard.server.common.data.Customer)10 MessagingException (javax.mail.MessagingException)8 DashboardId (org.thingsboard.server.common.data.id.DashboardId)8 DataValidationException (org.thingsboard.server.dao.exception.DataValidationException)8 Device (org.thingsboard.server.common.data.Device)7 EntityId (org.thingsboard.server.common.data.id.EntityId)7 TimePageLink (org.thingsboard.server.common.data.page.TimePageLink)7 User (org.thingsboard.server.common.data.User)6 Asset (org.thingsboard.server.common.data.asset.Asset)6 DeviceId (org.thingsboard.server.common.data.id.DeviceId)6 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)6 UserCredentials (org.thingsboard.server.common.data.security.UserCredentials)6 List (java.util.List)5