Search in sources :

Example 1 with TemporaryResource

use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.

the class EventDetectorsRestController method getBulkDataPointOperations.

@ApiOperation(value = "Get a list of current bulk event detector operations", notes = "User can only get their own bulk operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointOperations(ASTNode query, Translations translations) {
    List<TemporaryResource<EventDetectorBulkResponse, AbstractRestException>> preFiltered = this.bulkResourceManager.list();
    // hide result property by setting a view
    MappingJacksonValue resultWithView = new MappingJacksonValue(new FilteredStreamWithTotal<>(preFiltered, query, translations));
    resultWithView.setSerializationView(Object.class);
    return resultWithView;
}
Also used : TemporaryResource(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with TemporaryResource

use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.

the class DataPointTagsRestController method getBulkDataPointTagOperations.

@ApiOperation(value = "Get a list of current bulk tag operations", notes = "User can only get their own bulk tag operations unless they are an admin")
@RequestMapping(method = RequestMethod.GET, value = "/bulk")
public MappingJacksonValue getBulkDataPointTagOperations(ASTNode query, Translations translations) {
    List<TemporaryResource<TagBulkResponse, AbstractRestException>> preFiltered = this.bulkResourceManager.list();
    // hide result property by setting a view
    MappingJacksonValue resultWithView = new MappingJacksonValue(new FilteredStreamWithTotal<>(preFiltered, query, translations));
    resultWithView.setSerializationView(Object.class);
    return resultWithView;
}
Also used : TemporaryResource(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 3 with TemporaryResource

use of com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource in project ma-modules-public by infiniteautomation.

the class SystemActionTemporaryResourceManager method create.

/**
 * Create the task
 * @param permissionTypeName - To get from system settings
 */
public <T extends SystemActionResult> ResponseEntity<TemporaryResource<T, AbstractRestException>> create(SystemActionModel requestBody, PermissionHolder user, UriComponentsBuilder builder, String permissionTypeName, String resourceType, ResourceTask<SystemActionResult, AbstractRestException> task) {
    requestBody.ensureValid();
    Long expiration = requestBody.getExpiration();
    Long timeout = requestBody.getTimeout();
    if (permissionTypeName != null) {
        PermissionDefinition def = ModuleRegistry.getPermissionDefinition(permissionTypeName);
        if (def == null) {
            throw new NotFoundException();
        } else {
            service.ensurePermission(user, def.getPermission());
        }
    } else {
        service.ensureAdminRole(user);
    }
    @SuppressWarnings("unchecked") TemporaryResource<T, AbstractRestException> responseBody = (TemporaryResource<T, AbstractRestException>) resourceManager.newTemporaryResource(resourceType, null, expiration, timeout, task);
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/system-actions/status/{id}").buildAndExpand(responseBody.getId()).toUri());
    return new ResponseEntity<TemporaryResource<T, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) ResponseEntity(org.springframework.http.ResponseEntity) NotFoundException(com.infiniteautomation.mango.util.exception.NotFoundException) TemporaryResource(com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException)

Aggregations

TemporaryResource (com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource)3 ApiOperation (io.swagger.annotations.ApiOperation)2 MappingJacksonValue (org.springframework.http.converter.json.MappingJacksonValue)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 AbstractRestException (com.infiniteautomation.mango.rest.latest.exception.AbstractRestException)1 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)1 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1