Search in sources :

Example 6 with JsonStreamedArray

use of com.serotonin.json.type.JsonStreamedArray in project ma-modules-public by infiniteautomation.

the class WatchListRestController 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<>();
    export.put(WatchListEmportDefinition.elementId, new StreamedSeroJsonVORqlQuery<>(service, rql, null, fieldMap, valueConverters));
    return export;
}
Also used : HashMap(java.util.HashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with JsonStreamedArray

use of com.serotonin.json.type.JsonStreamedArray 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)

Example 8 with JsonStreamedArray

use of com.serotonin.json.type.JsonStreamedArray in project ma-modules-public by infiniteautomation.

the class EventDetectorsRestController 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.hasAdminRole(user)) {
        export.put("eventDetectors", new StreamedSeroJsonVORqlQuery<>(service, rql, null, fieldMap, null));
    } else {
        export.put("eventDetectors", new StreamedSeroJsonVORqlQuery<>(service, rql, null, fieldMap, null, vo -> service.hasReadPermission(user, vo)));
    }
    return export;
}
Also used : BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) 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) Translations(com.serotonin.m2m2.i18n.Translations) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) RestModelMapper(com.infiniteautomation.mango.rest.latest.model.RestModelMapper) PatchVORequestBody(com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody) ActionAndModel(com.infiniteautomation.mango.rest.latest.model.ActionAndModel) ApiOperation(io.swagger.annotations.ApiOperation) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) Map(java.util.Map) URI(java.net.URI) PointEventDetectorRT(com.serotonin.m2m2.rt.event.detectors.PointEventDetectorRT) TemporaryResourceStatusUpdate(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResourceStatusUpdate) HttpHeaders(org.springframework.http.HttpHeaders) RQLUtils(com.infiniteautomation.mango.util.RQLUtils) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) Field(org.jooq.Field) Collectors(java.util.stream.Collectors) RestController(org.springframework.web.bind.annotation.RestController) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) List(java.util.List) StreamedSeroJsonVORqlQuery(com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery) ASTNode(net.jazdw.rql.parser.ASTNode) Environment(org.springframework.core.env.Environment) EventDetectors(com.infiniteautomation.mango.db.tables.EventDetectors) PermissionService(com.infiniteautomation.mango.spring.service.PermissionService) AbstractEventDetectorRTModel(com.infiniteautomation.mango.rest.latest.model.event.detectors.rt.AbstractEventDetectorRTModel) FilteredStreamWithTotal(com.infiniteautomation.mango.rest.latest.model.FilteredStreamWithTotal) VoAction(com.infiniteautomation.mango.rest.latest.bulk.VoAction) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) EventHandlerService(com.infiniteautomation.mango.spring.service.EventHandlerService) TemporaryResourceStatus(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.TemporaryResourceStatus) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) HashMap(java.util.HashMap) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) Function(java.util.function.Function) RequestBody(org.springframework.web.bind.annotation.RequestBody) EventDetectorsService(com.infiniteautomation.mango.spring.service.EventDetectorsService) HttpServletRequest(javax.servlet.http.HttpServletRequest) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) StreamedArrayWithTotal(com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal) AbstractEventDetectorModel(com.infiniteautomation.mango.rest.latest.model.event.detectors.AbstractEventDetectorModel) Api(io.swagger.annotations.Api) TemporaryResourceWebSocketHandler(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResourceWebSocketHandler) AbstractEventDetectorVO(com.serotonin.m2m2.vo.event.detector.AbstractEventDetectorVO) TemporaryResource(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource) MangoTaskTemporaryResourceManager(com.infiniteautomation.mango.rest.latest.temporaryResource.MangoTaskTemporaryResourceManager) Common(com.serotonin.m2m2.Common) BulkResponse(com.infiniteautomation.mango.rest.latest.bulk.BulkResponse) BulkRequest(com.infiniteautomation.mango.rest.latest.bulk.BulkRequest) HttpStatus(org.springframework.http.HttpStatus) VoIndividualRequest(com.infiniteautomation.mango.rest.latest.bulk.VoIndividualRequest) AuthenticationPrincipal(org.springframework.security.core.annotation.AuthenticationPrincipal) MediaTypes(com.serotonin.m2m2.web.MediaTypes) ResponseEntity(org.springframework.http.ResponseEntity) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException) TemporaryResourceManager(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResourceManager) VoIndividualResponse(com.infiniteautomation.mango.rest.latest.bulk.VoIndividualResponse) HashMap(java.util.HashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with JsonStreamedArray

use of com.serotonin.json.type.JsonStreamedArray in project ma-modules-public by infiniteautomation.

the class DataPointRestController 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<>();
    export.put("dataPoints", new StreamedSeroJsonVORqlQuery<>(service, rql, null, this.fieldMap, this.valueConverters));
    return export;
}
Also used : HashMap(java.util.HashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with JsonStreamedArray

use of com.serotonin.json.type.JsonStreamedArray in project ma-modules-public by infiniteautomation.

the class MailingListRestController 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<>();
    export.put("mailingLists", new StreamedSeroJsonVORqlQuery<>(service, rql, null, null, null));
    return export;
}
Also used : HashMap(java.util.HashMap) ASTNode(net.jazdw.rql.parser.ASTNode) JsonStreamedArray(com.serotonin.json.type.JsonStreamedArray) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

JsonStreamedArray (com.serotonin.json.type.JsonStreamedArray)10 ApiOperation (io.swagger.annotations.ApiOperation)10 HashMap (java.util.HashMap)10 ASTNode (net.jazdw.rql.parser.ASTNode)10 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)10 RestModelMapper (com.infiniteautomation.mango.rest.latest.model.RestModelMapper)4 StreamedArrayWithTotal (com.infiniteautomation.mango.rest.latest.model.StreamedArrayWithTotal)4 StreamedSeroJsonVORqlQuery (com.infiniteautomation.mango.rest.latest.model.StreamedSeroJsonVORqlQuery)4 StreamedVORqlQueryWithTotal (com.infiniteautomation.mango.rest.latest.model.StreamedVORqlQueryWithTotal)4 PatchVORequestBody (com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody)4 PermissionService (com.infiniteautomation.mango.spring.service.PermissionService)4 RQLUtils (com.infiniteautomation.mango.util.RQLUtils)4 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)4 MediaTypes (com.serotonin.m2m2.web.MediaTypes)4 Api (io.swagger.annotations.Api)4 ApiParam (io.swagger.annotations.ApiParam)4 URI (java.net.URI)4 LinkedHashMap (java.util.LinkedHashMap)4 Map (java.util.Map)4 BiFunction (java.util.function.BiFunction)4