use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class SystemMetricsRestController method query.
@ApiOperation(value = "Get the current value for all System Metrics", notes = "TBD Add RQL Support to this endpoint")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<ValueMonitor<?>>> query(HttpServletRequest request) {
RestProcessResult<List<ValueMonitor<?>>> result = new RestProcessResult<List<ValueMonitor<?>>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
// Check Permissions
String permissions = SystemSettingsDao.getValue(internalMetricsPermission);
if (Permissions.hasPermission(user, permissions)) {
return result.createResponseEntity(Common.MONITORED_VALUES.getMonitors());
} else {
result.addRestMessage(getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class SystemMetricsRestController method get.
@ApiOperation(value = "Get the current value for one System Metric by its ID", notes = "")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" }, value = "/{id}")
public ResponseEntity<ValueMonitor<?>> get(@ApiParam(value = "Valid Monitor id", required = true, allowMultiple = false) @PathVariable String id, HttpServletRequest request) {
RestProcessResult<ValueMonitor<?>> result = new RestProcessResult<ValueMonitor<?>>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
// Check Permissions
String permissions = SystemSettingsDao.getValue(internalMetricsPermission);
if (Permissions.hasPermission(user, permissions)) {
List<ValueMonitor<?>> values = Common.MONITORED_VALUES.getMonitors();
ValueMonitor<?> value = null;
for (ValueMonitor<?> v : values) {
if (v.getId().equals(id)) {
value = v;
break;
}
}
if (value != null)
return result.createResponseEntity(value);
else {
result.addRestMessage(getDoesNotExistMessage());
}
} else {
result.addRestMessage(getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class ThreadMonitorRestController method getThreads.
@ApiOperation(value = "Get all threads", notes = "Larger stack depth will slow this request")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json" })
public ResponseEntity<List<ThreadModel>> getThreads(HttpServletRequest request, @ApiParam(value = "Limit size of stack trace", allowMultiple = false, defaultValue = "10") @RequestParam(value = "stackDepth", defaultValue = "10") int stackDepth, @ApiParam(value = "Return as file", allowMultiple = false, defaultValue = "false") @RequestParam(value = "asFile", defaultValue = "false") boolean asFile, @ApiParam(value = "Order by this member", allowMultiple = false, required = false) @RequestParam(value = "orderBy", required = false) String orderBy) {
RestProcessResult<List<ThreadModel>> result = new RestProcessResult<List<ThreadModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
List<ThreadModel> models = new ArrayList<ThreadModel>();
Thread[] allThreads = this.getAllThreads();
ThreadMXBean manager = ManagementFactory.getThreadMXBean();
for (Thread t : allThreads) {
ThreadInfo info = manager.getThreadInfo(t.getId(), stackDepth);
ThreadModel model;
if (info != null)
model = new ThreadModel(t.getId(), t.getPriority(), t.getName(), info, manager.getThreadCpuTime(t.getId()), manager.getThreadUserTime(t.getId()));
else
model = new ThreadModel(t.getId(), t.getPriority(), t.getName(), manager.getThreadCpuTime(t.getId()), manager.getThreadUserTime(t.getId()));
models.add(model);
}
// Do we need to order this list?
if (orderBy != null) {
// Determine what to order by
final ThreadModelProperty orderProperty = ThreadModelProperty.convert(orderBy);
Collections.sort(models, new Comparator<ThreadModel>() {
@Override
public int compare(ThreadModel left, ThreadModel right) {
switch(orderProperty) {
case PRIORITY:
return left.getPriority() - right.getPriority();
case NAME:
return left.getName().compareTo(right.getName());
case CPU_TIME:
if (left.getCpuTime() > right.getCpuTime())
return 1;
else if ((left.getCpuTime() < right.getCpuTime()))
return -1;
else
return 0;
case USER_TIME:
if (left.getUserTime() > right.getUserTime())
return 1;
else if ((left.getUserTime() < right.getUserTime()))
return -1;
else
return 0;
case STATE:
return left.getState().compareTo(right.getState());
case LOCATION:
case ID:
default:
return (int) (left.getId() - right.getId());
}
}
});
}
if (asFile) {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss_'threads.json'");
String filename = sdf.format(new Date());
result.addHeader("Content-Disposition", "inline;filename=" + filename);
return result.createResponseEntity(models, MediaType.APPLICATION_OCTET_STREAM);
} else
return result.createResponseEntity(models);
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class UserAccessRestController method getDataSourceAccess.
@ApiOperation(value = "Get Data Source Access List", notes = "Returns a list of users and thier access")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/data-source/{xid}")
public ResponseEntity<List<UserAccessModel>> getDataSourceAccess(@ApiParam(value = "Valid data point xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<UserAccessModel>> result = new RestProcessResult<List<UserAccessModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
DataSourceVO<?> vo = DataSourceDao.instance.getByXid(xid);
if (vo != null) {
List<UserAccessModel> models = new ArrayList<UserAccessModel>();
List<User> allUsers = UserDao.instance.getUsers();
for (User mangoUser : allUsers) {
if (Permissions.hasDataSourcePermission(mangoUser, vo)) {
models.add(new UserAccessModel(Permissions.ACCESS_TYPE_CODES.getCode(DataPointAccessTypes.DATA_SOURCE), new UserModel(mangoUser)));
}
}
return result.createResponseEntity(models);
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.web.mvc.rest.v1.message.RestProcessResult in project ma-modules-public by infiniteautomation.
the class UserAccessRestController method getDataPointAccess.
@ApiOperation(value = "Get Data Point Access List", notes = "Returns a list of users and thier access")
@RequestMapping(method = RequestMethod.GET, produces = { "application/json", "text/csv" }, value = "/data-point/{xid}")
public ResponseEntity<List<UserAccessModel>> getDataPointAccess(@ApiParam(value = "Valid data point xid", required = true, allowMultiple = false) @PathVariable String xid, HttpServletRequest request) {
RestProcessResult<List<UserAccessModel>> result = new RestProcessResult<List<UserAccessModel>>(HttpStatus.OK);
this.checkUser(request, result);
if (result.isOk()) {
DataPointVO vo = DataPointDao.instance.getByXid(xid);
if (vo != null) {
List<UserAccessModel> models = new ArrayList<UserAccessModel>();
List<User> allUsers = UserDao.instance.getUsers();
int accessType;
for (User mangoUser : allUsers) {
accessType = Permissions.getDataPointAccessType(mangoUser, vo);
if (accessType != Permissions.DataPointAccessTypes.NONE) {
models.add(new UserAccessModel(Permissions.ACCESS_TYPE_CODES.getCode(accessType), new UserModel(mangoUser)));
}
}
return result.createResponseEntity(models);
}
}
return result.createResponseEntity();
}
Aggregations