Search in sources :

Example 26 with PermissionHolder

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

the class UserFileStoresRestController method getUserFileStoreModel.

@ApiOperation(value = "Get a user file store model")
@RequestMapping(method = RequestMethod.GET, value = "/{xid}")
public MappingJacksonValue getUserFileStoreModel(@PathVariable("xid") String xid, @AuthenticationPrincipal PermissionHolder user) {
    FileStore fs = this.fileStoreService.get(xid);
    // Seeing the permissions fields should require write protection
    MappingJacksonValue resultWithView = new MappingJacksonValue(new FileStoreModel(fs));
    if (fileStoreService.hasEditPermission(user, fs)) {
        resultWithView.setSerializationView(RoleViews.ShowRoles.class);
    } else {
        resultWithView.setSerializationView(Object.class);
    }
    return resultWithView;
}
Also used : FileStoreModel(com.infiniteautomation.mango.rest.latest.model.filestore.FileStoreModel) FileStore(com.serotonin.m2m2.vo.FileStore) MappingJacksonValue(org.springframework.http.converter.json.MappingJacksonValue) RoleViews(com.infiniteautomation.mango.rest.latest.model.RoleViews) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 27 with PermissionHolder

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

the class DataSourcesRestController method getRuntimeStatus.

@ApiOperation(value = "Get runtime status for data source", notes = "Only polling data sources have runtime status", response = RuntimeStatusModel.class)
@RequestMapping(method = RequestMethod.GET, value = "/status/{xid}")
public RuntimeStatusModel getRuntimeStatus(@ApiParam(value = "Valid Data Source XID", required = true, allowMultiple = false) @PathVariable String xid, @AuthenticationPrincipal PermissionHolder user) {
    DataSourceVO vo = service.get(xid);
    RuntimeStatusModel model = new RuntimeStatusModel();
    DataSourceRT<?> ds;
    try {
        ds = Common.runtimeManager.getRunningDataSource(vo.getId());
    } catch (RTException e) {
        return model;
    }
    model.setState(ds.getLifecycleState());
    model.setActiveEventTypes(ds.eventTypeStatus().entrySet().stream().filter(Entry::getValue).map(e -> new ActiveEventTypeModel(e.getKey().getDescription(), e.getKey().getAlarmLevel())).collect(Collectors.toList()));
    if (ds instanceof PollingDataSource) {
        List<LongLongPair> list = ((PollingDataSource<?>) ds).getLatestPollTimes();
        List<PollStatus> latestPolls = new ArrayList<>();
        for (LongLongPair poll : list) {
            latestPolls.add(new PollStatus(new Date(poll.getKey()), poll.getValue()));
        }
        model.setLatestPolls(latestPolls);
        List<PollStatus> latestAbortedPolls = new ArrayList<>();
        List<Long> aborted = ((PollingDataSource<?>) ds).getLatestAbortedPollTimes();
        for (Long poll : aborted) latestAbortedPolls.add(new PollStatus(new Date(poll), -1L));
        model.setLatestAbortedPolls(latestAbortedPolls);
    }
    return model;
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) LongLongPair(com.serotonin.db.pair.LongLongPair) PollStatus(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.PollStatus) RuntimeStatusModel(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel) ArrayList(java.util.ArrayList) Date(java.util.Date) RTException(com.serotonin.m2m2.rt.RTException) ActiveEventTypeModel(com.infiniteautomation.mango.rest.latest.model.datasource.RuntimeStatusModel.ActiveEventTypeModel) PollingDataSource(com.serotonin.m2m2.rt.dataSource.PollingDataSource) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 28 with PermissionHolder

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

the class DataSourcesRestController method copy.

@ApiOperation(value = "Copy data source", notes = "Copy the data source and its points with optional new XID and Name.")
@RequestMapping(method = RequestMethod.PUT, value = "/copy/{xid}")
public ResponseEntity<AbstractDataSourceModel<?>> copy(@PathVariable String xid, @ApiParam(value = "Copy's new XID", required = false, defaultValue = "null", allowMultiple = false) @RequestParam(required = false, defaultValue = "null") String copyXid, @ApiParam(value = "Copy's name", required = false, defaultValue = "null", allowMultiple = false) @RequestParam(required = false, defaultValue = "null") String copyName, @ApiParam(value = "Device name for copied points", required = false, defaultValue = "null", allowMultiple = false) @RequestParam(required = false, defaultValue = "null") String copyDeviceName, @ApiParam(value = "Enable/disabled state of data source", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean enabled, @ApiParam(value = "Copy data points", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean copyPoints, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    DataSourceVO copy = service.copy(xid, copyXid, copyName, copyDeviceName, enabled, copyPoints);
    URI location = builder.path("/data-sources/{xid}").buildAndExpand(copy.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(map.apply(copy, user), headers, HttpStatus.OK);
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 29 with PermissionHolder

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

the class DataSourcesRestController method partialUpdate.

@ApiOperation(value = "Partially update a data source", notes = "Requires edit permission")
@RequestMapping(method = RequestMethod.PATCH, value = "/{xid}")
public ResponseEntity<AbstractDataSourceModel<?>> partialUpdate(@PathVariable String xid, @ApiParam(value = "Updated data source", required = true) @PatchVORequestBody(service = DataSourceService.class, modelClass = AbstractDataSourceModel.class) AbstractDataSourceModel<? extends DataSourceVO> model, @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    DataSourceVO vo = service.update(xid, model.toVO());
    URI location = builder.path("/data-sources/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    return new ResponseEntity<>(map.apply(vo, user), headers, HttpStatus.OK);
}
Also used : DataSourceVO(com.serotonin.m2m2.vo.dataSource.DataSourceVO) HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) URI(java.net.URI) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 30 with PermissionHolder

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

the class EventHandlersRestController method create.

@ApiOperation(value = "Create an Event Handler", notes = "Requires global Event Handler privileges", response = AbstractEventHandlerModel.class)
@RequestMapping(method = RequestMethod.POST)
public ResponseEntity<AbstractEventHandlerModel<?>> create(@RequestBody AbstractEventHandlerModel<? extends AbstractEventHandlerVO> model, @ApiParam(value = "User", required = true) @AuthenticationPrincipal PermissionHolder user, UriComponentsBuilder builder) {
    AbstractEventHandlerVO vo = service.insert(modelMapper.unMap(model, AbstractEventHandlerVO.class, user));
    URI location = builder.path("/event-handlers/{xid}").buildAndExpand(vo.getXid()).toUri();
    HttpHeaders headers = new HttpHeaders();
    headers.setLocation(location);
    @SuppressWarnings("unchecked") AbstractEventHandlerModel<? extends AbstractEventHandlerVO> responseModel = modelMapper.map(vo, AbstractEventHandlerModel.class, user);
    return new ResponseEntity<>(responseModel, headers, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) ResponseEntity(org.springframework.http.ResponseEntity) AbstractEventHandlerVO(com.serotonin.m2m2.vo.event.AbstractEventHandlerVO) 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