use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class PasswordResetController method sendEmail.
@ApiOperation(value = "Sends the user an email containing a password reset link")
@RequestMapping(method = RequestMethod.POST, value = "/send-email")
public ResponseEntity<Void> sendEmail(@RequestBody SendEmailRequestBody body) throws AddressException, TemplateException, IOException {
User user = UserDao.instance.getUser(body.getUsername());
if (user == null) {
throw new NotFoundRestException();
}
String email = body.getEmail();
if (email == null) {
throw new BadRequestException(new TranslatableMessage("rest.error.emailRequired"));
}
String providedEmail = email.toLowerCase(Locale.ROOT);
String userEmail = user.getEmail().toLowerCase(Locale.ROOT);
if (!providedEmail.equals(userEmail)) {
throw new BadRequestException(new TranslatableMessage("rest.error.incorrectEmail"));
}
if (user.isDisabled()) {
throw new BadRequestException(new TranslatableMessage("rest.error.userIsDisabled"));
}
passwordResetService.sendEmail(user);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method setTagsForDataPoint.
@ApiOperation(value = "Set data point tags by data point XID", notes = "User must have edit permission for the data point's data source")
@RequestMapping(method = RequestMethod.POST, value = "/point/{xid}")
public Map<String, String> setTagsForDataPoint(@ApiParam(value = "Data point XID", required = true, allowMultiple = false) @PathVariable String xid, @RequestBody Map<String, String> tags, @AuthenticationPrincipal User user) {
return DataPointTagsDao.instance.doInTransaction(txStatus -> {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
Permissions.ensureDataSourcePermission(user, dataPoint.getDataSourceId());
dataPoint.setTags(tags);
DataPointTagsDao.instance.saveDataPointTags(dataPoint);
return dataPoint.getTags();
});
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class DataPointTagsRestController method getTagsForDataPoint.
@ApiOperation(value = "Get data point tags by data point XID", notes = "User must have read permission for the data point")
@RequestMapping(method = RequestMethod.GET, value = "/point/{xid}")
public Map<String, String> getTagsForDataPoint(@ApiParam(value = "Data point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null) {
throw new NotFoundRestException();
}
Permissions.ensureDataPointReadPermission(user, dataPoint);
Map<String, String> tags = DataPointTagsDao.instance.getTagsForDataPointId(dataPoint.getId());
dataPoint.setTags(tags);
// we set the tags on the data point then retrieve them so that the device and name tags are removed
return dataPoint.getTags();
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class SystemActionRestV2Controller method performAction.
@ApiOperation(value = "Perform an Action", notes = "Kicks off action and returns temporary URL for status")
@ApiResponses({ @ApiResponse(code = 500, message = "Internal error", response = ResponseEntity.class), @ApiResponse(code = 404, message = "Not Found", response = ResponseEntity.class) })
@RequestMapping(method = RequestMethod.PUT, value = "/trigger/{action}")
public ResponseEntity<SystemActionTemporaryResource> performAction(@ApiParam(value = "Valid System Action", required = true, allowMultiple = false) @PathVariable String action, @ApiParam(value = "Input for task", required = false, allowMultiple = false) @RequestBody(required = false) JsonNode input, @AuthenticationPrincipal User user, UriComponentsBuilder builder) {
// Kick off action
SystemActionDefinition def = ModuleRegistry.getSystemActionDefinition(action);
if (def == null)
throw new NotFoundRestException();
String resourceId = resources.generateResourceId();
SystemActionTemporaryResource resource = new SystemActionTemporaryResource(resourceId, def.getTask(user, input), resources, new Date(System.currentTimeMillis() + 600000));
// Resource can live for up to 10 minutes (TODO Configurable?)
resources.put(resourceId, resource);
URI location = builder.path("/v2/actions/status/{resourceId}").buildAndExpand(resourceId).toUri();
HttpHeaders headers = new HttpHeaders();
headers.setLocation(location);
return new ResponseEntity<>(resource, headers, HttpStatus.OK);
}
use of com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException in project ma-modules-public by infiniteautomation.
the class VirtualSerialPortRestV2Controller method delete.
@PreAuthorize("isAdmin()")
@ApiOperation(value = "Delete virtual serial port", notes = "")
@RequestMapping(method = RequestMethod.DELETE, consumes = { "application/json", "application/sero-json" }, produces = { "application/json", "text/csv", "application/sero-json" }, value = { "/{xid}" })
public ResponseEntity<VirtualSerialPortConfig> delete(@ApiParam(value = "Valid Virtual serial port XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal User user, UriComponentsBuilder builder, HttpServletRequest request) {
// Check to see if it already exists
VirtualSerialPortConfig existing = VirtualSerialPortConfigDao.instance.getByXid(xid);
if (existing == null)
throw new NotFoundRestException();
// Ensure we set the xid
existing.setXid(xid);
// Save it
VirtualSerialPortConfigDao.instance.remove(existing);
return new ResponseEntity<>(existing, HttpStatus.OK);
}
Aggregations