@Override
    public AlarmApiCallResult createOrUpdateActiveAlarm(AlarmCreateOrUpdateActiveRequest request, boolean alarmCreationEnabled) {
        UUID tenantUUID = request.getTenantId().getId();
        log.debug("[{}] createOrUpdateActiveAlarm [{}] {}", tenantUUID, alarmCreationEnabled, request);

        AlarmPropagationInfo ap = getSafePropagationInfo(request.getPropagation());
        return toAlarmApiResult(alarmRepository.createOrUpdateActiveAlarm(
                tenantUUID,
                request.getCustomerId() != null ? request.getCustomerId().getId() : CustomerId.NULL_UUID,
                request.getEdgeAlarmId() != null ? request.getEdgeAlarmId().getId() : UUID.randomUUID(),
                System.currentTimeMillis(),
                request.getOriginator().getId(),
                request.getOriginator().getEntityType().ordinal(),
                request.getType(),
                request.getSeverity().name(),
                request.getStartTs(), request.getEndTs(),
                getDetailsAsString(request.getDetails()),
                ap.isPropagate(),
                ap.isPropagateToOwner(),
                ap.isPropagateToTenant(),
                getPropagationTypes(ap),
                alarmCreationEnabled
        ));
    }
@Test
    public void createOrUpdateActiveAlarm() {
        Tenant tenant = createTenant();
        TenantId tenantId = tenant.getId();
        DeviceId deviceId = new DeviceId(UUID.randomUUID());

        AlarmCreateOrUpdateActiveRequest request = AlarmCreateOrUpdateActiveRequest.builder()
                .tenantId(tenantId)
                .originator(deviceId)
                .type("ALARM_TYPE")
                .severity(AlarmSeverity.MAJOR)
                .build();
        AlarmApiCallResult result = alarmDao.createOrUpdateActiveAlarm(request, true);
        assertNotNull(result);
        assertTrue(result.isSuccessful());
        assertTrue(result.isCreated());
        assertTrue(result.isModified());
        assertNotNull(result.getAlarm());
        UUID newAlarmId = result.getAlarm().getUuidId();
        AlarmInfo afterSave = alarmDao.findAlarmInfoById(tenantId, newAlarmId);
        assertEquals(afterSave, result.getAlarm());

        request = AlarmCreateOrUpdateActiveRequest.builder()
                .tenantId(tenantId)
                .originator(deviceId)
                .type("ALARM_TYPE")
                .severity(AlarmSeverity.CRITICAL)
                .build();
        result = alarmDao.createOrUpdateActiveAlarm(request, true);
        assertNotNull(result);
        assertTrue(result.isSuccessful());
        assertFalse(result.isCreated());
        assertTrue(result.isModified());
        assertNotNull(result.getAlarm());
        assertEquals(newAlarmId, result.getAlarm().getUuidId());
        afterSave = alarmDao.findAlarmInfoById(tenantId, newAlarmId);
        assertEquals(afterSave, result.getAlarm());

        alarmDao.clearAlarm(tenantId, result.getAlarm().getId(), System.currentTimeMillis(), result.getAlarm().getDetails());

        request = AlarmCreateOrUpdateActiveRequest.builder()
                .tenantId(tenantId)
                .originator(deviceId)
                .type("ALARM_TYPE")
                .severity(AlarmSeverity.CRITICAL)
                .build();
        result = alarmDao.createOrUpdateActiveAlarm(request, true);
        assertNotNull(result);
        assertTrue(result.isSuccessful());
        assertTrue(result.isCreated());
        assertTrue(result.isModified());
        assertNotNull(result.getAlarm());
        assertNotEquals(newAlarmId, result.getAlarm().getUuidId());
        afterSave = alarmDao.findAlarmInfoById(tenantId, result.getAlarm().getUuidId());
        assertEquals(afterSave, result.getAlarm());

        alarmDao.clearAlarm(tenantId, result.getAlarm().getId(), System.currentTimeMillis(), result.getAlarm().getDetails());

        request = AlarmCreateOrUpdateActiveRequest.builder()
                .tenantId(tenantId)
                .originator(deviceId)
                .type("ALARM_TYPE2")
                .severity(AlarmSeverity.CRITICAL)
                .build();
        result = alarmDao.createOrUpdateActiveAlarm(request, true);
        assertNotNull(result);
        assertTrue(result.isSuccessful());
        assertTrue(result.isCreated());
        assertTrue(result.isModified());
        assertNotNull(result.getAlarm());
        assertNotEquals(newAlarmId, result.getAlarm().getUuidId());

        tenantDao.removeById(TenantId.SYS_TENANT_ID, tenant.getUuidId());
        tenantProfileDao.removeById(TenantId.SYS_TENANT_ID, tenant.getTenantProfileId().getId());
    }