Search in sources :

Example 6 with NotFoundRestException

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

the class VirtualSerialPortRestController method delete.

@PreAuthorize("isAdmin()")
@ApiOperation(value = "Delete virtual serial port", notes = "")
@RequestMapping(method = RequestMethod.DELETE, value = { "/{xid}" })
public ResponseEntity<VirtualSerialPortConfig> delete(@ApiParam(value = "Valid Virtual serial port XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder, HttpServletRequest request) {
    // Check to see if it already exists
    VirtualSerialPortConfig existing = VirtualSerialPortConfigDao.getInstance().getByXid(xid);
    if (existing == null)
        throw new NotFoundRestException();
    // Ensure we set the xid
    existing.setXid(xid);
    // Save it
    VirtualSerialPortConfigDao.getInstance().remove(existing);
    return new ResponseEntity<>(existing, HttpStatus.OK);
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) VirtualSerialPortConfig(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 7 with NotFoundRestException

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

the class VirtualSerialPortRestController method update.

@PreAuthorize("isAdmin()")
@ApiOperation(value = "Update virtual serial port", notes = "")
@RequestMapping(method = RequestMethod.PUT, 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 PermissionHolder user, UriComponentsBuilder builder, HttpServletRequest request) {
    // Check to see if it already exists
    VirtualSerialPortConfig existing = VirtualSerialPortConfigDao.getInstance().getByXid(model.getXid());
    if (existing == null)
        throw new NotFoundRestException();
    // Validate
    model.ensureValid();
    // Save it
    VirtualSerialPortConfigDao.getInstance().save(model);
    // Put a link to the updated data in the header
    URI location = builder.path("/virtual-serial-ports/{xid}").buildAndExpand(model.getXid()).toUri();
    return getResourceUpdated(model, location);
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) VirtualSerialPortConfig(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 8 with NotFoundRestException

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

the class PermissionsRestController method update.

@ApiOperation(value = "Update all of a Permission's Roles", notes = "If no roles are supplied then all existing assigned roles are removed")
@RequestMapping(method = RequestMethod.PUT, value = "/{name}")
public PermissionDefinitionModel update(@PathVariable String name, @ApiParam(value = "Permission", required = true) @RequestBody(required = true) PermissionDefinitionModel model) {
    PermissionDefinition def = ModuleRegistry.getPermissionDefinition(name);
    if (def == null) {
        throw new NotFoundRestException();
    }
    MangoPermission permission = model.getPermission() != null ? model.getPermission().getPermission() : null;
    service.update(permission, def);
    return new PermissionDefinitionModel(def);
}
Also used : PermissionDefinitionModel(com.infiniteautomation.mango.rest.latest.model.permissions.PermissionDefinitionModel) PermissionDefinition(com.serotonin.m2m2.module.PermissionDefinition) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) MangoPermission(com.infiniteautomation.mango.permission.MangoPermission) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 9 with NotFoundRestException

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

the class PointValueRestController method updatePointAttributes.

@ApiOperation(value = "Update point attributes, return all attributes after change", notes = "Data Point must be running and user must have write access")
@RequestMapping(method = RequestMethod.PUT, value = "/{xid}/attributes")
public ResponseEntity<Map<String, Object>> updatePointAttributes(@ApiParam(value = "Point xids", required = true) @PathVariable String xid, @RequestBody() Map<String, Object> attributes, @AuthenticationPrincipal PermissionHolder user) {
    DataPointVO vo = dataPointService.get(xid);
    dataPointService.ensureSetPermission(user, vo);
    DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getId());
    if (rt == null)
        throw new NotFoundRestException();
    for (Entry<String, Object> entry : attributes.entrySet()) {
        rt.setAttribute(entry.getKey(), entry.getValue());
    }
    return ResponseEntity.ok(rt.getAttributes());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 10 with NotFoundRestException

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

the class PointValueRestController method buildMap.

/**
 * Build and validate the map of Requested Data Points
 *
 * @return Map of series ids to data points
 */
protected Map<Integer, DataPointVO> buildMap(String[] xids, RollupEnum rollup) {
    if (xids == null)
        throw new BadRequestException(new TranslatableMessage("validate.invalidValueForField", "xids"));
    // Build the map, check permissions, we want this map ordered so our results are in order for csv output
    Map<Integer, DataPointVO> voMap = new LinkedHashMap<>();
    for (String xid : xids) {
        DataPointVO vo = dataPointService.get(xid);
        // Validate the rollup
        switch(vo.getPointLocator().getDataType()) {
            case ALPHANUMERIC:
            case BINARY:
            case MULTISTATE:
                if (!rollup.nonNumericSupport())
                    throw new BadRequestException(new TranslatableMessage("rest.validate.rollup.incompatible", rollup.toString(), xid));
                break;
            case NUMERIC:
                break;
        }
        voMap.put(vo.getSeriesId(), vo);
    }
    // Do we have any points
    if (voMap.isEmpty())
        throw new NotFoundRestException();
    return voMap;
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NotFoundRestException(com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException) BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

NotFoundRestException (com.infiniteautomation.mango.rest.latest.exception.NotFoundRestException)11 ApiOperation (io.swagger.annotations.ApiOperation)6 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)6 ResponseEntity (org.springframework.http.ResponseEntity)4 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)3 HttpHeaders (org.springframework.http.HttpHeaders)3 VirtualSerialPortConfig (com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig)2 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)2 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)2 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)2 URI (java.net.URI)2 Path (java.nio.file.Path)2 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)2 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 MangoPermission (com.infiniteautomation.mango.permission.MangoPermission)1 FileModel (com.infiniteautomation.mango.rest.latest.model.filestore.FileModel)1 PermissionDefinitionModel (com.infiniteautomation.mango.rest.latest.model.permissions.PermissionDefinitionModel)1 PatchVORequestBody (com.infiniteautomation.mango.rest.latest.patch.PatchVORequestBody)1