Search in sources :

Example 16 with NotFoundRestException

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);
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) User(com.serotonin.m2m2.vo.User) BadRequestException(com.infiniteautomation.mango.rest.v2.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 17 with NotFoundRestException

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();
    });
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 18 with NotFoundRestException

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();
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 19 with NotFoundRestException

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);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) SystemActionTemporaryResource(com.infiniteautomation.mango.rest.v2.util.SystemActionTemporaryResource) URI(java.net.URI) Date(java.util.Date) SystemActionDefinition(com.serotonin.m2m2.module.SystemActionDefinition) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 20 with NotFoundRestException

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);
}
Also used : NotFoundRestException(com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException) ResponseEntity(org.springframework.http.ResponseEntity) VirtualSerialPortConfig(com.infiniteautomation.mango.io.serial.virtual.VirtualSerialPortConfig) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

NotFoundRestException (com.infiniteautomation.mango.rest.v2.exception.NotFoundRestException)35 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)31 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)31 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)19 ResponseEntity (org.springframework.http.ResponseEntity)17 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)12 GenericRestException (com.infiniteautomation.mango.rest.v2.exception.GenericRestException)6 File (java.io.File)6 URI (java.net.URI)6 User (com.serotonin.m2m2.vo.User)5 MultipartFile (org.springframework.web.multipart.MultipartFile)5 CommonsMultipartFile (org.springframework.web.multipart.commons.CommonsMultipartFile)5 BadRequestException (com.infiniteautomation.mango.rest.v2.exception.BadRequestException)4 DataPointModel (com.infiniteautomation.mango.rest.v2.model.dataPoint.DataPointModel)4 ArrayList (java.util.ArrayList)4 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)4 AccessDeniedException (com.infiniteautomation.mango.rest.v2.exception.AccessDeniedException)3 FileModel (com.infiniteautomation.mango.rest.v2.model.filestore.FileModel)3 FileStoreDefinition (com.serotonin.m2m2.module.FileStoreDefinition)3 AbstractPointEventDetectorVO (com.serotonin.m2m2.vo.event.detector.AbstractPointEventDetectorVO)3