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);
}
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);
}
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);
}
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());
}
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;
}
Aggregations