Search in sources :

Example 11 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method relinquish.

@ApiOperation(value = "Relinquish the value of a data point", notes = "Only BACnet data points allow this", response = Void.class)
@RequestMapping(method = RequestMethod.POST, value = "/relinquish/{xid}")
public void relinquish(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user, HttpServletRequest request) {
    DataPointVO dataPoint = service.get(xid);
    service.ensureReadPermission(user, dataPoint);
    DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    // Get the Data Source and Relinquish the point
    DataSourceRT<?> dsRt = null;
    try {
        dsRt = Common.runtimeManager.getRunningDataSource(rt.getDataSourceId());
    } catch (RTException e) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.dataSourceNotEnabled", xid));
    }
    dsRt.relinquish(rt);
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) RTException(com.serotonin.m2m2.rt.RTException) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 12 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class RuntimeManagerRestController method forceRefreshDataPoint.

@ApiOperation(value = "Force Refresh a data point", notes = "Not all data sources implement this feature", response = Void.class)
@RequestMapping(method = RequestMethod.PUT, value = "/force-refresh/{xid}")
public void forceRefreshDataPoint(@ApiParam(value = "Valid Data Point XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
    DataPointVO vo = service.get(xid);
    service.ensureReadPermission(user, vo);
    DataPointRT rt = Common.runtimeManager.getDataPoint(vo.getId());
    if (rt == null) {
        throw new TranslatableIllegalStateException(new TranslatableMessage("rest.error.pointNotEnabled", xid));
    }
    Common.runtimeManager.forcePointRead(vo.getId());
}
Also used : DataPointVO(com.serotonin.m2m2.vo.DataPointVO) DataPointRT(com.serotonin.m2m2.rt.dataImage.DataPointRT) TranslatableIllegalStateException(com.infiniteautomation.mango.util.exception.TranslatableIllegalStateException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 13 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class ServerRestController method acceptLicenseAgreement.

@ApiOperation(value = "Accept the current license agreement.", notes = "Only valid if the current license agreement has not been accepted.  If you do not accept, Mango will restart in 15 seconds, giving you a 2nd chance in case you change your mind.")
@ApiResponses({ @ApiResponse(code = 400, message = "License already accepted.") })
@RequestMapping(method = { RequestMethod.POST }, value = "/accept-license-agreement")
public void acceptLicenseAgreement(@ApiParam(value = "Agree or not", required = true, allowMultiple = false) @RequestParam Boolean agree, @AuthenticationPrincipal PermissionHolder user) {
    if (agree) {
        systemSettingsDao.setIntValue(SystemSettingsDao.LICENSE_AGREEMENT_VERSION, Common.getLicenseAgreementVersion());
    } else {
        if (Common.getLicenseAgreementVersion() == systemSettingsDao.getIntValue(SystemSettingsDao.LICENSE_AGREEMENT_VERSION))
            throw new BadRequestException(new TranslatableMessage("systemSettings.licenseAlreadyAgreed"));
        // Start shutdown timer
        log.error("Mango will restart in 15 seconds.");
        Providers.get(IMangoLifecycle.class).scheduleShutdown(15000L, true, user);
    }
}
Also used : BadRequestException(com.infiniteautomation.mango.rest.latest.exception.BadRequestException) TranslatableMessage(com.serotonin.m2m2.i18n.TranslatableMessage) IMangoLifecycle(com.serotonin.m2m2.IMangoLifecycle) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 14 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class PublishersWithoutPointsRestController method partialUpdate.

@ApiOperation(value = "Partially update a publisher, if points are supplied in model they will replace all existing points", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<AbstractPublisherModel<?, ?>> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated data source", required = true) @PatchVORequestBody(service = PublisherService.class, modelClass = AbstractPublisherModel.class) AbstractPublisherModel<?, ?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    PublisherVO vo = service.update(xid, model.toVO());
    URI location = builder.path("/publishers/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.OK);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 15 with PermissionHolder

use of com.serotonin.m2m2.vo.permission.PermissionHolder in project ma-modules-public by infiniteautomation.

the class PublishersWithoutPointsRestController method save.

@ApiOperation(value = "Save publisher, if points are supplied in model they will replace all existing points")
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<AbstractPublisherModel<?, ?>> save(@RequestBody(required = true) AbstractPublisherModel<?, ?> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder, HttpServletRequest request) {
    PublisherVO vo = this.service.insert(model.toVO());
    URI location = builder.path("/publishers/{xid}").buildAndExpand(new Object[] { vo.getXid() }).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) PublisherVO(com.serotonin.m2m2.vo.publish.PublisherVO) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

PermissionHolder (com.serotonin.m2m2.vo.permission.PermissionHolder)120 ApiOperation (io.swagger.annotations.ApiOperation)97 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)97 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)64 ResponseEntity (org.springframework.http.ResponseEntity)53 HttpHeaders (org.springframework.http.HttpHeaders)50 URI (java.net.URI)48 ArrayList (java.util.ArrayList)37 DataPointVO (com.serotonin.m2m2.vo.DataPointVO)34 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)29 List (java.util.List)27 User (com.serotonin.m2m2.vo.User)25 NotFoundException (com.infiniteautomation.mango.util.exception.NotFoundException)24 PermissionException (com.serotonin.m2m2.vo.permission.PermissionException)24 BadRequestException (com.infiniteautomation.mango.rest.latest.exception.BadRequestException)19 HashMap (java.util.HashMap)19 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)18 Common (com.serotonin.m2m2.Common)18 Collectors (java.util.stream.Collectors)17 Role (com.serotonin.m2m2.vo.role.Role)16