Search in sources :

Example 1 with DataSourcePermissionsCheckCallback

use of com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method doQuery.

public StreamedArrayWithTotal doQuery(ASTNode rql, PermissionHolder user, Function<MaintenanceEventVO, Object> transformVO) {
    // If we are admin or have overall data source permission we can view all
    if (permissionService.hasPermission(user, dataSourcePermissionDefinition.getPermission())) {
        return new StreamedVORqlQueryWithTotal<>(service, rql, null, null, null, transformVO);
    } else {
        return new StreamedVORqlQueryWithTotal<>(service, rql, null, null, null, item -> {
            if (item.getDataPoints().size() > 0) {
                DataPointPermissionsCheckCallback callback = new DataPointPermissionsCheckCallback(user, true, permissionService, dataPointService);
                dao.getPoints(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            if (item.getDataSources().size() > 0) {
                DataSourcePermissionsCheckCallback callback = new DataSourcePermissionsCheckCallback(user, true, permissionService);
                dao.getDataSources(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            return true;
        }, transformVO);
    }
}
Also used : StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) DataPointPermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback) DataSourcePermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback)

Example 2 with DataSourcePermissionsCheckCallback

use of com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback in project ma-modules-public by infiniteautomation.

the class MaintenanceEventsRestController method exportQuery.

@ApiOperation(value = "Export formatted for Configuration Import by supplying an RQL query", notes = "User must have read permission")
@RequestMapping(method = RequestMethod.GET, value = "/export", produces = MediaTypes.SEROTONIN_JSON_VALUE)
public Map<String, JsonStreamedArray> exportQuery(HttpServletRequest request, @AuthenticationPrincipal PermissionHolder user) {
    ASTNode rql = RQLUtils.parseRQLtoAST(request.getQueryString());
    Map<String, JsonStreamedArray> export = new HashMap<>();
    if (permissionService.hasPermission(user, dataSourcePermissionDefinition.getPermission())) {
        export.put("maintenanceEvents", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
    } else {
        export.put("maintenanceEvents", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null, item -> {
            if (item.getDataPoints().size() > 0) {
                DataPointPermissionsCheckCallback callback = new DataPointPermissionsCheckCallback(user, true, permissionService, dataPointService);
                dao.getPoints(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            if (item.getDataSources().size() > 0) {
                DataSourcePermissionsCheckCallback callback = new DataSourcePermissionsCheckCallback(user, true, permissionService);
                dao.getDataSources(item.getId(), callback);
                if (!callback.hasPermission())
                    return false;
            }
            return true;
        }));
    }
    return export;
}
Also used : PathVariable(org.springframework.web.bind.annotation.PathVariable) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) RequestParam(org.springframework.web.bind.annotation.RequestParam) BiFunction(java.util.function.BiFunction) StreamedVORqlQueryWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal) Autowired(org.springframework.beans.factory.annotation.Autowired) ApiParam(io.swagger.annotations.ApiParam) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) RestModelMapper(com.infiniteautomation.mango.rest.latest.model.RestModelMapper) PatchVORequestBody(com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody) MaintenanceEventsService(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService) ApiOperation(io.swagger.annotations.ApiOperation) Map(java.util.Map) URI(java.net.URI) DataPointPermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback) HttpHeaders(org.springframework.http.HttpHeaders) RQLUtils(com.infiniteautomation.mango.util.RQLUtils) Set(java.util.Set) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) EventInstanceService(com.infiniteautomation.mango.spring.service.EventInstanceService) Field(org.jooq.Field) RestController(org.springframework.web.bind.annotation.RestController) EventQueryByMaintenanceEventRql(com.infiniteautomation.mango.rest.latest.model.EventQueryByMaintenanceEventRql) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) DataSourcePermissionDefinition(com.serotonin.m2m2.module.definitions.permissions.DataSourcePermissionDefinition) List(java.util.List) DataSourcePermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback) StreamedSeroJsonVORqlQuery(com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery) ASTNode(net.jazdw.rql.parser.ASTNode) EventTableRqlMappings(com.infiniteautomation.mango.rest.latest.EventsRestController.EventTableRqlMappings) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) EventQueryByMaintenanceCriteria(com.infiniteautomation.mango.rest.latest.model.EventQueryByMaintenanceCriteria) MaintenanceEventType(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventType) MaintenanceEventModel(com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel) MaintenanceEventVO(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventVO) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) Function(java.util.function.Function) Events(com.infiniteautomation.mango.db.tables.Events) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) RequestBody(org.springframework.web.bind.annotation.RequestBody) HttpServletRequest(javax.servlet.http.HttpServletRequest) StreamedArrayWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal) DataPointService(com.infiniteautomation.mango.spring.service.DataPointService) Api(io.swagger.annotations.Api) MaintenanceEventDao(com.serotonin.m2m2.maintenanceEvents.MaintenanceEventDao) EventInstanceVO(com.serotonin.m2m2.vo.event.EventInstanceVO) EventInstanceModel(com.infiniteautomation.mango.rest.latest.model.event.EventInstanceModel) Consumer(java.util.function.Consumer) HttpStatus(org.springframework.http.HttpStatus) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) MediaTypes(com.serotonin.m2m2.web.MediaTypes) ResponseEntity(org.springframework.http.ResponseEntity) StreamedArray(com.infiniteautomation.mango.rest.latest.model.StreamedArray) HashMap(java.util.HashMap) ASTNode(net.jazdw.rql.parser.ASTNode) DataPointPermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback) DataSourcePermissionsCheckCallback(com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

StreamedVORqlQueryWithTotal (com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal)2 DataPointPermissionsCheckCallback (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataPointPermissionsCheckCallback)2 DataSourcePermissionsCheckCallback (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService.DataSourcePermissionsCheckCallback)2 Events (com.infiniteautomation.mango.db.tables.Events)1 EventTableRqlMappings (com.infiniteautomation.mango.rest.latest.EventsRestController.EventTableRqlMappings)1 EventQueryByMaintenanceCriteria (com.infiniteautomation.mango.rest.latest.model.EventQueryByMaintenanceCriteria)1 EventQueryByMaintenanceEventRql (com.infiniteautomation.mango.rest.latest.model.EventQueryByMaintenanceEventRql)1 MaintenanceEventModel (com.infiniteautomation.mango.rest.latest.model.MaintenanceEventModel)1 RestModelMapper (com.infiniteautomation.mango.rest.latest.model.RestModelMapper)1 StreamedArray (com.infiniteautomation.mango.rest.latest.model.StreamedArray)1 StreamedArrayWithTotal (com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal)1 StreamedSeroJsonVORqlQuery (com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery)1 EventInstanceModel (com.infiniteautomation.mango.rest.latest.model.event.EventInstanceModel)1 PatchVORequestBody (com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody)1 DataPointService (com.infiniteautomation.mango.spring.service.DataPointService)1 EventInstanceService (com.infiniteautomation.mango.spring.service.EventInstanceService)1 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)1 MaintenanceEventsService (com.infiniteautomation.mango.spring.service.maintenanceEvents.MaintenanceEventsService)1 RQLUtils (com.infiniteautomation.mango.util.RQLUtils)1 JsonStreamedArray (com.serotonin.json.type.JsonStreamedArray)1