Java Code Examples for org.kie.api.runtime.process.WorkItemManager#completeWorkItem()
The following examples show how to use
org.kie.api.runtime.process.WorkItemManager#completeWorkItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AddCalendarWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<String, Object>(); String paramCalendarSummary = (String) workItem.getParameter("CalendarSummary"); try { RequiredParameterValidator.validate(this.getClass(), workItem); com.google.api.services.calendar.Calendar client = auth.getAuthorizedCalendar(appName, clientSecret); results.put(RESULTS_CALENDAR, addCalendar(client, paramCalendarSummary)); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 2
Source File: StartContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerId = (String) workItem.getParameter("ContainerId"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } dockerClient.startContainerCmd(containerId).exec(); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { logger.error("Unable to start container: " + e.getMessage()); handleException(e); } }
Example 3
Source File: StopContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerId = (String) workItem.getParameter("ContainerId"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } dockerClient.stopContainerCmd(containerId).exec(); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { logger.error("Unable to stop container: " + e.getMessage()); handleException(e); } }
Example 4
Source File: GetEventsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 6 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String paramCalendarSummary = (String) workItem.getParameter("CalendarSummary"); Map<String, Object> results = new HashMap<String, Object>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); Calendar client = auth.getAuthorizedCalendar(appName, clientSecret); results.put(RESULTS_ALL_EVENTS, getAllEvents(client, getCalendarIdBySummary(client, paramCalendarSummary))); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 5
Source File: GetUsersWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String userids = (String) workItem.getParameter("UserIds"); List<OktaUser> retUserList = new ArrayList<>(); UserList userList = oktaClient.listUsers(); if (userids != null && userids.length() > 0) { List<String> useridsList = Arrays.asList(userids.split(",")); userList.stream() .filter(usr -> useridsList.contains(usr.getId())) .forEach(usr -> retUserList.add(new OktaUser(usr))); } else { // get all userList.stream().forEach(usr -> retUserList.add(new OktaUser(usr))); } Map<String, Object> results = new HashMap<>(); results.put(RESULTS_VALUE, retUserList); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 6
Source File: KafkaWorkItemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<String, Object>(); String topic = (String) workItem.getParameter("Topic"); String key = (String) workItem.getParameter("Key"); String value = (String) workItem.getParameter("Value"); try { producer.send(new ProducerRecord(topic, key, value)); results.put(RESULTS_VALUE, "success"); manager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { LOG.error("Kafka error", e); producer.flush(); results.put(RESULTS_VALUE, "failure"); } } catch (Exception exp) { LOG.error("Handler error", exp); handleException(exp); } }
Example 7
Source File: TranslateWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String toTranslate = (String) workItem.getParameter("ToTranslate"); String sourceLang = (String) workItem.getParameter("SourceLang"); String targetLang = (String) workItem.getParameter("TargetLang"); Map<String, Object> results = new HashMap<String, Object>(); translationService = googleTranslateAuth.getTranslationService(apiKey); TranslateOption srcLangOption = TranslateOption.sourceLanguage(sourceLang); TranslateOption targetLangOption = TranslateOption.targetLanguage(targetLang); Translation translation = translationService.translate(toTranslate, srcLangOption, targetLangOption); if (translation != null && translation.getTranslatedText() != null) { results.put(RESULTS_TRANSLATION, translation.getTranslatedText()); } else { logger.error("Could not translate provided text."); throw new IllegalArgumentException("Could not translate provided text."); } workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Error executing workitem: " + e.getMessage()); handleException(e); } }
Example 8
Source File: CreateGistWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Document content = (Document) workItem.getParameter("Content"); String description = (String) workItem.getParameter("Description"); String isPublicStr = (String) workItem.getParameter("IsPublic"); Map<String, Object> results = new HashMap<String, Object>(); GistService gistService = auth.getGistService(this.userName, this.password); Gist gist = new Gist(); gist.setPublic(Boolean.parseBoolean(isPublicStr)); gist.setDescription(description); GistFile file = new GistFile(); file.setContent(new String(content.getContent(), StandardCharsets.UTF_8)); file.setFilename(content.getName()); gist.setFiles(Collections.singletonMap(file.getFilename(), file)); gist = gistService.createGist(gist); results.put(RESULTS_VALUE, gist.getHtmlUrl()); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 9
Source File: AddTaskWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String taskName = (String) workItem.getParameter("TaskName"); String taskKind = (String) workItem.getParameter("TaskKind"); try { RequiredParameterValidator.validate(this.getClass(), workItem); Tasks service = auth.getTasksService(appName, clientSecret); TaskList taskList = new TaskList(); taskList.setTitle(taskName); taskList.setId(taskName); taskList.setKind(taskKind); taskList.setUpdated(new DateTime(new Date())); service.tasklists().insert(taskList).execute(); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { handleException(e); } }
Example 10
Source File: ListImagesWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); String showAll = (String) workItem.getParameter("ShowAll"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } ListImagesCmd listImagesCmd = dockerClient.listImagesCmd(); if (showAll != null && Boolean.parseBoolean(showAll)) { listImagesCmd = listImagesCmd.withShowAll(true); } List<Image> images = listImagesCmd.exec(); results.put(RESULTS_DOCUMENT, images); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Unable to get list of containers: " + e.getMessage()); handleException(e); } }
Example 11
Source File: GetApplicationsWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String appids = (String) workItem.getParameter("AppIds"); List<OktaApplication> retAppList = new ArrayList<>(); ApplicationList appList = oktaClient.listApplications(); if (appids != null && appids.length() > 0) { List<String> appidsList = Arrays.asList(appids.split(",")); appList.stream() .filter(app -> appidsList.contains(app.getId())) .forEach(app -> retAppList.add(new OktaApplication(app))); } else { // get all appList.stream().forEach(app -> retAppList.add(new OktaApplication(app))); } Map<String, Object> results = new HashMap<>(); results.put(RESULTS_VALUE, retAppList); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 12
Source File: SendDirectMessageWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 5 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { String message = (String) workItem.getParameter("Message"); String screenName = (String) workItem.getParameter("ScreenName"); // debug is optional (default to false) boolean debugOption = false; if (workItem.getParameter("DebugEnabled") != null) { debugOption = Boolean.parseBoolean((String) workItem.getParameter("DebugEnabled")); } try { RequiredParameterValidator.validate(this.getClass(), workItem); Twitter twitter = auth.getTwitterService(this.consumerKey, this.consumerSecret, this.accessKey, this.accessSecret, debugOption); directMessage = twitter.sendDirectMessage(screenName, message); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { handleException(e); } }
Example 13
Source File: UpdateStatusWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String statusMessage = (String) workItem.getParameter("StatusUpdate"); // media is optional Document statusMedia = null; if (workItem.getParameter("Media") != null) { statusMedia = (Document) workItem.getParameter("Media"); } // debug is optional (default to false) boolean debugOption = false; if (workItem.getParameter("DebugEnabled") != null) { debugOption = Boolean.parseBoolean((String) workItem.getParameter("DebugEnabled")); } Twitter twitter = auth.getTwitterService(this.consumerKey, this.consumerSecret, this.accessKey, this.accessSecret, debugOption); statusUpdate = new StatusUpdate(statusMessage); if (statusMedia != null) { statusUpdate.setMedia(FilenameUtils.getBaseName(statusMedia.getName()) + "." + FilenameUtils.getExtension(statusMedia.getName()), new ByteArrayInputStream(statusMedia.getContent())); } twitter.updateStatus(statusUpdate); workItemManager.completeWorkItem(workItem.getId(), null); } catch (Exception e) { handleException(e); } }
Example 14
Source File: CreateContainerWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { Map<String, Object> results = new HashMap<String, Object>(); try { RequiredParameterValidator.validate(this.getClass(), workItem); String containerName = (String) workItem.getParameter("ContainerName"); String containerImageName = (String) workItem.getParameter("ContainerImageName"); String containerCommand = (String) workItem.getParameter("ContainerCommand"); String containerHostName = (String) workItem.getParameter("ContainerHostName"); String containerEnv = (String) workItem.getParameter("ContainerEnv"); String containerPortBindings = (String) workItem.getParameter("ContainerPortBindings"); String containerBinds = (String) workItem.getParameter("ContainerBinds"); if (dockerClient == null) { DockerClientConnector connector = new DockerClientConnector(); dockerClient = connector.getDockerClient(); } CreateContainerCmd createContainerCmd = dockerClient.createContainerCmd(containerImageName).withName(containerName); if (containerCommand != null) { createContainerCmd = createContainerCmd.withCmd(containerCommand); } if (containerHostName != null) { createContainerCmd = createContainerCmd.withHostName(containerHostName); } if (containerEnv != null) { createContainerCmd = createContainerCmd.withEnv(containerEnv); } if (containerPortBindings != null) { createContainerCmd = createContainerCmd.withPortBindings(PortBinding.parse(containerPortBindings)); } if (containerBinds != null) { createContainerCmd = createContainerCmd.withBinds(Bind.parse(containerBinds)); } CreateContainerResponse container = createContainerCmd.exec(); if (container != null && container.getId() != null) { results.put(RESULTS_DOCUMENT, container.getId()); } workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Unable to create container: " + e.getMessage()); handleException(e); } }
Example 15
Source File: ResolveIssueWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String issueKey = (String) workItem.getParameter("IssueKey"); String resolution = (String) workItem.getParameter("Resolution"); String resolutionComment = (String) workItem.getParameter("ResolutionComment"); if (auth == null) { auth = new JiraAuth(userName, password, repoURI); } NullProgressMonitor progressMonitor = new NullProgressMonitor(); Issue issue = auth.getIssueRestClient().getIssue(issueKey, progressMonitor); if (issue != null) { Iterable<Transition> transitions = auth.getIssueRestClient().getTransitions(issue.getTransitionsUri(), progressMonitor); Transition resolveIssueTransition = getTransitionByName(transitions, "Resolve Issue"); Collection<FieldInput> fieldInputs = Arrays.asList(new FieldInput("resolution", resolution)); TransitionInput transitionInput = new TransitionInput(resolveIssueTransition.getId(), fieldInputs, Comment.valueOf(resolutionComment)); auth.getIssueRestClient().transition(issue.getTransitionsUri(), transitionInput, progressMonitor); workItemManager.completeWorkItem(workItem.getId(), null); } else { logger.error("Could not find issue with key: " + issueKey); throw new IllegalArgumentException("Could not find issue with key: " + issueKey); } } catch (Exception e) { logger.error("Error executing workitem: " + e.getMessage()); handleException(e); } }
Example 16
Source File: DailyForecastWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String cityName = (String) workItem.getParameter("CityName"); String countryCode = (String) workItem.getParameter("CountryCode"); Map<String, Object> results = new HashMap<String, Object>(); DailyForecastData dfd = new DailyForecastData(); if (owm == null) { owm = new OWM(apiKey); } DailyWeatherForecast dailyWeatherForecast; if (countryCode == null) { dailyWeatherForecast = owm.dailyWeatherForecastByCityName(cityName); } else { dailyWeatherForecast = owm.dailyWeatherForecastByCityName(cityName, Country.valueOf(countryCode)); } if (dailyWeatherForecast.hasRespCode() && dailyWeatherForecast.getRespCode().equals("200")) { if (dailyWeatherForecast.hasCityData()) { dfd.setCityName(dailyWeatherForecast.getCityData().getName()); } if (dailyWeatherForecast.hasDataCount()) { dfd.setDataCount(dailyWeatherForecast.getDataCount().intValue()); } if (dailyWeatherForecast.hasDataList()) { List<ForecastData> forecastDataList = dailyWeatherForecast.getDataList(); for (ForecastData forecastData : forecastDataList) { DailyForecastDay dailyForecastDay = dfd.new DailyForecastDay(); dailyForecastDay.setDate(forecastData.getDateTime()); dailyForecastDay.setCloud(forecastData.getCloud()); dailyForecastDay.setHumidity(forecastData.getHumidity()); dailyForecastDay.setPressure(forecastData.getPressure()); dailyForecastDay.setRain(forecastData.getRain()); dailyForecastDay.setSnow(forecastData.getSnow()); dailyForecastDay.setSpeed(forecastData.getSpeed()); dailyForecastDay.setMaxTemp(forecastData.getTempData().getTempMax()); dailyForecastDay.setMinTemp(forecastData.getTempData().getTempMin()); dailyForecastDay.setDayTemp(forecastData.getTempData().getTempDay()); dailyForecastDay.setMorningTemp(forecastData.getTempData().getTempMorning()); dailyForecastDay.setEveningTemp(forecastData.getTempData().getTempEvening()); dailyForecastDay.setNightTemp(forecastData.getTempData().getTempNight()); dfd.getDailyForecastDayList().add(dailyForecastDay); } } } else { logger.error("Unable to retrieve weather info."); } results.put(RESULTS_VALUES, dfd); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { handleException(e); } }
Example 17
Source File: DeployContractWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String serviceURL = (String) workItem.getParameter("ServiceURL"); String contractPath = (String) workItem.getParameter("ContractPath"); String depositAmount = (String) workItem.getParameter("DepositAmount"); String waitForReceiptStr = (String) workItem.getParameter("WaitForReceipt"); Map<String, Object> results = new HashMap<String, Object>(); if (web3j == null) { web3j = Web3j.build(new HttpService(serviceURL)); } auth = new EthereumAuth(walletPassword, walletPath, classLoader); Credentials credentials = auth.getCredentials(); int depositEtherAmountToSend = 0; if (depositAmount != null) { depositEtherAmountToSend = Integer.parseInt(depositAmount); } boolean waitForReceipt = false; if (waitForReceiptStr != null) { waitForReceipt = Boolean.parseBoolean(waitForReceiptStr); } String createdContractAddress = EthereumUtils.deployContract(credentials, web3j, EthereumUtils.convertStreamToStr(classLoader.getResourceAsStream(contractPath)), depositEtherAmountToSend, waitForReceipt, EthereumUtils.DEFAULT_SLEEP_DURATION, org.jbpm.process.workitem.ethereum.EthereumUtils.DEFAULT_ATTEMPTS); results.put(RESULTS, createdContractAddress); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error("Error executing workitem: " + e.getMessage()); handleException(e); } }
Example 18
Source File: JavaHandlerWorkItemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); String className = (String) workItem.getParameter("Class"); Class<JavaHandler> c = (Class<JavaHandler>) Class.forName(className); JavaHandler handler = c.newInstance(); KieSession localksession = ksession; RuntimeManager runtimeManager = null; RuntimeEngine engine = null; if (localksession == null) { runtimeManager = RuntimeManagerRegistry.get().getManager(((org.drools.core.process.instance.WorkItem) workItem).getDeploymentId()); engine = runtimeManager.getRuntimeEngine(ProcessInstanceIdContext.get(workItem.getProcessInstanceId())); localksession = engine.getKieSession(); } ProcessContext kcontext = new ProcessContext(localksession); try { WorkflowProcessInstance processInstance = (WorkflowProcessInstance) localksession.getProcessInstance(workItem.getProcessInstanceId()); kcontext.setProcessInstance(processInstance); WorkItemNodeInstance nodeInstance = findNodeInstance(workItem.getId(), processInstance); kcontext.setNodeInstance(nodeInstance); Map<String, Object> results = handler.execute(kcontext); manager.completeWorkItem(workItem.getId(), results); } finally { if (engine != null) { runtimeManager.disposeRuntimeEngine(engine); } } return; } catch (Exception e) { handleException(e); } }
Example 19
Source File: ProcessWorkItemTest.java From kogito-runtimes with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager manager) { manager.completeWorkItem(workItem.getId(), null); }
Example 20
Source File: GeneratePDFWorkitemHandler.java From jbpm-work-items with Apache License 2.0 | 4 votes |
public void executeWorkItem(WorkItem workItem, WorkItemManager workItemManager) { try { RequiredParameterValidator.validate(this.getClass(), workItem); Map<String, Object> results = new HashMap<>(); String templateXHTML = (String) workItem.getParameter("TemplateXHTML"); String pdfName = (String) workItem.getParameter("PDFName"); if (pdfName == null || pdfName.isEmpty()) { pdfName = "generatedpdf"; } Configuration cfg = new Configuration(freemarker.template.Configuration.VERSION_2_3_26); cfg.setDefaultEncoding("UTF-8"); cfg.setTemplateExceptionHandler(TemplateExceptionHandler.RETHROW_HANDLER); cfg.setLogTemplateExceptions(false); StringTemplateLoader stringLoader = new StringTemplateLoader(); stringLoader.putTemplate("pdfTemplate", templateXHTML); cfg.setTemplateLoader(stringLoader); StringWriter stringWriter = new StringWriter(); Template pdfTemplate = cfg.getTemplate("pdfTemplate"); pdfTemplate.process(workItem.getParameters(), stringWriter); resultXHTML = stringWriter.toString(); ITextRenderer renderer = new ITextRenderer(); renderer.setDocumentFromString(resultXHTML); renderer.layout(); Document document = new DocumentImpl(); document.setName(pdfName + ".pdf"); document.setLastModified(new Date()); ByteArrayOutputStream baos = new ByteArrayOutputStream(); renderer.createPDF(baos); document.setContent(baos.toByteArray()); results.put(RESULTS_VALUE, document); workItemManager.completeWorkItem(workItem.getId(), results); } catch (Exception e) { logger.error(e.getMessage()); handleException(e); } }