package com.alexanderlogistics.rest; import java.util.List; import java.util.Map; import java.util.logging.Logger; import org.imixs.melman.EventLogClient; import org.imixs.melman.FormAuthenticator; import org.imixs.melman.RestAPIException; import org.imixs.workflow.ItemCollection; import org.imixs.workflow.WorkflowKernel; import org.imixs.workflow.exceptions.PluginException; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; /** * A simple example how to create a new event log entry remote. * */ @Disabled public class TestEventLog { private static Logger logger = Logger.getLogger(TestEventLog.class.getName()); EventLogClient client = null; // String restAPI = "https://test.alexander-logistics.office-workflow.de/api"; String restAPI = "http://localhost:8080/api"; String userID = "kutzner-service"; String password = "imixs"; /** * Setup a new Rest Client * * @throws PluginException */ @BeforeEach public void setup() throws PluginException { client = new EventLogClient(restAPI); FormAuthenticator aut; try { aut = new FormAuthenticator(restAPI, userID, password); client.registerClientRequestFilter(aut); } catch (RestAPIException e) { // TODO Auto-generated catch block e.printStackTrace(); } } /** * Create an event log entry.... * */ @Test public void sendXMLData() { logger.info("start..."); ItemCollection payLoad = new ItemCollection(); String uid = WorkflowKernel.generateUniqueID(); try { // set data.... payLoad.setItemValue("some-data", "abc"); String xmlString = "" + "" + " " + " 224225" + " " + " "; payLoad.setItemValue("xml-data", xmlString); client.createEventLogEntry("TOPIC_CARGOSOFT_INVOICE", uid, payLoad); logger.info("completed"); } catch (RestAPIException e) { logger.severe("Failed to send event log entry: " + e.getMessage()); e.printStackTrace(); } } @Test public void getXMLData() { logger.info("start..."); try { List list = client.searchEventLog("TOPIC_CARGOSOFT_INVOICE"); logger.info("found " + list.size() + " log entries"); for (ItemCollection entry : list) { List dataList = entry.getItemValue("data"); if (dataList != null && dataList.size() > 0) { ItemCollection data = new ItemCollection((Map>) dataList.get(0)); logger.info("Data=" + data.getItemValueString("some-data")); logger.info("XML Data=" + data.getItemValueString("xml-data")); } } } catch (RestAPIException e) { logger.severe("Failed to read event log entry: " + e.getMessage()); e.printStackTrace(); } } }