Search in sources :

Example 1 with WorkItemInfo

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;
    }
}
Also used : ValidationException(com.infiniteautomation.mango.util.exception.ValidationException) ProcessResult(com.serotonin.m2m2.i18n.ProcessResult) ArrayList(java.util.ArrayList) WorkItemInfo(com.infiniteautomation.mango.util.WorkItemInfo) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 2 with WorkItemInfo

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;
}
Also used : ArrayList(java.util.ArrayList) WorkItemInfo(com.infiniteautomation.mango.util.WorkItemInfo)

Example 3 with WorkItemInfo

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;
}
Also used : TimerTask(com.serotonin.timer.TimerTask) ArrayList(java.util.ArrayList) WorkItemInfo(com.infiniteautomation.mango.util.WorkItemInfo)

Example 4 with WorkItemInfo

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;
    }
}
Also used : ArrayList(java.util.ArrayList) WorkItemInfo(com.infiniteautomation.mango.util.WorkItemInfo) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with WorkItemInfo

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");
}
Also used : HashMap(java.util.HashMap) WorkItemInfo(com.infiniteautomation.mango.util.WorkItemInfo) RenderedPointValueTime(com.serotonin.m2m2.rt.dataImage.RenderedPointValueTime) UsedImagesDirective(com.serotonin.m2m2.email.UsedImagesDirective) Map(java.util.Map) HashMap(java.util.HashMap) EventInstanceWrapper(com.serotonin.m2m2.rt.script.EventInstanceWrapper) ApiOperation(io.swagger.annotations.ApiOperation) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

WorkItemInfo (com.infiniteautomation.mango.util.WorkItemInfo)6 ArrayList (java.util.ArrayList)5 ApiOperation (io.swagger.annotations.ApiOperation)3 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)3 UsedImagesDirective (com.serotonin.m2m2.email.UsedImagesDirective)2 RenderedPointValueTime (com.serotonin.m2m2.rt.dataImage.RenderedPointValueTime)2 EventInstanceWrapper (com.serotonin.m2m2.rt.script.EventInstanceWrapper)2 HashMap (java.util.HashMap)2 MangoJavaScriptService (com.infiniteautomation.mango.spring.service.MangoJavaScriptService)1 ValidationException (com.infiniteautomation.mango.util.exception.ValidationException)1 CompiledMangoJavaScript (com.infiniteautomation.mango.util.script.CompiledMangoJavaScript)1 MangoJavaScriptResult (com.infiniteautomation.mango.util.script.MangoJavaScriptResult)1 IntStringPair (com.serotonin.db.pair.IntStringPair)1 MangoEmailContent (com.serotonin.m2m2.email.MangoEmailContent)1 PostEmailRunnable (com.serotonin.m2m2.email.PostEmailRunnable)1 ProcessResult (com.serotonin.m2m2.i18n.ProcessResult)1 TranslatableMessage (com.serotonin.m2m2.i18n.TranslatableMessage)1 Translations (com.serotonin.m2m2.i18n.Translations)1 DataPointRT (com.serotonin.m2m2.rt.dataImage.DataPointRT)1 IDataPointValueSource (com.serotonin.m2m2.rt.dataImage.IDataPointValueSource)1