Auto-remove alarms when originator is deleted
This commit is contained in:
		
							parent
							
								
									8dca042035
								
							
						
					
					
						commit
						cff4f35b9a
					
				@ -19,12 +19,13 @@ import io.swagger.v3.oas.annotations.Parameter;
 | 
				
			|||||||
import io.swagger.v3.oas.annotations.media.Schema;
 | 
					import io.swagger.v3.oas.annotations.media.Schema;
 | 
				
			||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import org.springframework.security.access.prepost.PreAuthorize;
 | 
					import org.springframework.security.access.prepost.PreAuthorize;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.DeleteMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.GetMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
					import org.springframework.web.bind.annotation.PathVariable;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PostMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
					import org.springframework.web.bind.annotation.RequestBody;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMethod;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
					import org.springframework.web.bind.annotation.RequestParam;
 | 
				
			||||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.RestController;
 | 
					import org.springframework.web.bind.annotation.RestController;
 | 
				
			||||||
import org.thingsboard.server.common.data.alarm.Alarm;
 | 
					import org.thingsboard.server.common.data.alarm.Alarm;
 | 
				
			||||||
import org.thingsboard.server.common.data.alarm.AlarmComment;
 | 
					import org.thingsboard.server.common.data.alarm.AlarmComment;
 | 
				
			||||||
@ -54,6 +55,7 @@ import static org.thingsboard.server.controller.ControllerConstants.UUID_WIKI_LI
 | 
				
			|||||||
@RequiredArgsConstructor
 | 
					@RequiredArgsConstructor
 | 
				
			||||||
@RequestMapping("/api")
 | 
					@RequestMapping("/api")
 | 
				
			||||||
public class AlarmCommentController extends BaseController {
 | 
					public class AlarmCommentController extends BaseController {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public static final String ALARM_ID = "alarmId";
 | 
					    public static final String ALARM_ID = "alarmId";
 | 
				
			||||||
    public static final String ALARM_COMMENT_ID = "commentId";
 | 
					    public static final String ALARM_COMMENT_ID = "commentId";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -68,8 +70,7 @@ public class AlarmCommentController extends BaseController {
 | 
				
			|||||||
                    "\n\n If comment type is not specified the default value 'OTHER' will be saved. If 'alarmId' or 'userId' specified in body it will be ignored." +
 | 
					                    "\n\n If comment type is not specified the default value 'OTHER' will be saved. If 'alarmId' or 'userId' specified in body it will be ignored." +
 | 
				
			||||||
                    TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/comment", method = RequestMethod.POST)
 | 
					    @PostMapping(value = "/alarm/{alarmId}/comment")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public AlarmComment saveAlarmComment(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
					    public AlarmComment saveAlarmComment(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
				
			||||||
                                         @PathVariable(ALARM_ID) String strAlarmId, @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "A JSON value representing the comment.") @RequestBody AlarmComment alarmComment) throws ThingsboardException {
 | 
					                                         @PathVariable(ALARM_ID) String strAlarmId, @io.swagger.v3.oas.annotations.parameters.RequestBody(description = "A JSON value representing the comment.") @RequestBody AlarmComment alarmComment) throws ThingsboardException {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
@ -82,8 +83,7 @@ public class AlarmCommentController extends BaseController {
 | 
				
			|||||||
    @ApiOperation(value = "Delete Alarm comment (deleteAlarmComment)",
 | 
					    @ApiOperation(value = "Delete Alarm comment (deleteAlarmComment)",
 | 
				
			||||||
            notes = "Deletes the Alarm comment. Referencing non-existing Alarm comment Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					            notes = "Deletes the Alarm comment. Referencing non-existing Alarm comment Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/comment/{commentId}", method = RequestMethod.DELETE)
 | 
					    @DeleteMapping(value = "/alarm/{alarmId}/comment/{commentId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public void deleteAlarmComment(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId, @Parameter(description = ALARM_COMMENT_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_COMMENT_ID) String strCommentId) throws ThingsboardException {
 | 
					    public void deleteAlarmComment(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId, @Parameter(description = ALARM_COMMENT_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_COMMENT_ID) String strCommentId) throws ThingsboardException {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
        AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
 | 
					        AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
 | 
				
			||||||
@ -98,8 +98,7 @@ public class AlarmCommentController extends BaseController {
 | 
				
			|||||||
            notes = "Returns a page of alarm comments for specified alarm. " +
 | 
					            notes = "Returns a page of alarm comments for specified alarm. " +
 | 
				
			||||||
                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/comment", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/{alarmId}/comment")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<AlarmCommentInfo> getAlarmComments(
 | 
					    public PageData<AlarmCommentInfo> getAlarmComments(
 | 
				
			||||||
            @Parameter(description = ALARM_ID_PARAM_DESCRIPTION, required = true)
 | 
					            @Parameter(description = ALARM_ID_PARAM_DESCRIPTION, required = true)
 | 
				
			||||||
            @PathVariable(ALARM_ID) String strAlarmId,
 | 
					            @PathVariable(ALARM_ID) String strAlarmId,
 | 
				
			||||||
@ -118,4 +117,5 @@ public class AlarmCommentController extends BaseController {
 | 
				
			|||||||
        PageLink pageLink = createPageLink(pageSize, page, null, sortProperty, sortOrder);
 | 
					        PageLink pageLink = createPageLink(pageSize, page, null, sortProperty, sortOrder);
 | 
				
			||||||
        return checkNotNull(alarmCommentService.findAlarmComments(alarm.getTenantId(), alarmId, pageLink));
 | 
					        return checkNotNull(alarmCommentService.findAlarmComments(alarm.getTenantId(), alarmId, pageLink));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -21,12 +21,13 @@ import io.swagger.v3.oas.annotations.media.Schema;
 | 
				
			|||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
import org.springframework.http.HttpStatus;
 | 
					import org.springframework.http.HttpStatus;
 | 
				
			||||||
import org.springframework.security.access.prepost.PreAuthorize;
 | 
					import org.springframework.security.access.prepost.PreAuthorize;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.DeleteMapping;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.GetMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.PathVariable;
 | 
					import org.springframework.web.bind.annotation.PathVariable;
 | 
				
			||||||
 | 
					import org.springframework.web.bind.annotation.PostMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestBody;
 | 
					import org.springframework.web.bind.annotation.RequestBody;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
					import org.springframework.web.bind.annotation.RequestMapping;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestMethod;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.RequestParam;
 | 
					import org.springframework.web.bind.annotation.RequestParam;
 | 
				
			||||||
import org.springframework.web.bind.annotation.ResponseBody;
 | 
					 | 
				
			||||||
import org.springframework.web.bind.annotation.ResponseStatus;
 | 
					import org.springframework.web.bind.annotation.ResponseStatus;
 | 
				
			||||||
import org.springframework.web.bind.annotation.RestController;
 | 
					import org.springframework.web.bind.annotation.RestController;
 | 
				
			||||||
import org.thingsboard.server.common.data.EntitySubtype;
 | 
					import org.thingsboard.server.common.data.EntitySubtype;
 | 
				
			||||||
@ -58,7 +59,6 @@ import java.util.Arrays;
 | 
				
			|||||||
import java.util.Collections;
 | 
					import java.util.Collections;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
import java.util.concurrent.ExecutionException;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
import static org.thingsboard.server.controller.ControllerConstants.ALARM_ID_PARAM_DESCRIPTION;
 | 
					import static org.thingsboard.server.controller.ControllerConstants.ALARM_ID_PARAM_DESCRIPTION;
 | 
				
			||||||
import static org.thingsboard.server.controller.ControllerConstants.ALARM_INFO_DESCRIPTION;
 | 
					import static org.thingsboard.server.controller.ControllerConstants.ALARM_INFO_DESCRIPTION;
 | 
				
			||||||
@ -104,8 +104,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
    @ApiOperation(value = "Get Alarm (getAlarmById)",
 | 
					    @ApiOperation(value = "Get Alarm (getAlarmById)",
 | 
				
			||||||
            notes = "Fetch the Alarm object based on the provided Alarm Id. " + ALARM_SECURITY_CHECK)
 | 
					            notes = "Fetch the Alarm object based on the provided Alarm Id. " + ALARM_SECURITY_CHECK)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/{alarmId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public Alarm getAlarmById(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
					    public Alarm getAlarmById(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
				
			||||||
                              @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
					                              @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
@ -117,8 +116,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            notes = "Fetch the Alarm Info object based on the provided Alarm Id. " +
 | 
					            notes = "Fetch the Alarm Info object based on the provided Alarm Id. " +
 | 
				
			||||||
                    ALARM_SECURITY_CHECK + ALARM_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    ALARM_SECURITY_CHECK + ALARM_INFO_DESCRIPTION + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/info/{alarmId}", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/info/{alarmId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public AlarmInfo getAlarmInfoById(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
					    public AlarmInfo getAlarmInfoById(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
				
			||||||
                                      @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
					                                      @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
@ -136,11 +134,9 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "If the user tries to create 'HighTemperature' alarm for the same device again, the previous alarm will be updated (the 'end_ts' will be set to current timestamp). " +
 | 
					                    "If the user tries to create 'HighTemperature' alarm for the same device again, the previous alarm will be updated (the 'end_ts' will be set to current timestamp). " +
 | 
				
			||||||
                    "If the user clears the alarm (see 'Clear Alarm(clearAlarm)'), than new alarm with the same type and same device may be created. " +
 | 
					                    "If the user clears the alarm (see 'Clear Alarm(clearAlarm)'), than new alarm with the same type and same device may be created. " +
 | 
				
			||||||
                    "Remove 'id', 'tenantId' and optionally 'customerId' from the request body example (below) to create new Alarm entity. " +
 | 
					                    "Remove 'id', 'tenantId' and optionally 'customerId' from the request body example (below) to create new Alarm entity. " +
 | 
				
			||||||
                    TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH
 | 
					                    TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm", method = RequestMethod.POST)
 | 
					    @PostMapping(value = "/alarm")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public Alarm saveAlarm(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "A JSON value representing the alarm.") @RequestBody Alarm alarm) throws ThingsboardException {
 | 
					    public Alarm saveAlarm(@io.swagger.v3.oas.annotations.parameters.RequestBody(description = "A JSON value representing the alarm.") @RequestBody Alarm alarm) throws ThingsboardException {
 | 
				
			||||||
        alarm.setTenantId(getTenantId());
 | 
					        alarm.setTenantId(getTenantId());
 | 
				
			||||||
        checkNotNull(alarm.getOriginator());
 | 
					        checkNotNull(alarm.getOriginator());
 | 
				
			||||||
@ -155,8 +151,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
    @ApiOperation(value = "Delete Alarm (deleteAlarm)",
 | 
					    @ApiOperation(value = "Delete Alarm (deleteAlarm)",
 | 
				
			||||||
            notes = "Deletes the Alarm. Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					            notes = "Deletes the Alarm. Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}", method = RequestMethod.DELETE)
 | 
					    @DeleteMapping(value = "/alarm/{alarmId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public boolean deleteAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
					    public boolean deleteAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws ThingsboardException {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
        AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
 | 
					        AlarmId alarmId = new AlarmId(toUUID(strAlarmId));
 | 
				
			||||||
@ -169,7 +164,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "Once acknowledged, the 'ack_ts' field will be set to current timestamp and special rule chain event 'ALARM_ACK' will be generated. " +
 | 
					                    "Once acknowledged, the 'ack_ts' field will be set to current timestamp and special rule chain event 'ALARM_ACK' will be generated. " +
 | 
				
			||||||
                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/ack", method = RequestMethod.POST)
 | 
					    @PostMapping(value = "/alarm/{alarmId}/ack")
 | 
				
			||||||
    @ResponseStatus(value = HttpStatus.OK)
 | 
					    @ResponseStatus(value = HttpStatus.OK)
 | 
				
			||||||
    public AlarmInfo ackAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws Exception {
 | 
					    public AlarmInfo ackAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws Exception {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
@ -184,7 +179,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "Once cleared, the 'clear_ts' field will be set to current timestamp and special rule chain event 'ALARM_CLEAR' will be generated. " +
 | 
					                    "Once cleared, the 'clear_ts' field will be set to current timestamp and special rule chain event 'ALARM_CLEAR' will be generated. " +
 | 
				
			||||||
                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/clear", method = RequestMethod.POST)
 | 
					    @PostMapping(value = "/alarm/{alarmId}/clear")
 | 
				
			||||||
    @ResponseStatus(value = HttpStatus.OK)
 | 
					    @ResponseStatus(value = HttpStatus.OK)
 | 
				
			||||||
    public AlarmInfo clearAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws Exception {
 | 
					    public AlarmInfo clearAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION) @PathVariable(ALARM_ID) String strAlarmId) throws Exception {
 | 
				
			||||||
        checkParameter(ALARM_ID, strAlarmId);
 | 
					        checkParameter(ALARM_ID, strAlarmId);
 | 
				
			||||||
@ -200,7 +195,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "(or ALARM_REASSIGNED in case of assigning already assigned alarm) will be generated. " +
 | 
					                    "(or ALARM_REASSIGNED in case of assigning already assigned alarm) will be generated. " +
 | 
				
			||||||
                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/assign/{assigneeId}", method = RequestMethod.POST)
 | 
					    @PostMapping(value = "/alarm/{alarmId}/assign/{assigneeId}")
 | 
				
			||||||
    @ResponseStatus(value = HttpStatus.OK)
 | 
					    @ResponseStatus(value = HttpStatus.OK)
 | 
				
			||||||
    public Alarm assignAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
					    public Alarm assignAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
				
			||||||
                             @PathVariable(ALARM_ID) String strAlarmId,
 | 
					                             @PathVariable(ALARM_ID) String strAlarmId,
 | 
				
			||||||
@ -221,7 +216,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "Once unassigned, the 'assign_ts' field will be set to current timestamp and special rule chain event 'ALARM_UNASSIGNED' will be generated. " +
 | 
					                    "Once unassigned, the 'assign_ts' field will be set to current timestamp and special rule chain event 'ALARM_UNASSIGNED' will be generated. " +
 | 
				
			||||||
                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    "Referencing non-existing Alarm Id will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{alarmId}/assign", method = RequestMethod.DELETE)
 | 
					    @DeleteMapping(value = "/alarm/{alarmId}/assign")
 | 
				
			||||||
    @ResponseStatus(value = HttpStatus.OK)
 | 
					    @ResponseStatus(value = HttpStatus.OK)
 | 
				
			||||||
    public Alarm unassignAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
					    public Alarm unassignAlarm(@Parameter(description = ALARM_ID_PARAM_DESCRIPTION)
 | 
				
			||||||
                               @PathVariable(ALARM_ID) String strAlarmId
 | 
					                               @PathVariable(ALARM_ID) String strAlarmId
 | 
				
			||||||
@ -236,8 +231,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            notes = "Returns a page of alarms for the selected entity. Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
 | 
					            notes = "Returns a page of alarms for the selected entity. Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
 | 
				
			||||||
                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/{entityType}/{entityId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<AlarmInfo> getAlarms(
 | 
					    public PageData<AlarmInfo> getAlarms(
 | 
				
			||||||
            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
					            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
				
			||||||
            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
					            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
				
			||||||
@ -265,7 +259,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            @RequestParam(required = false) Long endTime,
 | 
					            @RequestParam(required = false) Long endTime,
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
 | 
					            @Parameter(description = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
 | 
				
			||||||
            @RequestParam(required = false) Boolean fetchOriginator
 | 
					            @RequestParam(required = false) Boolean fetchOriginator
 | 
				
			||||||
    ) throws ThingsboardException, ExecutionException, InterruptedException {
 | 
					    ) throws ThingsboardException {
 | 
				
			||||||
        checkParameter("EntityId", strEntityId);
 | 
					        checkParameter("EntityId", strEntityId);
 | 
				
			||||||
        checkParameter("EntityType", strEntityType);
 | 
					        checkParameter("EntityType", strEntityType);
 | 
				
			||||||
        EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
 | 
					        EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
 | 
				
			||||||
@ -292,8 +286,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
 | 
					                    "Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error. " +
 | 
				
			||||||
                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarms", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarms")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<AlarmInfo> getAllAlarms(
 | 
					    public PageData<AlarmInfo> getAllAlarms(
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, schema = @Schema(allowableValues = {"ANY", "ACTIVE", "CLEARED", "ACK", "UNACK"}))
 | 
					            @Parameter(description = ALARM_QUERY_SEARCH_STATUS_DESCRIPTION, schema = @Schema(allowableValues = {"ANY", "ACTIVE", "CLEARED", "ACK", "UNACK"}))
 | 
				
			||||||
            @RequestParam(required = false) String searchStatus,
 | 
					            @RequestParam(required = false) String searchStatus,
 | 
				
			||||||
@ -317,7 +310,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            @RequestParam(required = false) Long endTime,
 | 
					            @RequestParam(required = false) Long endTime,
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
 | 
					            @Parameter(description = ALARM_QUERY_FETCH_ORIGINATOR_DESCRIPTION)
 | 
				
			||||||
            @RequestParam(required = false) Boolean fetchOriginator
 | 
					            @RequestParam(required = false) Boolean fetchOriginator
 | 
				
			||||||
    ) throws ThingsboardException, ExecutionException, InterruptedException {
 | 
					    ) throws ThingsboardException {
 | 
				
			||||||
        AlarmSearchStatus alarmSearchStatus = StringUtils.isEmpty(searchStatus) ? null : AlarmSearchStatus.valueOf(searchStatus);
 | 
					        AlarmSearchStatus alarmSearchStatus = StringUtils.isEmpty(searchStatus) ? null : AlarmSearchStatus.valueOf(searchStatus);
 | 
				
			||||||
        AlarmStatus alarmStatus = StringUtils.isEmpty(status) ? null : AlarmStatus.valueOf(status);
 | 
					        AlarmStatus alarmStatus = StringUtils.isEmpty(status) ? null : AlarmStatus.valueOf(status);
 | 
				
			||||||
        if (alarmSearchStatus != null && alarmStatus != null) {
 | 
					        if (alarmSearchStatus != null && alarmStatus != null) {
 | 
				
			||||||
@ -341,8 +334,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            notes = "Returns a page of alarms for the selected entity. " +
 | 
					            notes = "Returns a page of alarms for the selected entity. " +
 | 
				
			||||||
                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('SYS_ADMIN', 'TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/v2/alarm/{entityType}/{entityId}", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/v2/alarm/{entityType}/{entityId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<AlarmInfo> getAlarmsV2(
 | 
					    public PageData<AlarmInfo> getAlarmsV2(
 | 
				
			||||||
            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
					            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
				
			||||||
            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
					            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
				
			||||||
@ -370,7 +362,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            @RequestParam(required = false) Long startTime,
 | 
					            @RequestParam(required = false) Long startTime,
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_END_TIME_DESCRIPTION)
 | 
					            @Parameter(description = ALARM_QUERY_END_TIME_DESCRIPTION)
 | 
				
			||||||
            @RequestParam(required = false) Long endTime
 | 
					            @RequestParam(required = false) Long endTime
 | 
				
			||||||
    ) throws ThingsboardException, ExecutionException, InterruptedException {
 | 
					    ) throws ThingsboardException {
 | 
				
			||||||
        checkParameter("EntityId", strEntityId);
 | 
					        checkParameter("EntityId", strEntityId);
 | 
				
			||||||
        checkParameter("EntityType", strEntityType);
 | 
					        checkParameter("EntityType", strEntityType);
 | 
				
			||||||
        EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
 | 
					        EntityId entityId = EntityIdFactory.getByTypeAndId(strEntityType, strEntityId);
 | 
				
			||||||
@ -407,8 +399,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                    "If the user has the authority of 'Customer User', the server returns alarms that belongs to the customer of current user. " +
 | 
					                    "If the user has the authority of 'Customer User', the server returns alarms that belongs to the customer of current user. " +
 | 
				
			||||||
                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
					                    PAGE_DATA_PARAMETERS + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/v2/alarms", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/v2/alarms")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<AlarmInfo> getAllAlarmsV2(
 | 
					    public PageData<AlarmInfo> getAllAlarmsV2(
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_SEARCH_STATUS_ARRAY_DESCRIPTION, array = @ArraySchema(schema = @Schema(type = "string", allowableValues = {"ANY", "ACTIVE", "CLEARED", "ACK", "UNACK"})))
 | 
					            @Parameter(description = ALARM_QUERY_SEARCH_STATUS_ARRAY_DESCRIPTION, array = @ArraySchema(schema = @Schema(type = "string", allowableValues = {"ANY", "ACTIVE", "CLEARED", "ACK", "UNACK"})))
 | 
				
			||||||
            @RequestParam(required = false) String[] statusList,
 | 
					            @RequestParam(required = false) String[] statusList,
 | 
				
			||||||
@ -432,7 +423,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
            @RequestParam(required = false) Long startTime,
 | 
					            @RequestParam(required = false) Long startTime,
 | 
				
			||||||
            @Parameter(description = ALARM_QUERY_END_TIME_DESCRIPTION)
 | 
					            @Parameter(description = ALARM_QUERY_END_TIME_DESCRIPTION)
 | 
				
			||||||
            @RequestParam(required = false) Long endTime
 | 
					            @RequestParam(required = false) Long endTime
 | 
				
			||||||
    ) throws ThingsboardException, ExecutionException, InterruptedException {
 | 
					    ) throws ThingsboardException {
 | 
				
			||||||
        List<AlarmSearchStatus> alarmStatusList = new ArrayList<>();
 | 
					        List<AlarmSearchStatus> alarmStatusList = new ArrayList<>();
 | 
				
			||||||
        if (statusList != null) {
 | 
					        if (statusList != null) {
 | 
				
			||||||
            for (String strStatus : statusList) {
 | 
					            for (String strStatus : statusList) {
 | 
				
			||||||
@ -465,11 +456,9 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    @ApiOperation(value = "Get Highest Alarm Severity (getHighestAlarmSeverity)",
 | 
					    @ApiOperation(value = "Get Highest Alarm Severity (getHighestAlarmSeverity)",
 | 
				
			||||||
            notes = "Search the alarms by originator ('entityType' and entityId') and optional 'status' or 'searchStatus' filters and returns the highest AlarmSeverity(CRITICAL, MAJOR, MINOR, WARNING or INDETERMINATE). " +
 | 
					            notes = "Search the alarms by originator ('entityType' and entityId') and optional 'status' or 'searchStatus' filters and returns the highest AlarmSeverity(CRITICAL, MAJOR, MINOR, WARNING or INDETERMINATE). " +
 | 
				
			||||||
                    "Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH
 | 
					                    "Specifying both parameters 'searchStatus' and 'status' at the same time will cause an error." + TENANT_OR_CUSTOMER_AUTHORITY_PARAGRAPH)
 | 
				
			||||||
            )
 | 
					 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/highestSeverity/{entityType}/{entityId}")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public AlarmSeverity getHighestAlarmSeverity(
 | 
					    public AlarmSeverity getHighestAlarmSeverity(
 | 
				
			||||||
            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
					            @Parameter(description = ENTITY_TYPE_PARAM_DESCRIPTION, required = true, schema = @Schema(defaultValue = "DEVICE"))
 | 
				
			||||||
            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
					            @PathVariable(ENTITY_TYPE) String strEntityType,
 | 
				
			||||||
@ -499,8 +488,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
    @ApiOperation(value = "Get Alarm Types (getAlarmTypes)",
 | 
					    @ApiOperation(value = "Get Alarm Types (getAlarmTypes)",
 | 
				
			||||||
            notes = "Returns a set of unique alarm types based on alarms that are either owned by the tenant or assigned to the customer which user is performing the request.")
 | 
					            notes = "Returns a set of unique alarm types based on alarms that are either owned by the tenant or assigned to the customer which user is performing the request.")
 | 
				
			||||||
    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
					    @PreAuthorize("hasAnyAuthority('TENANT_ADMIN', 'CUSTOMER_USER')")
 | 
				
			||||||
    @RequestMapping(value = "/alarm/types", method = RequestMethod.GET)
 | 
					    @GetMapping(value = "/alarm/types")
 | 
				
			||||||
    @ResponseBody
 | 
					 | 
				
			||||||
    public PageData<EntitySubtype> getAlarmTypes(@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
 | 
					    public PageData<EntitySubtype> getAlarmTypes(@Parameter(description = PAGE_SIZE_DESCRIPTION, required = true)
 | 
				
			||||||
                                                 @RequestParam int pageSize,
 | 
					                                                 @RequestParam int pageSize,
 | 
				
			||||||
                                                 @Parameter(description = PAGE_NUMBER_DESCRIPTION, required = true)
 | 
					                                                 @Parameter(description = PAGE_NUMBER_DESCRIPTION, required = true)
 | 
				
			||||||
@ -508,7 +496,7 @@ public class AlarmController extends BaseController {
 | 
				
			|||||||
                                                 @Parameter(description = ALARM_QUERY_TEXT_SEARCH_DESCRIPTION)
 | 
					                                                 @Parameter(description = ALARM_QUERY_TEXT_SEARCH_DESCRIPTION)
 | 
				
			||||||
                                                 @RequestParam(required = false) String textSearch,
 | 
					                                                 @RequestParam(required = false) String textSearch,
 | 
				
			||||||
                                                 @Parameter(description = SORT_ORDER_DESCRIPTION, schema = @Schema(allowableValues = {"ASC", "DESC"}))
 | 
					                                                 @Parameter(description = SORT_ORDER_DESCRIPTION, schema = @Schema(allowableValues = {"ASC", "DESC"}))
 | 
				
			||||||
                                                 @RequestParam(required = false) String sortOrder) throws ThingsboardException, ExecutionException, InterruptedException {
 | 
					                                                 @RequestParam(required = false) String sortOrder) throws ThingsboardException {
 | 
				
			||||||
        PageLink pageLink = createPageLink(pageSize, page, textSearch, "type", sortOrder);
 | 
					        PageLink pageLink = createPageLink(pageSize, page, textSearch, "type", sortOrder);
 | 
				
			||||||
        return checkNotNull(alarmService.findAlarmTypesByTenantId(getTenantId(), pageLink));
 | 
					        return checkNotNull(alarmService.findAlarmTypesByTenantId(getTenantId(), pageLink));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
				
			|||||||
@ -32,7 +32,7 @@ import org.thingsboard.server.service.entitiy.AbstractTbEntityService;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
@Service
 | 
					@Service
 | 
				
			||||||
@AllArgsConstructor
 | 
					@AllArgsConstructor
 | 
				
			||||||
public class DefaultTbAlarmCommentService extends AbstractTbEntityService implements TbAlarmCommentService{
 | 
					public class DefaultTbAlarmCommentService extends AbstractTbEntityService implements TbAlarmCommentService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private AlarmCommentService alarmCommentService;
 | 
					    private AlarmCommentService alarmCommentService;
 | 
				
			||||||
@ -68,4 +68,5 @@ public class DefaultTbAlarmCommentService extends AbstractTbEntityService implem
 | 
				
			|||||||
            throw new ThingsboardException("System comment could not be deleted", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
 | 
					            throw new ThingsboardException("System comment could not be deleted", ThingsboardErrorCode.BAD_REQUEST_PARAMS);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -43,29 +43,27 @@ public class AlarmsDeletionTaskProcessor extends HousekeeperTaskProcessor<Alarms
 | 
				
			|||||||
        EntityType entityType = entityId.getEntityType();
 | 
					        EntityType entityType = entityId.getEntityType();
 | 
				
			||||||
        TenantId tenantId = task.getTenantId();
 | 
					        TenantId tenantId = task.getTenantId();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        if (entityType == EntityType.DEVICE || entityType == EntityType.ASSET) {
 | 
					        if (task.getAlarms() == null) {
 | 
				
			||||||
            if (task.getAlarms() == null) {
 | 
					            AlarmId lastId = null;
 | 
				
			||||||
                AlarmId lastId = null;
 | 
					            long lastCreatedTime = 0;
 | 
				
			||||||
                long lastCreatedTime = 0;
 | 
					            while (true) {
 | 
				
			||||||
                while (true) {
 | 
					                List<TbPair<UUID, Long>> alarms = alarmService.findAlarmIdsByOriginatorId(tenantId, entityId, lastCreatedTime, lastId, 128);
 | 
				
			||||||
                    List<TbPair<UUID, Long>> alarms = alarmService.findAlarmIdsByOriginatorId(tenantId, entityId, lastCreatedTime, lastId, 128);
 | 
					                if (alarms.isEmpty()) {
 | 
				
			||||||
                    if (alarms.isEmpty()) {
 | 
					                    break;
 | 
				
			||||||
                        break;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    housekeeperClient.submitTask(new AlarmsDeletionHousekeeperTask(tenantId, entityId, alarms.stream().map(TbPair::getFirst).toList()));
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                    TbPair<UUID, Long> last = alarms.get(alarms.size() - 1);
 | 
					 | 
				
			||||||
                    lastId = new AlarmId(last.getFirst());
 | 
					 | 
				
			||||||
                    lastCreatedTime = last.getSecond();
 | 
					 | 
				
			||||||
                    log.debug("[{}][{}][{}] Submitted task for deleting {} alarms", tenantId, entityType, entityId, alarms.size());
 | 
					 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
            } else {
 | 
					
 | 
				
			||||||
                for (UUID alarmId : task.getAlarms()) {
 | 
					                housekeeperClient.submitTask(new AlarmsDeletionHousekeeperTask(tenantId, entityId, alarms.stream().map(TbPair::getFirst).toList()));
 | 
				
			||||||
                    alarmService.delAlarm(tenantId, new AlarmId(alarmId));
 | 
					
 | 
				
			||||||
                }
 | 
					                TbPair<UUID, Long> last = alarms.get(alarms.size() - 1);
 | 
				
			||||||
                log.debug("[{}][{}][{}] Deleted {} alarms", tenantId, entityType, entityId, task.getAlarms().size());
 | 
					                lastId = new AlarmId(last.getFirst());
 | 
				
			||||||
 | 
					                lastCreatedTime = last.getSecond();
 | 
				
			||||||
 | 
					                log.debug("[{}][{}][{}] Submitted task for deleting {} alarms", tenantId, entityType, entityId, alarms.size());
 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            for (UUID alarmId : task.getAlarms()) {
 | 
				
			||||||
 | 
					                alarmService.delAlarm(tenantId, new AlarmId(alarmId));
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					            log.debug("[{}][{}][{}] Deleted {} alarms", tenantId, entityType, entityId, task.getAlarms().size());
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        int count = alarmService.deleteEntityAlarmRecords(tenantId, entityId);
 | 
					        int count = alarmService.deleteEntityAlarmRecords(tenantId, entityId);
 | 
				
			||||||
 | 
				
			|||||||
@ -31,6 +31,8 @@ import org.thingsboard.rule.engine.metadata.TbGetAttributesNode;
 | 
				
			|||||||
import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
 | 
					import org.thingsboard.rule.engine.metadata.TbGetAttributesNodeConfiguration;
 | 
				
			||||||
import org.thingsboard.server.common.data.ApiUsageState;
 | 
					import org.thingsboard.server.common.data.ApiUsageState;
 | 
				
			||||||
import org.thingsboard.server.common.data.AttributeScope;
 | 
					import org.thingsboard.server.common.data.AttributeScope;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.Customer;
 | 
				
			||||||
 | 
					import org.thingsboard.server.common.data.Dashboard;
 | 
				
			||||||
import org.thingsboard.server.common.data.Device;
 | 
					import org.thingsboard.server.common.data.Device;
 | 
				
			||||||
import org.thingsboard.server.common.data.EventInfo;
 | 
					import org.thingsboard.server.common.data.EventInfo;
 | 
				
			||||||
import org.thingsboard.server.common.data.StringUtils;
 | 
					import org.thingsboard.server.common.data.StringUtils;
 | 
				
			||||||
@ -77,6 +79,8 @@ import org.thingsboard.server.controller.AbstractControllerTest;
 | 
				
			|||||||
import org.thingsboard.server.dao.alarm.AlarmDao;
 | 
					import org.thingsboard.server.dao.alarm.AlarmDao;
 | 
				
			||||||
import org.thingsboard.server.dao.alarm.AlarmService;
 | 
					import org.thingsboard.server.dao.alarm.AlarmService;
 | 
				
			||||||
import org.thingsboard.server.dao.attributes.AttributesService;
 | 
					import org.thingsboard.server.dao.attributes.AttributesService;
 | 
				
			||||||
 | 
					import org.thingsboard.server.dao.customer.CustomerService;
 | 
				
			||||||
 | 
					import org.thingsboard.server.dao.dashboard.DashboardService;
 | 
				
			||||||
import org.thingsboard.server.dao.entity.EntityServiceRegistry;
 | 
					import org.thingsboard.server.dao.entity.EntityServiceRegistry;
 | 
				
			||||||
import org.thingsboard.server.dao.event.EventService;
 | 
					import org.thingsboard.server.dao.event.EventService;
 | 
				
			||||||
import org.thingsboard.server.dao.relation.RelationService;
 | 
					import org.thingsboard.server.dao.relation.RelationService;
 | 
				
			||||||
@ -145,6 +149,10 @@ public class HousekeeperServiceTest extends AbstractControllerTest {
 | 
				
			|||||||
    private ApiUsageStateDao apiUsageStateDao;
 | 
					    private ApiUsageStateDao apiUsageStateDao;
 | 
				
			||||||
    @Autowired
 | 
					    @Autowired
 | 
				
			||||||
    private EntityServiceRegistry entityServiceRegistry;
 | 
					    private EntityServiceRegistry entityServiceRegistry;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private CustomerService customerService;
 | 
				
			||||||
 | 
					    @Autowired
 | 
				
			||||||
 | 
					    private DashboardService dashboardService;
 | 
				
			||||||
    @SpyBean
 | 
					    @SpyBean
 | 
				
			||||||
    private TsHistoryDeletionTaskProcessor tsHistoryDeletionTaskProcessor;
 | 
					    private TsHistoryDeletionTaskProcessor tsHistoryDeletionTaskProcessor;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -243,6 +251,62 @@ public class HousekeeperServiceTest extends AbstractControllerTest {
 | 
				
			|||||||
        });
 | 
					        });
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void whenAssetIsDeleted_thenDeleteAllAlarms() throws Exception {
 | 
				
			||||||
 | 
					        Asset asset = createAsset();
 | 
				
			||||||
 | 
					        for (int i = 1; i <= 1000; i++) {
 | 
				
			||||||
 | 
					            createAlarm(asset.getId());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doDelete("/api/asset/" + asset.getId()).andExpect(status().isOk());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
 | 
				
			||||||
 | 
					            verifyNoAlarms(asset.getId());
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void whenDashboardIsDeleted_thenDeleteAllAlarms() throws Exception {
 | 
				
			||||||
 | 
					        Dashboard dashboard = createDashboard();
 | 
				
			||||||
 | 
					        for (int i = 1; i <= 1000; i++) {
 | 
				
			||||||
 | 
					            createAlarm(dashboard.getId());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doDelete("/api/dashboard/" + dashboard.getId()).andExpect(status().isOk());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await().atMost(30, TimeUnit.SECONDS).untilAsserted(() -> {
 | 
				
			||||||
 | 
					            verifyNoAlarms(dashboard.getId());
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void whenCustomerIsDeleted_thenDeleteAllAlarms() throws Exception {
 | 
				
			||||||
 | 
					        Customer customer = createCustomer();
 | 
				
			||||||
 | 
					        for (int i = 1; i <= 1000; i++) {
 | 
				
			||||||
 | 
					            createAlarm(customer.getId());
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doDelete("/api/customer/" + customer.getId()).andExpect(status().isOk());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> {
 | 
				
			||||||
 | 
					            verifyNoAlarms(customer.getId());
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Test
 | 
				
			||||||
 | 
					    public void whenUserIsDeleted_thenDeleteAllAlarms() throws Exception {
 | 
				
			||||||
 | 
					        UserId userId = customerUserId;
 | 
				
			||||||
 | 
					        for (int i = 1; i <= 1000; i++) {
 | 
				
			||||||
 | 
					            createAlarm(userId);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        doDelete("/api/user/" + userId).andExpect(status().isOk());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        await().atMost(TIMEOUT, TimeUnit.SECONDS).untilAsserted(() -> {
 | 
				
			||||||
 | 
					            verifyNoAlarms(userId);
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Test
 | 
					    @Test
 | 
				
			||||||
    public void whenTenantIsDeleted_thenDeleteAllEntitiesAndCleanUpRelatedData() throws Exception {
 | 
					    public void whenTenantIsDeleted_thenDeleteAllEntitiesAndCleanUpRelatedData() throws Exception {
 | 
				
			||||||
        loginDifferentTenant();
 | 
					        loginDifferentTenant();
 | 
				
			||||||
@ -479,7 +543,6 @@ public class HousekeeperServiceTest extends AbstractControllerTest {
 | 
				
			|||||||
        eventService.saveAsync(event);
 | 
					        eventService.saveAsync(event);
 | 
				
			||||||
        await().atMost(10, TimeUnit.SECONDS)
 | 
					        await().atMost(10, TimeUnit.SECONDS)
 | 
				
			||||||
                .until(() -> !getEvents(entityId).isEmpty());
 | 
					                .until(() -> !getEvents(entityId).isEmpty());
 | 
				
			||||||
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void createRelation(DeviceId to, AssetId from) {
 | 
					    private void createRelation(DeviceId to, AssetId from) {
 | 
				
			||||||
@ -502,14 +565,14 @@ public class HousekeeperServiceTest extends AbstractControllerTest {
 | 
				
			|||||||
        assertThat(alarmService.findAlarmIdsByOriginatorId(tenantId, deviceId, 0, null, 10)).isNotEmpty();
 | 
					        assertThat(alarmService.findAlarmIdsByOriginatorId(tenantId, deviceId, 0, null, 10)).isNotEmpty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private void createAlarm(DeviceId deviceId) {
 | 
					    private void createAlarm(EntityId entityId) {
 | 
				
			||||||
        Alarm alarm = doPost("/api/alarm", Alarm.builder()
 | 
					        doPost("/api/alarm", Alarm.builder()
 | 
				
			||||||
                .tenantId(tenantId)
 | 
					                .tenantId(tenantId)
 | 
				
			||||||
                .originator(deviceId)
 | 
					                .originator(entityId)
 | 
				
			||||||
                .severity(AlarmSeverity.CRITICAL)
 | 
					                .severity(AlarmSeverity.CRITICAL)
 | 
				
			||||||
                .type("test alarm for " + deviceId + " " + RandomStringUtils.randomAlphabetic(10))
 | 
					                .type("test alarm for " + entityId + " " + RandomStringUtils.randomAlphabetic(10))
 | 
				
			||||||
                .build(), Alarm.class);
 | 
					                .build(), Alarm.class);
 | 
				
			||||||
        assertThat(alarmService.findAlarmIdsByOriginatorId(tenantId, deviceId, 0, null, 10)).isNotEmpty();
 | 
					        assertThat(alarmService.findAlarmIdsByOriginatorId(tenantId, entityId, 0, null, 10)).isNotEmpty();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private TsKvEntry getLatestTelemetry(EntityId entityId) throws Exception {
 | 
					    private TsKvEntry getLatestTelemetry(EntityId entityId) throws Exception {
 | 
				
			||||||
@ -534,6 +597,20 @@ public class HousekeeperServiceTest extends AbstractControllerTest {
 | 
				
			|||||||
        return doPost("/api/asset", asset, Asset.class);
 | 
					        return doPost("/api/asset", asset, Asset.class);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Customer createCustomer() {
 | 
				
			||||||
 | 
					        Customer customer = new Customer();
 | 
				
			||||||
 | 
					        customer.setTenantId(tenantId);
 | 
				
			||||||
 | 
					        customer.setTitle(StringUtils.randomAlphabetic(10));
 | 
				
			||||||
 | 
					        return customerService.saveCustomer(customer);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private Dashboard createDashboard() {
 | 
				
			||||||
 | 
					        Dashboard dashboard = new Dashboard();
 | 
				
			||||||
 | 
					        dashboard.setTenantId(tenantId);
 | 
				
			||||||
 | 
					        dashboard.setTitle(StringUtils.randomAlphabetic(10));
 | 
				
			||||||
 | 
					        return dashboardService.saveDashboard(dashboard);
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private RuleChainMetaData createRuleChain() {
 | 
					    private RuleChainMetaData createRuleChain() {
 | 
				
			||||||
        RuleChain ruleChain = new RuleChain();
 | 
					        RuleChain ruleChain = new RuleChain();
 | 
				
			||||||
        ruleChain.setTenantId(tenantId);
 | 
					        ruleChain.setTenantId(tenantId);
 | 
				
			||||||
 | 
				
			|||||||
@ -37,13 +37,11 @@ import org.thingsboard.server.common.data.id.UserId;
 | 
				
			|||||||
import org.thingsboard.server.common.data.validation.Length;
 | 
					import org.thingsboard.server.common.data.validation.Length;
 | 
				
			||||||
import org.thingsboard.server.common.data.validation.NoXss;
 | 
					import org.thingsboard.server.common.data.validation.NoXss;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serial;
 | 
				
			||||||
import java.util.List;
 | 
					import java.util.List;
 | 
				
			||||||
import java.util.Optional;
 | 
					import java.util.Optional;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by ashvayka on 11.05.17.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
@Schema
 | 
					@Schema
 | 
				
			||||||
@Data
 | 
					@Data
 | 
				
			||||||
@EqualsAndHashCode(callSuper = true)
 | 
					@EqualsAndHashCode(callSuper = true)
 | 
				
			||||||
@ -52,6 +50,9 @@ import java.util.UUID;
 | 
				
			|||||||
@JsonIgnoreProperties(ignoreUnknown = true)
 | 
					@JsonIgnoreProperties(ignoreUnknown = true)
 | 
				
			||||||
public class Alarm extends BaseData<AlarmId> implements HasName, HasTenantId, HasCustomerId {
 | 
					public class Alarm extends BaseData<AlarmId> implements HasName, HasTenantId, HasCustomerId {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Serial
 | 
				
			||||||
 | 
					    private static final long serialVersionUID = -1935800187424953611L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Schema(description = "JSON object with Tenant Id", accessMode = Schema.AccessMode.READ_ONLY)
 | 
					    @Schema(description = "JSON object with Tenant Id", accessMode = Schema.AccessMode.READ_ONLY)
 | 
				
			||||||
    private TenantId tenantId;
 | 
					    private TenantId tenantId;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
@ -30,11 +30,17 @@ import org.thingsboard.server.common.data.id.UserId;
 | 
				
			|||||||
import org.thingsboard.server.common.data.validation.Length;
 | 
					import org.thingsboard.server.common.data.validation.Length;
 | 
				
			||||||
import org.thingsboard.server.common.data.validation.NoXss;
 | 
					import org.thingsboard.server.common.data.validation.NoXss;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import java.io.Serial;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@Schema
 | 
					@Schema
 | 
				
			||||||
@Data
 | 
					@Data
 | 
				
			||||||
@Builder
 | 
					@Builder
 | 
				
			||||||
@AllArgsConstructor
 | 
					@AllArgsConstructor
 | 
				
			||||||
public class AlarmComment extends BaseData<AlarmCommentId> implements HasName {
 | 
					public class AlarmComment extends BaseData<AlarmCommentId> implements HasName {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    @Serial
 | 
				
			||||||
 | 
					    private static final long serialVersionUID = -5454905526404017592L;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Schema(description = "JSON object with Alarm id.", accessMode = Schema.AccessMode.READ_ONLY)
 | 
					    @Schema(description = "JSON object with Alarm id.", accessMode = Schema.AccessMode.READ_ONLY)
 | 
				
			||||||
    private AlarmId alarmId;
 | 
					    private AlarmId alarmId;
 | 
				
			||||||
    @Schema(description = "JSON object with User id.", accessMode = Schema.AccessMode.READ_ONLY)
 | 
					    @Schema(description = "JSON object with User id.", accessMode = Schema.AccessMode.READ_ONLY)
 | 
				
			||||||
@ -85,4 +91,5 @@ public class AlarmComment extends BaseData<AlarmCommentId> implements HasName {
 | 
				
			|||||||
        this.comment = alarmComment.getComment();
 | 
					        this.comment = alarmComment.getComment();
 | 
				
			||||||
        this.userId = alarmComment.getUserId();
 | 
					        this.userId = alarmComment.getUserId();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -22,9 +22,6 @@ import org.thingsboard.server.common.data.id.EntityId;
 | 
				
			|||||||
import org.thingsboard.server.common.data.id.UserId;
 | 
					import org.thingsboard.server.common.data.id.UserId;
 | 
				
			||||||
import org.thingsboard.server.common.data.page.TimePageLink;
 | 
					import org.thingsboard.server.common.data.page.TimePageLink;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by ashvayka on 11.05.17.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
@Data
 | 
					@Data
 | 
				
			||||||
@Builder
 | 
					@Builder
 | 
				
			||||||
@AllArgsConstructor
 | 
					@AllArgsConstructor
 | 
				
			||||||
 | 
				
			|||||||
@ -15,9 +15,6 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
package org.thingsboard.server.common.data.alarm;
 | 
					package org.thingsboard.server.common.data.alarm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by ashvayka on 11.05.17.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public enum AlarmSeverity {
 | 
					public enum AlarmSeverity {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    CRITICAL, MAJOR, MINOR, WARNING, INDETERMINATE;
 | 
					    CRITICAL, MAJOR, MINOR, WARNING, INDETERMINATE;
 | 
				
			||||||
 | 
				
			|||||||
@ -15,9 +15,6 @@
 | 
				
			|||||||
 */
 | 
					 */
 | 
				
			||||||
package org.thingsboard.server.common.data.alarm;
 | 
					package org.thingsboard.server.common.data.alarm;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by ashvayka on 11.05.17.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public enum AlarmStatus {
 | 
					public enum AlarmStatus {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    ACTIVE_UNACK, ACTIVE_ACK, CLEARED_UNACK, CLEARED_ACK;
 | 
					    ACTIVE_UNACK, ACTIVE_ACK, CLEARED_UNACK, CLEARED_ACK;
 | 
				
			||||||
 | 
				
			|||||||
@ -17,7 +17,6 @@ package org.thingsboard.server.dao.alarm;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import com.fasterxml.jackson.databind.JsonNode;
 | 
					import com.fasterxml.jackson.databind.JsonNode;
 | 
				
			||||||
import com.google.common.base.Function;
 | 
					 | 
				
			||||||
import com.google.common.util.concurrent.FluentFuture;
 | 
					import com.google.common.util.concurrent.FluentFuture;
 | 
				
			||||||
import com.google.common.util.concurrent.ListenableFuture;
 | 
					import com.google.common.util.concurrent.ListenableFuture;
 | 
				
			||||||
import lombok.RequiredArgsConstructor;
 | 
					import lombok.RequiredArgsConstructor;
 | 
				
			||||||
@ -68,7 +67,6 @@ import org.thingsboard.server.dao.eventsourcing.DeleteEntityEvent;
 | 
				
			|||||||
import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
 | 
					import org.thingsboard.server.dao.eventsourcing.SaveEntityEvent;
 | 
				
			||||||
import org.thingsboard.server.dao.exception.DataValidationException;
 | 
					import org.thingsboard.server.dao.exception.DataValidationException;
 | 
				
			||||||
import org.thingsboard.server.dao.service.ConstraintValidator;
 | 
					import org.thingsboard.server.dao.service.ConstraintValidator;
 | 
				
			||||||
import org.thingsboard.server.dao.service.DataValidator;
 | 
					 | 
				
			||||||
import org.thingsboard.server.dao.tenant.TenantService;
 | 
					import org.thingsboard.server.dao.tenant.TenantService;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import java.util.ArrayList;
 | 
					import java.util.ArrayList;
 | 
				
			||||||
@ -98,7 +96,6 @@ public class BaseAlarmService extends AbstractCachedEntityService<TenantId, Page
 | 
				
			|||||||
    private final TenantService tenantService;
 | 
					    private final TenantService tenantService;
 | 
				
			||||||
    private final AlarmDao alarmDao;
 | 
					    private final AlarmDao alarmDao;
 | 
				
			||||||
    private final EntityService entityService;
 | 
					    private final EntityService entityService;
 | 
				
			||||||
    private final DataValidator<Alarm> alarmDataValidator;
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @TransactionalEventListener(classes = AlarmTypesCacheEvictEvent.class)
 | 
					    @TransactionalEventListener(classes = AlarmTypesCacheEvictEvent.class)
 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
@ -444,12 +441,6 @@ public class BaseAlarmService extends AbstractCachedEntityService<TenantId, Page
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private <T> T getAndUpdate(TenantId tenantId, AlarmId alarmId, Function<Alarm, T> function) {
 | 
					 | 
				
			||||||
        validateId(alarmId, "Alarm id should be specified!");
 | 
					 | 
				
			||||||
        Alarm entity = alarmDao.findAlarmById(tenantId, alarmId.getId());
 | 
					 | 
				
			||||||
        return function.apply(entity);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    @Override
 | 
					    @Override
 | 
				
			||||||
    public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
 | 
					    public Optional<HasId<?>> findEntity(TenantId tenantId, EntityId entityId) {
 | 
				
			||||||
        return Optional.ofNullable(findAlarmById(tenantId, new AlarmId(entityId.getId())));
 | 
					        return Optional.ofNullable(findAlarmById(tenantId, new AlarmId(entityId.getId())));
 | 
				
			||||||
 | 
				
			|||||||
@ -32,9 +32,6 @@ import java.util.List;
 | 
				
			|||||||
import java.util.Set;
 | 
					import java.util.Set;
 | 
				
			||||||
import java.util.UUID;
 | 
					import java.util.UUID;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by Valerii Sosliuk on 5/21/2017.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
 | 
					public interface AlarmRepository extends JpaRepository<AlarmEntity, UUID> {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC")
 | 
					    @Query("SELECT a FROM AlarmEntity a WHERE a.originatorId = :originatorId AND a.type = :alarmType ORDER BY a.startTs DESC")
 | 
				
			||||||
 | 
				
			|||||||
@ -42,9 +42,6 @@ import org.thingsboard.server.common.data.query.AlarmDataQuery;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
import java.util.Collection;
 | 
					import java.util.Collection;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/**
 | 
					 | 
				
			||||||
 * Created by ashvayka on 02.04.18.
 | 
					 | 
				
			||||||
 */
 | 
					 | 
				
			||||||
public interface RuleEngineAlarmService {
 | 
					public interface RuleEngineAlarmService {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /*
 | 
					    /*
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user