Search in sources :

Example 1 with PointEventDetectorRT

use of com.serotonin.m2m2.rt.event.detectors.PointEventDetectorRT in project ma-modules-public by infiniteautomation.

the class EventDetectorsRestController method getState.

@ApiOperation(value = "Get Event Detector's internal state", notes = "User must have read permission for the data point", response = AbstractEventDetectorRTModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/runtime/{xid}")
public AbstractEventDetectorRTModel<?> getState(@ApiParam(value = "ID of Event detector", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    AbstractEventDetectorVO vo = service.get(xid);
    // For now all detectors are data point type
    DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getSourceId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    for (PointEventDetectorRT<?> edrt : rt.getEventDetectors()) {
        if (edrt.getVO().getId() == vo.getId()) {
            return modelMapper.map(edrt, AbstractEventDetectorRTModel.class, user);
        }
    }
    throw new NotFoundRestException();
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with PointEventDetectorRT

use of com.serotonin.m2m2.rt.event.detectors.PointEventDetectorRT in project ma-core-public by infiniteautomation.

the class DataPointChangeDefinitionTest method addDetectorsOnInsert.

@Test
public void addDetectorsOnInsert() {
    MockDataSourceVO ds = createMockDataSource(true);
    DataPointVO point = createMockDataPoint(ds, dp -> dp.setEnabled(true));
    DataPointRT rt = Common.runtimeManager.getDataPoint(point.getId());
    Assert.assertNotNull(rt);
    List<PointEventDetectorRT<?>> runningDetectors = rt.getEventDetectors();
    Assert.assertEquals(1, runningDetectors.size());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) MockDataSourceVO(com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) PointEventDetectorRT(com.serotonin.m2m2.rt.event.detectors.PointEventDetectorRT) Test(org.junit.Test)

Aggregations

DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)2 NotFoundRestException (com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException)1 TranslatableIllegalStateException (com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 PointEventDetectorRT (com.serotonin.m2m2.rt.event.detectors.PointEventDetectorRT)1 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)1 MockDataSourceVO (com.serotonin.m2m2.vo.dataSource.mock.MockDataSourceVO)1 AbstractEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO)1 ApiOperation (io.swagger.annotations.ApiOperation)1 Test (org.junit.Test)1 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)1