Search in sources :

Example 6 with VirtualSerialPortConfig

use of com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig in project ma-modules-public by infiniteautomation.

the class VirtualSerialPortRestV2Controller method update.

@PreAuthorize("isAdmin()")
@ApiOperation(value = "Update virtual serial port", notes = "")
@RequestMapping(method = RequestMethod.PUT, consumes = { "application/json", "application/sero-json" }, produces = { "application/json", "text/csv", "application/sero-json" }, value = { "/{xid}" })
public ResponseEntity<VirtualSerialPortConfig> update(@ApiParam(value = "Valid virtual serial port id", required = true, allowMultiple = false) @PathVariable String xid, @ApiParam(value = "Virtual Serial Port", required = true) @RequestBody(required = true) VirtualSerialPortConfig model, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
    // Check to see if it already exists
    VirtualSerialPortConfig existing = VirtualSerialPortConfigDao.instance.getByXid(model.getXid());
    if (existing == null)
        throw new NotFoundRestException();
    // Validate
    model.ensureValid();
    // Save it
    VirtualSerialPortConfigDao.instance.save(model);
    // Put a link to the updated data in the header
    URI location = builder.path("/v2/virtual-serial-ports/{xid}").buildAndExpand(model.getXid()).toUri();
    return getResourceUpdated(model, location);
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) VirtualSerialPortConfig(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig) URI(java.net.URI) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

VirtualSerialPortConfig (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)6 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)2 URI (java.net.URI)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 AlreadyExistsRestException (com.infiniteautomation.mango.rest.v2.exception.AlreadyExistsRestException)1 JsonException (com.serotonin.json.JsonException)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableJsonException (com.serotonin.m2m2.i18n.TranslatableJsonException)1 ModelNotFoundException (com.serotonin.m2m2.web.mvc.rest.v1.exception.ModelNotFoundException)1 LifecycleException (com.serotonin.util.LifecycleException)1 HashMap (java.util.HashMap)1 ResponseEntity (org.springframework.http.ResponseEntity)1