WOrk to enhance logging of rule execution ==> export as csv
This commit is contained in:
parent
9bc48dd653
commit
01cbf02961
1 changed files with 119 additions and 8 deletions
|
|
@ -1,38 +1,149 @@
|
||||||
package org.chtijbug.drools.console.view;
|
package org.chtijbug.drools.console.view;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.helger.commons.csv.CSVWriter;
|
||||||
|
import com.vaadin.flow.component.html.Anchor;
|
||||||
import com.vaadin.flow.component.html.Label;
|
import com.vaadin.flow.component.html.Label;
|
||||||
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
import com.vaadin.flow.component.orderedlayout.VerticalLayout;
|
||||||
|
import com.vaadin.flow.server.StreamResource;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.chtijbug.drools.console.service.IndexerService;
|
||||||
|
import org.chtijbug.drools.console.service.util.AppContext;
|
||||||
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
|
import org.chtijbug.drools.console.vaadinComponent.ComponentPerso.DialogPerso;
|
||||||
import org.chtijbug.drools.console.vaadinComponent.componentView.GridActionLogging;
|
import org.chtijbug.drools.console.vaadinComponent.componentView.GridActionLogging;
|
||||||
|
import org.chtijbug.drools.logging.Fact;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.model.BusinessTransactionAction;
|
||||||
import org.chtijbug.drools.proxy.persistence.model.BusinessTransactionPersistence;
|
import org.chtijbug.drools.proxy.persistence.model.BusinessTransactionPersistence;
|
||||||
|
import org.chtijbug.drools.proxy.persistence.model.EventType;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.StringWriter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
public class ActionLoggingView extends VerticalLayout {
|
public class ActionLoggingView extends VerticalLayout {
|
||||||
|
|
||||||
|
private IndexerService indexerService;
|
||||||
|
|
||||||
private Label title;
|
private Label title;
|
||||||
|
|
||||||
private GridActionLogging gridActionLogging;
|
private GridActionLogging gridActionLogging;
|
||||||
|
|
||||||
|
private String uniqueID;
|
||||||
|
private String dbID;
|
||||||
|
|
||||||
|
private ObjectMapper mapper = new ObjectMapper();
|
||||||
|
|
||||||
public ActionLoggingView(BusinessTransactionPersistence businessTransactionPersistence, DialogPerso dialogPerso){
|
public ActionLoggingView(BusinessTransactionPersistence businessTransactionPersistence, DialogPerso dialogPerso) {
|
||||||
|
indexerService = AppContext.getApplicationContext().getBean(IndexerService.class);
|
||||||
dialogPerso.getClose().setVisible(false);
|
dialogPerso.getClose().setVisible(false);
|
||||||
//Text text = new Text("Sessino Context ");
|
//Text text = new Text("Sessino Context ");
|
||||||
//dialogPerso.getBar().add(text);
|
//dialogPerso.getBar().add(text);
|
||||||
|
this.uniqueID = businessTransactionPersistence.getTransactionId();
|
||||||
|
this.dbID = businessTransactionPersistence.getId();
|
||||||
|
|
||||||
|
title = new Label("TransactionID : " + businessTransactionPersistence.getTransactionId() + "--" + businessTransactionPersistence.getId());
|
||||||
title=new Label("TransactionID : "+businessTransactionPersistence.getId());
|
|
||||||
title.setClassName("creation-runtime-title");
|
title.setClassName("creation-runtime-title");
|
||||||
|
|
||||||
add(title);
|
add(title);
|
||||||
|
|
||||||
|
|
||||||
gridActionLogging=new GridActionLogging(businessTransactionPersistence.getId());
|
gridActionLogging = new GridActionLogging(businessTransactionPersistence.getId());
|
||||||
add(gridActionLogging);
|
Anchor anchor = new Anchor(new StreamResource(uniqueID.trim().toLowerCase()+".csv", this::getInputStream), "Export as CSV");
|
||||||
|
anchor.getElement().setAttribute("download", true);
|
||||||
|
add(gridActionLogging, anchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private InputStream getInputStream() {
|
||||||
|
try {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
|
||||||
|
CSVWriter csvWriter = new CSVWriter(stringWriter);
|
||||||
|
csvWriter.setSeparatorChar(';');
|
||||||
|
csvWriter.writeNext("start", "end", "eventtype", "position", "rulename", "package", "ruleflowgroup", "processID", "IOData", "when", "then");
|
||||||
|
List<BusinessTransactionAction> businessTransactionPersistences = indexerService.getBusinessTransactionActionRepository().findAllByBusinessTransactionId(dbID, Sort.by(new Sort.Order(Sort.Direction.ASC, "eventNumber")), PageRequest.of(0, 5000));
|
||||||
|
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
|
||||||
|
for (BusinessTransactionAction c : businessTransactionPersistences) {
|
||||||
|
|
||||||
|
String ruleName = "";
|
||||||
|
String packageName = "";
|
||||||
|
String beginDate = "";
|
||||||
|
String endDate = "";
|
||||||
|
String inputData = "";
|
||||||
|
String outputData = "";
|
||||||
|
if (c.getInputData() != null) {
|
||||||
|
//inputData = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(c.getInputData().getRealFact());
|
||||||
|
inputData = mapper.writeValueAsString(c.getInputData().getRealFact());
|
||||||
|
}
|
||||||
|
if (c.getOutputData() != null) {
|
||||||
|
//outputData = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(c.getOutputData().getRealFact());
|
||||||
|
outputData = mapper.writeValueAsString(c.getOutputData().getRealFact());
|
||||||
|
}
|
||||||
|
if (c.getRuleExecution() != null) {
|
||||||
|
ruleName = c.getRuleExecution().getRuleName();
|
||||||
|
packageName = c.getRuleExecution().getPackageName();
|
||||||
|
beginDate = simpleDateFormat.format(c.getRuleExecution().getStartDate());
|
||||||
|
endDate = simpleDateFormat.format(c.getRuleExecution().getEndDate());
|
||||||
|
}
|
||||||
|
//TODO Encode in string the json content
|
||||||
|
|
||||||
|
if (c.getEventType().equals(EventType.INPUT)) {
|
||||||
|
csvWriter.writeNext("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", "", "", "", "",c.getInputData().getFullClassName(),inputData);
|
||||||
|
} else if (c.getEventType().equals(EventType.OUPUT)) {
|
||||||
|
csvWriter.writeNext("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", "", "", "", "",c.getOutputData().getFullClassName(),outputData);
|
||||||
|
} else if (c.getEventType().equals(EventType.STARTPROCESS)) {
|
||||||
|
csvWriter.writeNext("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", "", "", "", "");
|
||||||
|
} else if (c.getEventType().equals(EventType.STOPPROCESS)) {
|
||||||
|
csvWriter.writeNext("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", "", "", "", "");
|
||||||
|
} else if (c.getEventType().equals(EventType.STARTRULEFLOWGROUP)
|
||||||
|
|| c.getEventType().equals(EventType.STOPTRULEFLOWGROUP)) {
|
||||||
|
csvWriter.writeNext("", "", "" + c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", c.getRuleflowGroupName());
|
||||||
|
} else if (c.getEventType().equals(EventType.STARTPROCESS)
|
||||||
|
|| c.getEventType().equals(EventType.STOPPROCESS)) {
|
||||||
|
csvWriter.writeNext("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", c.getProcessID(), "", "", "");
|
||||||
|
} else if (c.getEventType().equals(EventType.RULE)) {
|
||||||
|
List<String> datas = new ArrayList<>();
|
||||||
|
datas.add(simpleDateFormat.format(c.getRuleExecution().getStartDate()));
|
||||||
|
datas.add(simpleDateFormat.format(c.getRuleExecution().getEndDate()));
|
||||||
|
datas.add(c.getEventType().name());
|
||||||
|
datas.add(String.valueOf(c.getEventNumber()));
|
||||||
|
datas.add(c.getRuleExecution().getRuleName());
|
||||||
|
datas.add(c.getRuleExecution().getPackageName());
|
||||||
|
datas.add(c.getRuleflowGroupName());
|
||||||
|
datas.add(c.getProcessID());
|
||||||
|
datas.add("");
|
||||||
|
datas.add("");
|
||||||
|
|
||||||
|
for (Fact f : c.getRuleExecution().getWhenFacts()){
|
||||||
|
datas.add(f.getFullClassName());
|
||||||
|
datas.add(mapper.writeValueAsString(f.getRealFact()));
|
||||||
|
}
|
||||||
|
for (Fact f : c.getRuleExecution().getThenFacts()){
|
||||||
|
datas.add(f.getFullClassName());
|
||||||
|
datas.add(mapper.writeValueAsString(f.getRealFact()));
|
||||||
|
}
|
||||||
|
//csvWriter.writeAll("", "", c.getEventType().name(), String.valueOf(c.getEventNumber()), "", "", "", c.getProcessID(), "", "", "",datas);
|
||||||
|
csvWriter.writeAll(Collections.singletonList(datas));
|
||||||
|
} else {
|
||||||
|
csvWriter.writeNext(beginDate, endDate, c.getEventType().name(), String.valueOf(c.getEventNumber()),
|
||||||
|
ruleName, packageName, c.getRuleflowGroupName(), c.getProcessID()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return IOUtils.toInputStream(stringWriter.toString(), "UTF-8");
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
editor.link_modal.header
Reference in a new issue