All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.uni.freiburg.iig.telematik.sewol.converter.CSV2MXMLTool Maven / Gradle / Ivy

Go to download

SEWOL provides support for the handling of workflow traces. Specifically it allows to specify the shape and content of process traces in terms of entries representing the execution of a specific workflow activity. SEWOL also allows to write these traces on disk as a log file with the help of a special file writer for process logs. Currently it supports plain text, Petrify, MXML and XES log file types. In order to specify security-related context information, SEWOL provides access control models such as access control lists (ACL) and role-based access control models (RBAC). All types of models can be conveniently edited with the help of appropriate dialogs.

The newest version!
package de.uni.freiburg.iig.telematik.sewol.converter;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.SwingConstants;

import de.invation.code.toval.graphic.diagrams.models.DotChartModel;
import de.invation.code.toval.graphic.diagrams.panels.AdjustableDiagramPanel;
import de.invation.code.toval.graphic.diagrams.panels.DotChartPanel;
import de.invation.code.toval.validate.ParameterException;
import de.uni.freiburg.iig.telematik.sewol.format.AbstractLogFormat;
import de.uni.freiburg.iig.telematik.sewol.format.MXMLLogFormat;
import de.uni.freiburg.iig.telematik.sewol.log.DataAttribute;
import de.uni.freiburg.iig.telematik.sewol.log.LogEntry;
import de.uni.freiburg.iig.telematik.sewol.log.LogTrace;


//VORSICHT: Probleme beim Zeitstempel-Handling, evtl. auch in LogWriter


/**
 * Diese Klasse dient dem Import von CSV-Dateien in das MXML-Format.
*
* Es gelten folgende Annahmen bezueglich der Struktur der CSV-Datei:
*
    *
  • Werte sind Komma-, Semikolon- oder Tab-separiert.
  • *
  • Jede Zeile steht fuer eine Prozessaktivitaet.
  • *
  • Die Spalten stehen fuer die einzelnen Felder innerhalb einer Prozessaktivitaet (Name des Vorgangs, durchfuehrender Akteur, ...)
  • *
  • Die erste Zeile enthaelt die Namen die einzelnen Felder von Prozessaktivitaeten.
  • *
  • Alle Aktivitaeten eines Prozessdurchlaufs sind gruppiert und in stehen in korrekter zeitlicher Abfolge untereinander.
  • *
  • Die Case-ID liegt entweder als Zahl vor oder enthaelt am Ende der Zeichenkette eine Zahl.
  • *
  • Die Zahlen fuer die Case-IDs sind fuer jeden Prozessdurchlauf verschieden.
  • *
* * Werte fuer einzelne Felder werden vor der Verarbeitung gesaeubert, * d.h. etwaige Anfuehrungszeichen werden entfernt. * * @author Thomas Stocker */ //TODO: Datumsformat aus erstem Eintrag verwenden @SuppressWarnings("serial") public class CSV2MXMLTool extends JFrame { protected final Dimension WINDOW_SIZE = new Dimension(600,580); protected static final Font defaultFont = new Font(Font.MONOSPACED, Font.PLAIN, 12); protected final int previewAreaCols = 80; protected File file = null; protected JTextArea previewArea = null; protected JComboBox inputCharsetChooser = null; protected JComboBox outputCharsetChooser = null; protected JComboBox separatorChooser = null; protected Charset charset = null; protected Character separator = null; protected Map columnInterpretation; protected JPanel interpretationPanel = null; protected JPanel interpretations = new JPanel(); protected List columnNames; protected AbstractLogFormat logFormat = new MXMLLogFormat(""); public CSV2MXMLTool() { setContentPane(getContentPane()); setPreferredSize(WINDOW_SIZE); setBackground(Color.white); setJMenuBar(createMenu()); pack(); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setVisible(true); } @Override public final JPanel getContentPane() { JPanel content = new JPanel(); content.setLayout(new BorderLayout(0,0)); content.add(getNavigationPanel(), BorderLayout.NORTH); content.add(getMidPanel(), BorderLayout.CENTER); return content; } protected JPanel getMidPanel() { JPanel midPanel = new JPanel(); JPanel previewPanel = new JPanel(new BorderLayout()); previewPanel.add(new JLabel("Preview (first 10 lines):"), BorderLayout.PAGE_START); previewPanel.add(getPreviewArea(), BorderLayout.CENTER); midPanel.add(previewPanel, BorderLayout.NORTH); midPanel.add(getInterpretationPanel(), BorderLayout.CENTER); return midPanel; } protected JPanel getInterpretationPanel(){ if(interpretationPanel == null){ interpretationPanel = new JPanel(new BorderLayout()); JPanel headingPanel = new JPanel(new GridLayout(1, 2,10,0)); headingPanel.setPreferredSize(new Dimension(560,40)); headingPanel.add(new JLabel("CSV Column", SwingConstants.CENTER)); headingPanel.add(new JLabel("Interpretation")); headingPanel.setBackground(Color.lightGray); interpretationPanel.add(headingPanel, BorderLayout.NORTH); JScrollPane interpretationScrollPane = new JScrollPane(interpretations); interpretationScrollPane.setPreferredSize(new Dimension(560, 250)); interpretationPanel.add(interpretationScrollPane, BorderLayout.CENTER); } return interpretationPanel; } private Integer extractCaseNumber(String caseID){ int caseNumber; for(int i=0; i(st.countTokens()); columnNames = new ArrayList<>(st.countTokens()); while(st.hasMoreTokens()){ String nextToken = st.nextToken(); columnInterpretation.put(nextToken, null); columnNames.add(nextToken); JLabel newLabel = new JLabel(nextToken); newLabel.setHorizontalAlignment(SwingConstants.CENTER); interpretations.add(newLabel); interpretations.add(getNewInterpretationBox(nextToken)); } } else { previewArea.append(line.substring(0, Math.min(line.length(), previewAreaCols-1))+'\n'); } lineCount++; } in.close(); } catch (IOException e) { JOptionPane.showMessageDialog(null,"Cannot prepare preview: " + e.getMessage(),"Internal Exception", JOptionPane.ERROR_MESSAGE); } } protected JComboBox getNewInterpretationBox(String columnName){ final String column = columnName; final JComboBox comboBox = new JComboBox(LogConcept.values()); comboBox.setSelectedIndex(comboBox.getItemCount()-1); columnInterpretation.put(column, (LogConcept) comboBox.getSelectedItem()); comboBox.addItemListener(new ItemListener(){ @Override public void itemStateChanged(ItemEvent e) { columnInterpretation.put(column, (LogConcept) comboBox.getSelectedItem()); } }); return comboBox; } protected class OpenAction extends AbstractAction { @Override public void actionPerformed(ActionEvent e) { JFileChooser chooser = new JFileChooser(); if (chooser.showOpenDialog(CSV2MXMLTool.this) == JFileChooser.APPROVE_OPTION) { file = chooser.getSelectedFile(); if(!file.exists()) { JOptionPane.showMessageDialog(null,"File does not exist!","I/O Error on opening file", JOptionPane.ERROR_MESSAGE); } if(!file.canRead()){ JOptionPane.showMessageDialog(null,"Unable to read file!","I/O Error on opening file", JOptionPane.ERROR_MESSAGE); } displayPreview(); } } } protected class ImportAction extends AbstractAction { private final Map numberOfActivities = new HashMap<>(); private void addActivityNumber(int number){ if(!numberOfActivities.containsKey(number)){ numberOfActivities.put(number, 1); return; } numberOfActivities.put(number, numberOfActivities.get(number)+1); } @Override public void actionPerformed(ActionEvent e) { try { if(charset == null || file == null) return; numberOfActivities.clear(); //Prepare output file writer String inputName = file.getAbsolutePath(); File outfile = new File(inputName.substring(0, inputName.lastIndexOf('.'))+"."+logFormat.getFileExtension()); if(outfile.exists()) outfile.delete(); outfile.createNewFile(); BufferedWriter output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outfile), logFormat.getCharset())); output.write(logFormat.getFileHeader()); BufferedReader in = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset)); String line = null; int lineCount = 0; int tokenCount; Integer lastCaseID = null; Integer actualCaseID = null; LogTrace actualTrace = null; while ((line = in.readLine()) != null) { if(lineCount == 0){ lineCount++; } else { String[] tokens = line.split(";", -1); // StringTokenizer st = new StringTokenizer(line, String.valueOf(separator)); tokenCount = 0; LogEntry newEntry = new LogEntry(); boolean abort = false; for(int i=0; i(actualCaseID); } catch (ParameterException e1) { JOptionPane.showMessageDialog(CSV2MXMLTool.this, "Error during trace generation: " + e1.getMessage(), "Transformation Exception", JOptionPane.ERROR_MESSAGE); output.close(); in.close(); return; } } actualTrace.addEntry(newEntry); lastCaseID = actualCaseID; lineCount++; } } output.write(logFormat.getTraceAsString(actualTrace)); addActivityNumber(actualTrace.size()); System.out.println("Writing new trace ["+actualCaseID+"]: "+actualTrace.size()+" entries"); System.out.println(); //Write out statistics System.out.println("Trace complexity (#activities -> number of traces)"); List activityNumbers = new ArrayList<>(); activityNumbers.addAll(numberOfActivities.keySet()); Collections.sort(activityNumbers); for(Integer activityNumber: activityNumbers){ System.out.println(activityNumber + " -> " + numberOfActivities.get(activityNumber)); } List numTraces = new ArrayList<>(); numTraces.addAll(numberOfActivities.values()); DotChartModel chartModel = new DotChartModel<>(activityNumbers, numTraces); DotChartPanel panel = new DotChartPanel(chartModel, true, true, true); AdjustableDiagramPanel adjustablePanel = new AdjustableDiagramPanel(panel); adjustablePanel.asFrame(); output.write(logFormat.getFileFooter()); output.close(); in.close(); System.out.println("Done"); } catch (IOException | NullPointerException ex) { throw new RuntimeException(ex); } } } public static void main(String[] args){ new CSV2MXMLTool(); } private enum LogConcept {CASEID, ACTIVITY, ORIGINATOR, TIMESTAMP, META}; }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy