XESExportMain { public static void main(String[] args) { Options options = getOptions(); CommandLineParser parser = new DefaultParser(); try (BasicDataSource ds = new BasicDataSource()) { CommandLine line = parser.parse(options, args); ds.setDriverClassName(line.getOptionValue("driver")); ds.setUrl(line.getOptionValue("url")); ds.setUsername(line.getOptionValue("user")); ds.setPassword(line.getOptionValue("password")); ds.setDefaultReadOnly(true); ds.getConnection().close(); DataSetService dataSetService = new DataSetServiceImpl(() -> ds); XESExportServiceImpl service = new XESExportServiceImpl(); service.setDataSetService(dataSetService); final XESProcessFilter.Builder filter = XESProcessFilter.builder(); filter.withProcessId(line.getOptionValue("process")); if (line.hasOption("version")) { filter.withProcessVersion(line.getOptionValue("version")); } if (line.hasOption("status")) { List<Integer> status = new ArrayList<>(); for (String statusLine : line.getOptionValues("status")) { try { final Integer pStatus = Integer.valueOf(statusLine); if (pStatus >= 0 && pStatus <= 4) { status.add(pStatus); } } catch (NumberFormatException ex) { System.err.println("Invalid process status number for input: " + statusLine + ", valid status are number between 0 and 4."); } } if (status.isEmpty() == false) { filter.withStatus(status); } } if (line.hasOption("logtype")) { filter.withNodeInstanceLogType(Integer.valueOf(line.getOptionValue("logtype"))); } if (line.hasOption("nodetypes")) { filter.withAllNodeTypes(); } final String xml = service.export(filter.build()); if (line.hasOption("file")) { FileUtils.write(new File(line.getOptionValue("file")), xml, "UTF-8"); } else { System.out.println(xml); } } catch (ParseException exp) { System.err.println("Parsing options failed. Reason: " + exp.getMessage()); HelpFormatter formatter = new HelpFormatter(); formatter.printHelp("xes", options, true); System.exit(-1); } catch (Exception ex) { System.err.println("Failed to execute export due to: " + ex.getMessage()); ex.printStackTrace(); System.exit(-1); } }  static void main(String[] args);  }
@Test public void testHelloProcessWithoutFilteringStatus() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-file" , ALL_STATUS_XES_FILE}); assertTrue(validateXML(ALL_STATUS_XES_FILE)); LogType log = assertTraceNodeInstances(ALL_STATUS_XES_FILE, 3); assertStatus(log, "active", "completed", "aborted"); }
@Test public void testHelloProcessFilteringStatusCompleteAndActive() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "1,2", "-file" , ACTIVE_COMPLETED_XES_FILE}); assertTrue(validateXML(ACTIVE_COMPLETED_XES_FILE)); LogType log = assertTraceNodeInstances(ACTIVE_COMPLETED_XES_FILE, 2); assertStatus(log, "active", "completed"); }
@Test public void testHelloProcessFilteringStatusAborted() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "3", "-file" , ABORTED_XES_FILE}); assertTrue(validateXML(ABORTED_XES_FILE)); LogType log = assertTraceNodeInstances(ABORTED_XES_FILE, 1); assertEquals(2, log.getTrace().get(0).getEvent().size()); assertStatus(log, "aborted"); }
@Test public void testHelloProcessFilteringStatusCompletedEnterAndExitEvents() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "2", "-file" , COMPLETED_EE_XES_FILE}); assertTrue(validateXML(COMPLETED_EE_XES_FILE)); LogType log = assertTraceNodeInstances(COMPLETED_EE_XES_FILE, 1); assertEquals(4, log.getTrace().get(0).getEvent().size()); assertStatus(log, "completed"); }
@Test public void testHelloProcessFilteringStatusCompletedOnlyExitEvents() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "2", "-file" , COMPLETED_XES_FILE, "-logtype", "1"}); assertTrue(validateXML(COMPLETED_XES_FILE)); LogType log = assertTraceNodeInstances(COMPLETED_XES_FILE, 1); assertEquals(2, log.getTrace().get(0).getEvent().size()); assertStatus(log, "completed"); }
@Test public void testHelloProcessFilteringStatusCompletedRelevantNodes() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "2", "-file" , COMPLETED_REL_XES_FILE, "-nodetypes"}); assertTrue(validateXML(COMPLETED_REL_XES_FILE)); LogType log = assertTraceNodeInstances(COMPLETED_REL_XES_FILE, 1); assertEquals(8, log.getTrace().get(0).getEvent().size()); assertStatus(log, "completed"); }
@Test public void testHelloProcessFilteringStatusCompletedVersion() throws Exception { XESExportMain.main(new String[] {"-user", user, "-password", password, "-url", url, "-driver", driver, "-process", PROCESS, "-status", "2", "-file" , COMPLETED_1_2_XES_FILE, "-version", "1.2"}); assertTrue(validateXML(COMPLETED_1_2_XES_FILE)); LogType log = assertTraceNodeInstances(COMPLETED_1_2_XES_FILE, 1); assertEquals(4, log.getTrace().get(0).getEvent().size()); assertStatus(log, "completed"); }