use of com.infiniteautomation.mango.util.WorkItemInfo in project ma-modules-public by infiniteautomation.
the class WorkItemRestController method getWorkItemsByPriority.
@ApiOperation(value = "Get list of work items by classname", notes = "Returns the Work Item specified by the given classname and priority")
@RequestMapping(method = RequestMethod.GET, value = "/by-priority/{priority}")
public List<WorkItemInfo> getWorkItemsByPriority(@ApiParam(value = "priority", required = true, allowMultiple = false) @PathVariable String priority, @RequestParam(value = "classname", required = false, defaultValue = "") String classname, @AuthenticationPrincipal PermissionHolder user) {
permissionService.ensureAdminRole(user);
List<WorkItemInfo> list;
if (priority.equalsIgnoreCase("HIGH")) {
list = Common.backgroundProcessing.getHighPriorityServiceItems();
} else if (priority.equalsIgnoreCase("MEDIUM")) {
list = Common.backgroundProcessing.getMediumPriorityServiceQueueItems();
} else if (priority.equalsIgnoreCase("LOW")) {
list = Common.backgroundProcessing.getLowPriorityServiceQueueItems();
} else {
ProcessResult result = new ProcessResult();
result.addContextualMessage("priority", "validate.invalidValue");
throw new ValidationException(result);
}
// Filter if we need to
if (StringUtils.isNotEmpty(classname)) {
List<WorkItemInfo> modelList = new ArrayList<>();
for (WorkItemInfo model : list) {
if (model.getClassname().equalsIgnoreCase(classname)) {
modelList.add(model);
}
}
return modelList;
} else {
return list;
}
}
use of com.infiniteautomation.mango.util.WorkItemInfo in project ma-core-public by infiniteautomation.
the class BackgroundProcessingImpl method getQueueItems.
private List<WorkItemInfo> getQueueItems(ThreadPoolExecutor e, String priority) {
List<WorkItemInfo> list = new ArrayList<WorkItemInfo>();
Iterator<Runnable> iter = e.getQueue().iterator();
while (iter.hasNext()) {
Runnable r = iter.next();
WorkItemRunnable wir = (WorkItemRunnable) r;
list.add(new WorkItemInfo(wir.getWorkItem().getClass().getCanonicalName(), wir.getWorkItem().getDescription(), priority));
}
return list;
}
use of com.infiniteautomation.mango.util.WorkItemInfo in project ma-core-public by infiniteautomation.
the class BackgroundProcessingImpl method getHighPriorityServiceItems.
@Override
public List<WorkItemInfo> getHighPriorityServiceItems() {
List<WorkItemInfo> list = new ArrayList<WorkItemInfo>();
Iterator<TimerTask> iter = timer.getTasks().iterator();
while (iter.hasNext()) {
TimerTask task = iter.next();
list.add(new WorkItemInfo(task.getClass().getCanonicalName(), task.getName(), "HIGH"));
}
return list;
}
use of com.infiniteautomation.mango.util.WorkItemInfo in project ma-modules-public by infiniteautomation.
the class WorkItemRestController method getAll.
@ApiOperation(value = "Get all work items", notes = "Returns a list of all work items, optionally filterable on classname")
@RequestMapping(method = RequestMethod.GET)
public List<WorkItemInfo> getAll(@RequestParam(value = "classname", required = false, defaultValue = "") String classname, @AuthenticationPrincipal PermissionHolder user) {
permissionService.ensureAdminRole(user);
List<WorkItemInfo> modelList = new ArrayList<>();
modelList.addAll(Common.backgroundProcessing.getHighPriorityServiceItems());
modelList.addAll(Common.backgroundProcessing.getMediumPriorityServiceQueueItems());
modelList.addAll(Common.backgroundProcessing.getLowPriorityServiceQueueItems());
if (StringUtils.isNotEmpty(classname)) {
List<WorkItemInfo> filteredList = new ArrayList<>();
for (WorkItemInfo model : modelList) {
if (model.getClassname().equalsIgnoreCase(classname)) {
filteredList.add(model);
}
}
return filteredList;
} else {
return modelList;
}
}
use of com.infiniteautomation.mango.util.WorkItemInfo in project ma-modules-public by infiniteautomation.
the class EventHandlersRestController method validateEmailHandlerScript.
@ApiOperation(value = "Validate an email event handler script", notes = "Admin Only")
@RequestMapping(method = RequestMethod.POST, value = "/validate-email-handler-script")
public MangoJavaScriptResultModel validateEmailHandlerScript(@RequestBody MangoJavaScriptModel model) throws IOException, EncryptedDocumentException, InvalidFormatException {
// Add in the additional validation context
if (model.getAdditionalContext() == null) {
model.setAdditionalContext(new HashMap<>());
}
model.getAdditionalContext().putIfAbsent(EmailHandlerRT.DO_NOT_SEND_KEY, MangoJavaScriptService.UNCHANGED);
// Setup the email ftl model
Map<String, Object> emailModel = new HashMap<>();
emailModel.put(EventInstance.CONTEXT_KEY, new ValidationEventInstance());
emailModel.put(EventInstanceWrapper.CONTEXT_KEY, new EventInstanceWrapper(new ValidationEventInstance()));
emailModel.put("additionalContext", new HashMap<>());
emailModel.put("renderedPointValues", new ArrayList<RenderedPointValueTime>());
emailModel.put("renderedHtmlPointValues", new ArrayList<RenderedPointValueTime>());
emailModel.put("img", new UsedImagesDirective());
emailModel.put("instanceDescription", SystemSettingsDao.getInstance().getValue(SystemSettingsDao.INSTANCE_DESCRIPTION));
// Get the Work Items
List<WorkItemInfo> highPriorityWorkItems = Common.backgroundProcessing.getHighPriorityServiceItems();
emailModel.put("highPriorityWorkItems", highPriorityWorkItems);
List<WorkItemInfo> mediumPriorityWorkItems = Common.backgroundProcessing.getMediumPriorityServiceQueueItems();
emailModel.put("mediumPriorityWorkItems", mediumPriorityWorkItems);
List<WorkItemInfo> lowPriorityWorkItems = Common.backgroundProcessing.getLowPriorityServiceQueueItems();
emailModel.put("lowPriorityWorkItems", lowPriorityWorkItems);
emailModel.put("threadList", new ArrayList<Map<String, Object>>());
model.getAdditionalContext().putIfAbsent("model", emailModel);
return validateScript(model, "eventHandlers.script.successNoEmail");
}
Aggregations