Search in sources :

Example 1 with TranslatableIllegalStateException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException 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 TranslatableIllegalStateException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method relinquish.

@ApiOperation(value = "Relinquish the value of a data point", notes = "Only BACnet data points allow this", response = Void.class)
@RequestMapping(method = RequestMethod.POST, value = "/relinquish/{xid}")
public void relinquish(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    DataPointVO dataPoint = service.get(xid);
    service.ensureReadPermission(user, dataPoint);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    // Get the Data Source and Relinquish the point
    DataSourceRT<?> dsRt = null;
    try {
        dsRt = Common.runtimeManager.getRunningDataSource(rt.getDataSourceId());
    } catch (RTException e) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.dataSourceNotEnabled", xid));
    }
    dsRt.relinquish(rt);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) RTException(com.serotonin.m2m2.rt.RTException) 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 3 with TranslatableIllegalStateException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method forceRefreshDataPoint.

@ApiOperation(value = "Force Refresh a data point", notes = "Not all data sources implement this feature", response = Void.class)
@RequestMapping(method = RequestMethod.PUT, value = "/force-refresh/{xid}")
public void forceRefreshDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
    DataPointVO vo = service.get(xid);
    service.ensureReadPermission(user, vo);
    DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    Common.runtimeManager.forcePointRead(vo.getId());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) 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 4 with TranslatableIllegalStateException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsService method getEventRT.

public MaintenanceEventRT getEventRT(String xid) throws NotFoundException, PermissionException, TranslatableIllegalStateException {
    PermissionHolder user = Common.getUser();
    MaintenanceEventVO existing = dao.getByXid(xid);
    if (existing == null)
        throw new NotFoundException();
    ensureTogglePermission(existing, user);
    MaintenanceEventRT rt = RTMDefinition.instance.getRunningMaintenanceEvent(existing.getId());
    if (rt == null)
        throw new TranslatableIllegalStateException(new TranslatableMessage("maintenanceEvents.toggle.disabled"));
    return rt;
}
Also used : MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MaintenanceEventRT(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder)

Example 5 with TranslatableIllegalStateException

use of com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method resetCache.

@ApiOperation(value = "Reset the cache on a running data point", notes = "Must have edit access to the data point", response = Void.class)
@RequestMapping(method = RequestMethod.POST, value = "/reset-cache/{xid}")
public void resetCache(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    DataPointVO vo = service.get(xid);
    service.ensureEditPermission(user, vo);
    DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    rt.invalidateCache();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) 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)

Aggregations

TranslatableIllegalStateException (com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException)6 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)4 ApiOperation (io.swagger.annotations.ApiOperation)4 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)4 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)3 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)2 NotFoundRestException (com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 MaintenanceEventRT (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventRT)1 MaintenanceEventVO (com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO)1 RTException (com.serotonin.m2m2.rt.RTException)1 PollingDataSourceVO (com.serotonin.m2m2.vo.dataSource.PollingDataSourceVO)1 AbstractEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO)1