use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class DataPointEventsByWatchlistQueryDefinition method createQuery.
/* (non-Javadoc)
* @see com.serotonin.m2m2.module.ModuleQueryDefinition#createQuery(com.fasterxml.jackson.databind.JsonNode)
*/
@Override
public ASTNode createQuery(User user, JsonNode parameters) throws IOException {
// Lookup data points by watchlist
WatchListVO vo = WatchListDao.instance.getByXid(parameters.get("watchListXid").asText());
if (vo == null)
throw new NotFoundException();
if (!WatchListRestController.hasReadPermission(user, vo))
throw new PermissionException(new TranslatableMessage("common.default", "Unauthorized access"), user);
List<Object> args = new ArrayList<>();
args.add("typeRef1");
WatchListDao.instance.getPoints(vo.getId(), new MappedRowCallback<DataPointVO>() {
@Override
public void row(DataPointVO dp, int index) {
if (Permissions.hasDataPointReadPermission(user, dp)) {
args.add(Integer.toString(dp.getId()));
}
}
});
// Create Event Query for these Points
ASTNode query = new ASTNode("in", args);
query = addAndRestriction(query, new ASTNode("eq", "userId", user.getId()));
query = addAndRestriction(query, new ASTNode("eq", "typeName", "DATA_POINT"));
// TODO Should we force a limit if none is supplied?
if (parameters.has("limit")) {
int offset = 0;
int limit = parameters.get("limit").asInt();
if (parameters.has("offset"))
offset = parameters.get("offset").asInt();
query = addAndRestriction(query, new ASTNode("limit", limit, offset));
}
return query;
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class WatchListVO method validate.
public void validate(ProcessResult response) {
if (StringUtils.isBlank(name))
response.addMessage("name", new TranslatableMessage("validate.required"));
else if (StringValidation.isLengthGreaterThan(name, 50))
response.addMessage("name", new TranslatableMessage("validate.notLongerThan", 50));
if (StringUtils.isBlank(xid))
response.addMessage("xid", new TranslatableMessage("validate.required"));
else if (StringValidation.isLengthGreaterThan(xid, 50))
response.addMessage("xid", new TranslatableMessage("validate.notLongerThan", 50));
else if (!WatchListDao.instance.isXidUnique(xid, id))
response.addMessage("xid", new TranslatableMessage("validate.xidUsed"));
// Validate the points
UserDao dao = UserDao.instance;
User user = dao.getUser(userId);
if (user == null) {
response.addContextualMessage("userId", "watchlists.validate.userDNE");
}
// Using the owner of the report to validate against permissions if there is no current user
User currentUser = Common.getUser();
if (currentUser == null)
currentUser = user;
// Validate Points
for (DataPointVO vo : pointList) try {
Permissions.ensureDataPointReadPermission(user, vo);
} catch (PermissionException e) {
response.addContextualMessage("points", "watchlist.vaildate.pointNoReadPermission", vo.getXid());
}
// Validate the permissions
Permissions.validateAddedPermissions(this.readPermission, currentUser, response, "readPermission");
Permissions.validateAddedPermissions(this.editPermission, currentUser, response, "editPermission");
// TODO Validate new members
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class ModulesRestController method upgrade.
@ApiOperation(value = "Download Upgrades and optionally backup and restart", notes = "Use Modules web socket to track progress")
@RequestMapping(method = RequestMethod.POST, consumes = { "application/json" }, produces = { "application/json" }, value = "/upgrade")
public ResponseEntity<Void> upgrade(@ApiParam(value = "Perform Backup first", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean backup, @ApiParam(value = "Restart when completed", required = false, defaultValue = "false", allowMultiple = false) @RequestParam(required = false, defaultValue = "false") boolean restart, @ApiParam(value = "Desired Upgrades", required = true) @RequestBody(required = true) ModuleUpgradesModel model, UriComponentsBuilder builder, HttpServletRequest request) {
RestProcessResult<Void> result = new RestProcessResult<Void>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (user.isAdmin()) {
// Start Downloads
String status = ModulesDwr.startDownloads(model.fullModulesList(), backup, restart);
if (status == null) {
return result.createResponseEntity();
} else {
result.addRestMessage(HttpStatus.NOT_MODIFIED, new TranslatableMessage("common.default", status));
}
} else {
result.addRestMessage(this.getUnauthorizedMessage());
}
}
return result.createResponseEntity();
}
use of com.serotonin.m2m2.i18n.TranslatableMessage 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 User user, HttpServletRequest request) {
DataPointVO dataPoint = DataPointDao.instance.getByXid(xid);
if (dataPoint == null)
throw new NotFoundRestException();
Permissions.ensureDataPointReadPermission(user, dataPoint);
DataPointRT rt = Common.runtimeManager.getDataPoint(dataPoint.getId());
if (rt == null)
throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.pointNotEnabled", xid));
// Get the Data Source and Relinquish the point
DataSourceRT<?> dsRt = Common.runtimeManager.getRunningDataSource(rt.getDataSourceId());
if (dsRt == null)
throw new GenericRestException(HttpStatus.BAD_REQUEST, new TranslatableMessage("rest.error.dataSourceNotEnabled", xid));
dsRt.relinquish(rt);
}
use of com.serotonin.m2m2.i18n.TranslatableMessage in project ma-modules-public by infiniteautomation.
the class BackgroundProcessingRestController method setHighPrioritySettings.
@ApiOperation(value = "Update high priority queue settings", notes = "")
@RequestMapping(method = RequestMethod.PUT, produces = { "application/json" }, value = "/high-priority-thread-pool-settings")
public ResponseEntity<ThreadPoolSettingsModel> setHighPrioritySettings(@ApiParam(value = "Settings", required = true, allowMultiple = false) @RequestBody ThreadPoolSettingsModel model, HttpServletRequest request) throws RestValidationFailedException {
RestProcessResult<ThreadPoolSettingsModel> result = new RestProcessResult<ThreadPoolSettingsModel>(HttpStatus.OK);
User user = this.checkUser(request, result);
if (result.isOk()) {
if (Permissions.hasAdmin(user)) {
// Validate the settings
ThreadPoolExecutor executor = (ThreadPoolExecutor) Common.timer.getExecutorService();
int currentCorePoolSize = executor.getCorePoolSize();
int currentMaxPoolSize = executor.getMaximumPoolSize();
if ((model.getMaximumPoolSize() != null) && (model.getMaximumPoolSize() < BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN)) {
// Test to ensure we aren't setting too low
model.getMessages().add(new RestValidationMessage(new TranslatableMessage("validate.greaterThanOrEqualTo", BackgroundProcessing.HIGH_PRI_MAX_POOL_SIZE_MIN), RestMessageLevel.ERROR, "corePoolSize"));
result.addRestMessage(this.getValidationFailedError());
} else if (!validate(model, currentCorePoolSize, currentMaxPoolSize)) {
result.addRestMessage(this.getValidationFailedError());
} else {
if (model.getCorePoolSize() != null) {
executor.setCorePoolSize(model.getCorePoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.HIGH_PRI_CORE_POOL_SIZE, model.getCorePoolSize());
} else {
// Get the info for the user
int corePoolSize = executor.getCorePoolSize();
model.setCorePoolSize(corePoolSize);
}
if (model.getMaximumPoolSize() != null) {
executor.setMaximumPoolSize(model.getMaximumPoolSize());
SystemSettingsDao.instance.setIntValue(SystemSettingsDao.HIGH_PRI_MAX_POOL_SIZE, model.getMaximumPoolSize());
} else {
// Get the info for the user
int maximumPoolSize = executor.getMaximumPoolSize();
model.setMaximumPoolSize(maximumPoolSize);
}
// Get the settings for the model
int activeCount = executor.getActiveCount();
int largestPoolSize = executor.getLargestPoolSize();
model.setActiveCount(activeCount);
model.setLargestPoolSize(largestPoolSize);
}
return result.createResponseEntity(model);
} else {
LOG.warn("Non admin user: " + user.getUsername() + " attempted to set high priority thread pool settings.");
result.addRestMessage(this.getUnauthorizedMessage());
return result.createResponseEntity();
}
}
return result.createResponseEntity();
}
Aggregations