Search in sources :

Example 1 with ValueMonitorModel

use of com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel in project ma-modules-public by infiniteautomation.

the class SystemMetricsRestController method query.

@ApiOperation(value = "Get the current value for all System Metrics", notes = "TBD Add RQL Support to this endpoint")
@RequestMapping(method = RequestMethod.GET)
public List<ValueMonitorModel> query(@AuthenticationPrincipal User user) {
    MangoPermission permission = definition.getPermission();
    service.ensurePermission(user, permission);
    return Common.MONITORED_VALUES.getMonitors().stream().sorted(Comparator.comparing(a -> a.getName().translate(user.getTranslations()))).map(ValueMonitorModel::new).collect(Collectors.toList());
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) ValueMonitorModel(com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel) Common(com.serotonin.m2m2.Common) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) SystemMetricsReadPermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.SystemMetricsReadPermissionDefinition) Autowired(org.springframework.beans.factory.annotation.Autowired) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ApiParam(io.swagger.annotations.ApiParam) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) ModuleRegistry(com.serotonin.m2m2.module.ModuleRegistry) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor) ApiOperation(io.swagger.annotations.ApiOperation) List(java.util.List) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) Api(io.swagger.annotations.Api) Comparator(java.util.Comparator) User(com.serotonin.m2m2.vo.User) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with ValueMonitorModel

use of com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel in project ma-modules-public by infiniteautomation.

the class SystemMetricsRestController method get.

@ApiOperation(value = "Get the current value for one System Metric by its ID", notes = "")
@RequestMapping(method = RequestMethod.GET, value = "/{id}")
public ValueMonitorModel get(@ApiParam(value = "Valid Monitor id", required = true, allowMultiple = false) @PathVariable String id, @AuthenticationPrincipal PermissionHolder user) {
    MangoPermission permission = definition.getPermission();
    service.ensurePermission(user, permission);
    List<ValueMonitor<?>> values = Common.MONITORED_VALUES.getMonitors();
    for (ValueMonitor<?> v : values) {
        if (v.getId().equals(id)) {
            return new ValueMonitorModel(v);
        }
    }
    throw new NotFoundException();
}
Also used : ValueMonitorModel(com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) ValueMonitor(com.infiniteautomation.mango.monitor.ValueMonitor) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

ValueMonitor (com.infiniteautomation.mango.monitor.ValueMonitor)2 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)2 ValueMonitorModel (com.infiniteautomation.mango.rest.latest.model.ValueMonitorModel)2 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 ApiOperation (io.swagger.annotations.ApiOperation)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)1 Common (com.serotonin.m2m2.Common)1 ModuleRegistry (com.serotonin.m2m2.module.ModuleRegistry)1 SystemMetricsReadPermissionDefinition (com.serotonin.m2m2.module.definitions.permissions.SystemMetricsReadPermissionDefinition)1 User (com.serotonin.m2m2.vo.User)1 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)1 Api (io.swagger.annotations.Api)1 ApiParam (io.swagger.annotations.ApiParam)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Autowired (org.springframework.beans.factory.annotation.Autowired)1 AuthenticationPrincipal (org.springframework.security.core.annotation.AuthenticationPrincipal)1 PathVariable (org.springframework.web.bind.annotation.PathVariable)1