Search in sources :

Example 6 with RelationTypeGroup

use of org.thingsboard.server.common.data.relation.RelationTypeGroup 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)

Aggregations

PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)6 EntityId (org.thingsboard.server.common.data.id.EntityId)6 RelationTypeGroup (org.thingsboard.server.common.data.relation.RelationTypeGroup)6 ThingsboardException (org.thingsboard.server.exception.ThingsboardException)6