Search in sources :

Example 6 with AbstractRestException

use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.

the class RestExceptionIndividualResponse method exceptionCaught.

/**
 * Sets the http status and error fields from the exception
 */
public void exceptionCaught(Throwable exception) {
    AbstractRestException e = this.mapException(exception);
    this.setHttpStatus(e.getStatus().value());
    this.setError(e);
}
Also used : AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException)

Example 7 with AbstractRestException

use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.

the class EventDetectorsRestController method bulkEventDetectorOperation.

@ApiOperation(value = "Bulk get/create/update/delete event detectors", notes = "User must have read permission for the data point or edit permission for the data source")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<EventDetectorBulkResponse, AbstractRestException>> bulkEventDetectorOperation(@RequestBody EventDetectorBulkRequest requestBody, @ApiParam(value = "Restart the source to load in the changes", required = false, defaultValue = "true", allowMultiple = false) @RequestParam(required = false, defaultValue = "true") boolean restart, UriComponentsBuilder builder) {
    VoAction defaultAction = requestBody.getAction();
    AbstractEventDetectorModel<? extends AbstractEventDetectorVO> defaultBody = requestBody.getBody();
    List<EventDetectorIndividualRequest> requests = requestBody.getRequests();
    if (requests == null) {
        throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
    } else if (requests.isEmpty()) {
        throw new BadRequestException(new TranslatableMessage("rest.error.cantBeEmpty", "requests"));
    }
    String resourceId = requestBody.getId();
    Long expiration = requestBody.getExpiration();
    Long timeout = requestBody.getTimeout();
    TemporaryResource<EventDetectorBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_EVENT_DETECTOR, resourceId, expiration, timeout, (resource) -> {
        EventDetectorBulkResponse bulkResponse = new EventDetectorBulkResponse();
        int i = 0;
        resource.progressOrSuccess(bulkResponse, i++, requests.size());
        for (EventDetectorIndividualRequest request : requests) {
            UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
            EventDetectorIndividualResponse individualResponse = doIndividualRequest(request, restart, defaultAction, defaultBody, reqBuilder);
            bulkResponse.addResponse(individualResponse);
            resource.progressOrSuccess(bulkResponse, i++, requests.size());
        }
        return null;
    });
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/event-detectors/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
    return new ResponseEntity<TemporaryResource<EventDetectorBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) VoAction(com.infiniteautomation.mango.rest.latest.bulk.VoAction) ResponseEntity(org.springframework.http.ResponseEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with AbstractRestException

use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.

the class DataPointRestController method bulkDataPointOperation.

@ApiOperation(value = "Bulk get/create/update/delete data points", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestException>> bulkDataPointOperation(@RequestBody DataPointBulkRequest requestBody, UriComponentsBuilder builder) {
    VoAction defaultAction = requestBody.getAction();
    DataPointModel defaultBody = requestBody.getBody();
    List<DataPointIndividualRequest> requests = requestBody.getRequests();
    if (requests == null) {
        throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
    } else if (requests.isEmpty()) {
        throw new BadRequestException(new TranslatableMessage("rest.error.cantBeEmpty", "requests"));
    }
    String resourceId = requestBody.getId();
    Long expiration = requestBody.getExpiration();
    Long timeout = requestBody.getTimeout();
    TemporaryResource<DataPointBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT, resourceId, expiration, timeout, (resource) -> {
        DataPointBulkResponse bulkResponse = new DataPointBulkResponse();
        int i = 0;
        resource.progressOrSuccess(bulkResponse, i++, requests.size());
        PermissionHolder resourceUser = Common.getUser();
        for (DataPointIndividualRequest request : requests) {
            UriComponentsBuilder reqBuilder = UriComponentsBuilder.newInstance();
            DataPointIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody, resourceUser, reqBuilder);
            bulkResponse.addResponse(individualResponse);
            resource.progressOrSuccess(bulkResponse, i++, requests.size());
        }
        return null;
    });
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/data-points/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
    return new ResponseEntity<TemporaryResource<DataPointBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) VoAction(com.infiniteautomation.mango.rest.latest.bulk.VoAction) DataPointModel(com.infiniteautomation.mango.rest.latest.model.dataPoint.DataPointModel) PermissionHolder(com.serotonin.m2m2.vo.permission.PermissionHolder) ResponseEntity(org.springframework.http.ResponseEntity) UriComponentsBuilder(org.springframework.web.util.UriComponentsBuilder) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with AbstractRestException

use of com.infiniteautomation.mango.rest.latest.exception.AbstractRestException in project ma-modules-public by infiniteautomation.

the class DataPointTagsRestController method bulkDataPointTagOperation.

@ApiOperation(value = "Bulk get/set/add data point tags for a list of XIDs", notes = "User must have read/edit permission for the data point")
@RequestMapping(method = RequestMethod.POST, value = "/bulk")
public ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestException>> bulkDataPointTagOperation(@RequestBody TagBulkRequest requestBody, UriComponentsBuilder builder) {
    BulkTagAction defaultAction = requestBody.getAction();
    Map<String, String> defaultBody = requestBody.getBody();
    List<TagIndividualRequest> requests = requestBody.getRequests();
    if (requests == null) {
        throw new BadRequestException(new TranslatableMessage("rest.error.mustNotBeNull", "requests"));
    }
    String resourceId = requestBody.getId();
    Long expiration = requestBody.getExpiration();
    Long timeout = requestBody.getTimeout();
    TemporaryResource<TagBulkResponse, AbstractRestException> responseBody = bulkResourceManager.newTemporaryResource(RESOURCE_TYPE_BULK_DATA_POINT_TAGS, resourceId, expiration, timeout, (resource) -> {
        TagBulkResponse bulkResponse = new TagBulkResponse();
        int i = 0;
        resource.progress(bulkResponse, i++, requests.size());
        for (TagIndividualRequest request : requests) {
            TagIndividualResponse individualResponse = doIndividualRequest(request, defaultAction, defaultBody);
            bulkResponse.addResponse(individualResponse);
            resource.progressOrSuccess(bulkResponse, i++, requests.size());
        }
        return null;
    });
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(builder.path("/data-point-tags/bulk/{id}").buildAndExpand(responseBody.getId()).toUri());
    return new ResponseEntity<TemporaryResource<TagBulkResponse, AbstractRestException>>(responseBody, headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) AbstractRestException(com.infiniteautomation.mango.rest.latest.exception.AbstractRestException) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

AbstractRestException (com.infiniteautomation.mango.rest.latest.exception.AbstractRestException)9 HttpHeaders (org.springframework.http.HttpHeaders)7 ResponseEntity (org.springframework.http.ResponseEntity)7 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)6 ApiOperation (io.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)5 VoAction (com.infiniteautomation.mango.rest.latest.bulk.VoAction)4 UriComponentsBuilder (org.springframework.web.util.UriComponentsBuilder)4 PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)3 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)2 ServerErrorException (com.infiniteautomation.mango.rest.latest.exception.ServerErrorException)1 DataPointModel (com.infiniteautomation.mango.rest.latest.model.dataPoint.DataPointModel)1 PurgePointValuesResponseModel (com.infiniteautomation.mango.rest.latest.model.pointValue.PurgePointValuesResponseModel)1 UserIndividualRequest (com.infiniteautomation.mango.rest.latest.model.user.UserIndividualRequest)1 UserIndividualResponse (com.infiniteautomation.mango.rest.latest.model.user.UserIndividualResponse)1 UserModel (com.infiniteautomation.mango.rest.latest.model.user.UserModel)1 TemporaryResource (com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource)1 StatusUpdateException (com.infiniteautomation.mango.rest.latest.temporaryResource.TemporaryResource.StatusUpdateException)1 PermissionDefinition (com.serotonin.m2m2.module.PermissionDefinition)1