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