Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| e35d5ff013 | |||
| d905d4195c | |||
| c12444c0d6 | |||
| 16ef02b533 | |||
| 3bb37ef10d |
@@ -0,0 +1 @@
|
|||||||
|
{`<EFBFBD><EFBFBD>i<EFBFBD>\<EFBFBD>0<EFBFBD>'ݳ<EFBFBD>-I1+<EFBFBD>x<EFBFBD><EFBFBD>c/J<EFBFBD>M<EFBFBD>@<EFBFBD>gL<EFBFBD><EFBFBD>@<EFBFBD>Y<EFBFBD><EFBFBD>R<EFBFBD><EFBFBD><EFBFBD>zJ<EFBFBD>{zq4<EFBFBD><EFBFBD>6<EFBFBD>s<EFBFBD>^<EFBFBD>z
|
||||||
38
MDM-LCAG-JavaFunctions/.dbeaver/.data-sources.json.bak
Normal file
38
MDM-LCAG-JavaFunctions/.dbeaver/.data-sources.json.bak
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
{
|
||||||
|
"folders": {},
|
||||||
|
"connections": {
|
||||||
|
"mariaDB-19b7ec1a720-2d9c28ffc4370b6b": {
|
||||||
|
"provider": "mysql",
|
||||||
|
"driver": "mariaDB",
|
||||||
|
"name": "unserleben",
|
||||||
|
"save-password": true,
|
||||||
|
"configuration": {
|
||||||
|
"host": "boston",
|
||||||
|
"port": "3306",
|
||||||
|
"database": "unserleben",
|
||||||
|
"url": "jdbc:mariadb://boston:3306/unserleben",
|
||||||
|
"configurationType": "MANUAL",
|
||||||
|
"home": "mysql_client",
|
||||||
|
"type": "dev",
|
||||||
|
"closeIdleConnection": true,
|
||||||
|
"auth-model": "native"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"connection-types": {
|
||||||
|
"dev": {
|
||||||
|
"name": "Development",
|
||||||
|
"color": "255,255,255",
|
||||||
|
"description": "Regular development database",
|
||||||
|
"auto-commit": true,
|
||||||
|
"confirm-execute": false,
|
||||||
|
"confirm-data-change": false,
|
||||||
|
"smart-commit": false,
|
||||||
|
"smart-commit-recover": false,
|
||||||
|
"auto-close-transactions": true,
|
||||||
|
"close-transactions-period": 1800,
|
||||||
|
"auto-close-connections": true,
|
||||||
|
"close-connections-period": 14400
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{"resources":{"Scripts/Script.sql":{"default-datasource":"mariaDB-19b7ec917b8-2c62df336d3e06a"}}}
|
||||||
2
MDM-LCAG-JavaFunctions/.dbeaver/credentials-config.json
Normal file
2
MDM-LCAG-JavaFunctions/.dbeaver/credentials-config.json
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
hv<EFBFBD><EFBFBD><EFBFBD>EH x<EFBFBD>ߓ<EFBFBD>]Ig<EFBFBD>YC<EFBFBD>Yo<EFBFBD><EFBFBD>+GQxm<EFBFBD>A<EFBFBD>
|
||||||
|
<EFBFBD><EFBFBD>><EFBFBD>i"<22><>Б/<2F><><1E><>.<2E>q!z<><7A><12>X<07><1F>:<3A>@<40>=t<><74>3M/mG<6D><47>7<EFBFBD>0<EFBFBD>O<EFBFBD>Խ<EFBFBD>;~<1A><><EFBFBD><EFBFBD><EFBFBD>`<60>cȝ<18>fN<66><4E>dߊwzd<7A><64>G<EFBFBD><47><EFBFBD><EFBFBD><EFBFBD>Y:)<29>l<EFBFBD>HB'<27>719<><39><EFBFBD>a<EFBFBD>:lx<14><>%gJ<0C>I<EFBFBD><49>Cyl5<0F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>$gP<67><08><>y<EFBFBD>+p<><70>(<28><>(<28>5<><35><EFBFBD>'k<><6B><EFBFBD><EFBFBD><EFBFBD>"o<EFBFBD>O<EFBFBD>;7<EFBFBD><EFBFBD>u<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
||||||
69
MDM-LCAG-JavaFunctions/.dbeaver/data-sources.json
Normal file
69
MDM-LCAG-JavaFunctions/.dbeaver/data-sources.json
Normal file
@@ -0,0 +1,69 @@
|
|||||||
|
{
|
||||||
|
"folders": {},
|
||||||
|
"connections": {
|
||||||
|
"mariaDB-19b7ec1a720-2d9c28ffc4370b6b": {
|
||||||
|
"provider": "mysql",
|
||||||
|
"driver": "mariaDB",
|
||||||
|
"name": "unserleben",
|
||||||
|
"save-password": true,
|
||||||
|
"configuration": {
|
||||||
|
"host": "boston",
|
||||||
|
"port": "3306",
|
||||||
|
"database": "unserleben",
|
||||||
|
"url": "jdbc:mariadb://boston:3306/unserleben",
|
||||||
|
"configurationType": "MANUAL",
|
||||||
|
"home": "mysql_client",
|
||||||
|
"type": "dev",
|
||||||
|
"closeIdleConnection": true,
|
||||||
|
"auth-model": "native"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mariaDB-19b7ec917b8-2c62df336d3e06a": {
|
||||||
|
"provider": "mysql",
|
||||||
|
"driver": "mariaDB",
|
||||||
|
"name": "unserleben@boston",
|
||||||
|
"save-password": true,
|
||||||
|
"configuration": {
|
||||||
|
"host": "boston",
|
||||||
|
"port": "3306",
|
||||||
|
"database": "unserleben",
|
||||||
|
"url": "jdbc:mariadb://boston:3306/unserleben",
|
||||||
|
"configurationType": "MANUAL",
|
||||||
|
"home": "mysql_client",
|
||||||
|
"type": "prod",
|
||||||
|
"closeIdleConnection": true,
|
||||||
|
"auth-model": "native"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"connection-types": {
|
||||||
|
"dev": {
|
||||||
|
"name": "Development",
|
||||||
|
"color": "255,255,255",
|
||||||
|
"description": "Regular development database",
|
||||||
|
"auto-commit": true,
|
||||||
|
"confirm-execute": false,
|
||||||
|
"confirm-data-change": false,
|
||||||
|
"smart-commit": false,
|
||||||
|
"smart-commit-recover": false,
|
||||||
|
"auto-close-transactions": true,
|
||||||
|
"close-transactions-period": 1800,
|
||||||
|
"auto-close-connections": true,
|
||||||
|
"close-connections-period": 14400
|
||||||
|
},
|
||||||
|
"prod": {
|
||||||
|
"name": "Production",
|
||||||
|
"color": "org.jkiss.dbeaver.color.connectionType.prod.background",
|
||||||
|
"description": "Production database",
|
||||||
|
"auto-commit": false,
|
||||||
|
"confirm-execute": true,
|
||||||
|
"confirm-data-change": true,
|
||||||
|
"smart-commit": false,
|
||||||
|
"smart-commit-recover": false,
|
||||||
|
"auto-close-transactions": true,
|
||||||
|
"close-transactions-period": 600,
|
||||||
|
"auto-close-connections": true,
|
||||||
|
"close-connections-period": 3600
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
1
MDM-LCAG-JavaFunctions/.dbeaver/project-metadata.json
Normal file
1
MDM-LCAG-JavaFunctions/.dbeaver/project-metadata.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"resources":{"Scripts/Script.sql":{"default-datasource":"mariaDB-19b7ec917b8-2c62df336d3e06a","default-catalog":"unserleben"}}}
|
||||||
1
MDM-LCAG-JavaFunctions/.dbeaver/project-settings.json
Normal file
1
MDM-LCAG-JavaFunctions/.dbeaver/project-settings.json
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{"id":"1ead1cdd-1b48-4d2d-8560-6913212ffc8b"}
|
||||||
@@ -38,6 +38,7 @@
|
|||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.python.pydev.pythonNature</nature>
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
|
<nature>org.jkiss.dbeaver.DBeaverNature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
<variableList>
|
<variableList>
|
||||||
<variable>
|
<variable>
|
||||||
|
|||||||
23
MDM-LCAG-JavaFunctions/Scripts/Script.sql
Normal file
23
MDM-LCAG-JavaFunctions/Scripts/Script.sql
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
SELECT
|
||||||
|
ts.Start_Time AS Datum
|
||||||
|
, CASE
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Silke TGIF%' THEN 'F-Tag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Silke Home Office%' THEN 'Home Office'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Silke %rotag%' THEN 'Buerotag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Silke Dienstreise%' THEN 'Dienstreise'
|
||||||
|
WHEN lower(ts.NOTE_TEXT) LIKE '%Silke krank%' THEN 'Krank'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Silke Urlaubs%' THEN 'Urlaub'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Urlaubstag Silke%' THEN 'Urlaub'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Urlaubsanfang Silke%' THEN 'Urlaub'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Urlaubsende Silke%' THEN 'Urlaub'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%ilke F Tag%' THEN 'F-Tag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%ilke Tag frei%' THEN 'F-Tag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%ilke frei%' THEN 'F-Tag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%Tag frei Silke%' THEN 'F-Tag'
|
||||||
|
WHEN ts.NOTE_TEXT LIKE '%ilke Kurzarbeit%' THEN 'Kurzarbeit'
|
||||||
|
ELSE 'Sonstiges'
|
||||||
|
END AS Category
|
||||||
|
, 'Silke' AS Person
|
||||||
|
, ts.NOTE_TEXT
|
||||||
|
FROM note ts
|
||||||
|
WHERE CLASSTYPE = 'Note' AND ts.note_text like '%ilke%'
|
||||||
@@ -8,22 +8,26 @@ import java.io.InputStreamReader;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
|
import com.vladsch.flexmark.html2md.converter.FlexmarkHtmlConverter;
|
||||||
|
|
||||||
import de.lcag.common.AbstractTable.ListColumn;
|
|
||||||
import de.lcag.common.HashTable;
|
import de.lcag.common.HashTable;
|
||||||
|
import de.lcag.common.Table.TableColumn;
|
||||||
import routines.LcagFileTools;
|
import routines.LcagFileTools;
|
||||||
import routines.LcagLogger;
|
import routines.LcagLogger;
|
||||||
|
|
||||||
public class CommentExtractor {
|
public class CommentExtractor {
|
||||||
|
private static final String BUGFIX_COMMAND = "BUGFIX_"; // Fix of a Agile Defect in Trackspace
|
||||||
|
private static final String STORY_COMMAND = "BUGFIX_"; // User Story in Trackspace to implement
|
||||||
private static final String HOW_TO_COMMAND = "HOWTO_";
|
private static final String HOW_TO_COMMAND = "HOWTO_";
|
||||||
private static final String DOCUMENT_FLOW_COMMAND = "FLOW_";
|
private static final String DOCUMENT_FLOW_COMMAND = "FLOW_";
|
||||||
private static final String TODO_COMMAND = "TODO_";
|
private static final String TODO_COMMAND = "TODO_";
|
||||||
|
|
||||||
private static final String[] COMMAD_LIST = new String[] { HOW_TO_COMMAND, DOCUMENT_FLOW_COMMAND, TODO_COMMAND };
|
private static final String[] COMMAD_LIST = new String[] { HOW_TO_COMMAND, DOCUMENT_FLOW_COMMAND, TODO_COMMAND,
|
||||||
|
BUGFIX_COMMAND, STORY_COMMAND };
|
||||||
|
|
||||||
private static final String COL_TYPE = "Type";
|
private static final String COL_TYPE = "Type";
|
||||||
private static final String COL_ID = "Id";
|
private static final String COL_ID = "Id";
|
||||||
@@ -73,7 +77,7 @@ public class CommentExtractor {
|
|||||||
try {
|
try {
|
||||||
extractCodeExamples(rootDirPath);
|
extractCodeExamples(rootDirPath);
|
||||||
|
|
||||||
ListColumn sortedResults = resultTable.sort(COL_ID, COL_STEP);
|
TableColumn sortedResults = resultTable.sort(COL_ID, COL_STEP);
|
||||||
|
|
||||||
String txt = resultTable.asCSV(sortedResults);
|
String txt = resultTable.asCSV(sortedResults);
|
||||||
String fileName = DOC_FILE + ".csv";
|
String fileName = DOC_FILE + ".csv";
|
||||||
@@ -87,11 +91,13 @@ public class CommentExtractor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void writeHtmlFile(ListColumn sortedResults) throws IOException {
|
private static void writeHtmlFile(TableColumn sortedResults) throws IOException {
|
||||||
String fileName = DOC_FILE + ".html";
|
String fileName = DOC_FILE + ".html";
|
||||||
|
|
||||||
for (int i = 0; i < resultTable.lenght(); i++) {
|
for (int i = 0; i < resultTable.lenght(); i++) {
|
||||||
int lineNo = (int) resultTable.getCellValue(i, COL_LINE_NO);
|
int lineNo = (int) resultTable.getCellValue(i, COL_LINE_NO);
|
||||||
|
|
||||||
|
String colId = (String) resultTable.getCellValue(i, COL_ID);
|
||||||
String filePath = (String) resultTable.getCellValue(i, COL_FILE);
|
String filePath = (String) resultTable.getCellValue(i, COL_FILE);
|
||||||
String gitURL = String.format(CODE_BASE_GITHUB_DIR, filePath, gitBranchName, lineNo, lineNo + 1);
|
String gitURL = String.format(CODE_BASE_GITHUB_DIR, filePath, gitBranchName, lineNo, lineNo + 1);
|
||||||
String lineNoURL = String.format("<html><a href=\"%s\">%d</a></html>", gitURL, lineNo);
|
String lineNoURL = String.format("<html><a href=\"%s\">%d</a></html>", gitURL, lineNo);
|
||||||
@@ -111,6 +117,16 @@ public class CommentExtractor {
|
|||||||
if (kind.equals("Title")) {
|
if (kind.equals("Title")) {
|
||||||
String disc = String.format("<html><b>%s</b></html>", (String) resultTable.getCellValue(i, COL_DESC));
|
String disc = String.format("<html><b>%s</b></html>", (String) resultTable.getCellValue(i, COL_DESC));
|
||||||
resultTable.setCellValue(i, COL_DESC, disc);
|
resultTable.setCellValue(i, COL_DESC, disc);
|
||||||
|
|
||||||
|
// For BUGFIX or STORY: Add link into trackspace:
|
||||||
|
String digits = colId.replaceAll(".*[BS](\\d+).*", "$1"); // Extract digits after 'B'
|
||||||
|
|
||||||
|
if (!Objects.equals(colId, digits)) {
|
||||||
|
String htmlLink = "<html><a href=\"https://trackspace.lhsystems.com/browse/MDMGMT-" + digits
|
||||||
|
+ "\" target=\"_blank\">" + colId + "</a></html>";
|
||||||
|
|
||||||
|
resultTable.setCellValue(i, COL_ID, htmlLink);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,25 @@
|
|||||||
package application;
|
package application;
|
||||||
|
|
||||||
|
import java.awt.BorderLayout;
|
||||||
import java.awt.Desktop;
|
import java.awt.Desktop;
|
||||||
|
import java.awt.Dimension;
|
||||||
import java.awt.GridLayout;
|
import java.awt.GridLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.KeyEvent;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.StandardCopyOption;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import javax.naming.ConfigurationException;
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JButton;
|
||||||
import javax.swing.JFileChooser;
|
import javax.swing.JFileChooser;
|
||||||
import javax.swing.JFrame;
|
import javax.swing.JFrame;
|
||||||
@@ -13,88 +28,390 @@ import javax.swing.JMenu;
|
|||||||
import javax.swing.JMenuBar;
|
import javax.swing.JMenuBar;
|
||||||
import javax.swing.JMenuItem;
|
import javax.swing.JMenuItem;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
|
import javax.swing.JPanel;
|
||||||
|
import javax.swing.JPopupMenu;
|
||||||
|
import javax.swing.KeyStroke;
|
||||||
import javax.swing.SwingUtilities;
|
import javax.swing.SwingUtilities;
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FilenameUtils;
|
||||||
|
|
||||||
|
import de.lcag.common.ExcelWorkbook;
|
||||||
|
import de.lcag.common.LcagProperties;
|
||||||
|
import de.lcag.common.MappingTable;
|
||||||
|
import de.lcag.common.Table;
|
||||||
|
import de.lcag.common.WorkbookComparisonResult;
|
||||||
|
import routines.LcagFileTools;
|
||||||
|
import routines.LcagStringTools;
|
||||||
|
|
||||||
public class FileActions extends JFrame {
|
public class FileActions extends JFrame {
|
||||||
private JLabel file1Label, file2Label;
|
private static final int FRAME_HEIGHT = 150;
|
||||||
private JButton selectFile1, selectFile2;
|
private static String MASTER_FILE_LABEL = "Main Excel File";
|
||||||
private File file1, file2;
|
private static String CONFIG_FILE_LABEL = "Configuration File";
|
||||||
|
|
||||||
|
private JLabel masterFileLabel, clientFileLabel, configFileLabel;
|
||||||
|
private JButton selectMasterFile, selectClientFile, selectConfigFile;
|
||||||
|
private Path configFile;
|
||||||
|
private String masterFile, clientFile;
|
||||||
private JMenuBar menuBar;
|
private JMenuBar menuBar;
|
||||||
private JMenu actionsMenu;
|
private JMenu actionsMenu;
|
||||||
private JMenuItem openInExcelItem;
|
private JMenuItem mergeAction;
|
||||||
|
private JPopupMenu contextMenuMasterFile, contextMenuClientFile;
|
||||||
|
private File configFileDirectoryPath = null;
|
||||||
|
private LcagProperties config = null;
|
||||||
|
private File masterDirecory = null;
|
||||||
|
private File clientDirecory = null;
|
||||||
|
private static List<String> SUPPORTED_FILE_TYPES = List.of("xls", "xlsx");
|
||||||
|
|
||||||
public FileActions() {
|
public FileActions() {
|
||||||
setTitle("Datei-Auswahl und Aktionen");
|
setTitle("Compare 2 Excel Files");
|
||||||
setSize(400, 200);
|
setSize(800, FRAME_HEIGHT);
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
setLayout(new GridLayout(3, 2));
|
|
||||||
|
|
||||||
file1Label = new JLabel("Datei 1: Keine ausgew<65>hlt");
|
JPanel mainPanel = new JPanel(new BorderLayout());
|
||||||
file2Label = new JLabel("Datei 2: Keine ausgew<65>hlt");
|
JPanel leftButtonPanel = new JPanel(new GridLayout(3, 1, 5, 5));
|
||||||
selectFile1 = new JButton("Datei 1 ausw<73>hlen");
|
JPanel rightTextPanel = new JPanel(new GridLayout(3, 1, 5, 5));
|
||||||
selectFile2 = new JButton("Datei 2 ausw<73>hlen");
|
// setLayout(new GridLayout(4, 2));
|
||||||
|
|
||||||
// File Chooser f<>r Datei 1 (nur Excel-Dateien)
|
leftButtonPanel.setPreferredSize(new Dimension(200, FRAME_HEIGHT)); // Fixed width
|
||||||
selectFile1.addActionListener(e -> {
|
|
||||||
|
// Add an empty border to create a gap on the right side of leftPanel
|
||||||
|
leftButtonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); // right gap: 10px
|
||||||
|
|
||||||
|
rightTextPanel.setPreferredSize(new Dimension(1000, FRAME_HEIGHT));
|
||||||
|
mainPanel.add(leftButtonPanel, BorderLayout.WEST);
|
||||||
|
mainPanel.add(rightTextPanel, BorderLayout.EAST);
|
||||||
|
|
||||||
|
configFileLabel = new JLabel(String.format(" %s: Not selected", CONFIG_FILE_LABEL));
|
||||||
|
|
||||||
|
selectConfigFile = new JButton("Select " + CONFIG_FILE_LABEL);
|
||||||
|
leftButtonPanel.add(selectConfigFile);
|
||||||
|
rightTextPanel.add(configFileLabel);
|
||||||
|
|
||||||
|
// File Chooser for config file
|
||||||
|
selectConfigFile.setEnabled(true);
|
||||||
|
selectConfigFile.addActionListener(e -> {
|
||||||
|
if (!configFileDirectoryPath.isDirectory()) {
|
||||||
|
System.err.println(String.format("ERROR: Config directory %s does not exist",
|
||||||
|
configFileDirectoryPath.getAbsolutePath()));
|
||||||
|
System.exit(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
JFileChooser fileChooser = new JFileChooser(configFileDirectoryPath);
|
||||||
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Config Files", "properties");
|
||||||
|
fileChooser.setFileFilter(filter);
|
||||||
|
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
|
String clientDirString = null;
|
||||||
|
|
||||||
|
configFile = Path.of(selectFile(fileChooser));
|
||||||
|
config = new LcagProperties(configFile.toString());
|
||||||
|
|
||||||
|
configFileLabel.setText(String.format(" %s: %s", CONFIG_FILE_LABEL, configFile));
|
||||||
|
|
||||||
|
masterFile = config.getOptionalProperty("main_file");
|
||||||
|
|
||||||
|
if (masterFile != null) {
|
||||||
|
String masterFilePath = LcagFileTools.getPath(masterFile);
|
||||||
|
masterFile = LcagFileTools.getName(masterFile);
|
||||||
|
masterDirecory = new File(masterFilePath);
|
||||||
|
masterFileLabel.setText(String.format("<html>Selected: %s<br>in: %s</html>", masterFile,
|
||||||
|
masterDirecory.getAbsolutePath()));
|
||||||
|
selectMasterFile.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
clientFile = config.getOptionalProperty("compare_file");
|
||||||
|
if (clientFile != null) {
|
||||||
|
String clientFilePath = LcagFileTools.getPath(clientFile);
|
||||||
|
clientFile = LcagFileTools.getName(clientFile);
|
||||||
|
clientDirecory = new File(clientFilePath);
|
||||||
|
|
||||||
|
if (clientDirecory.isAbsolute()) {
|
||||||
|
clientDirString = clientFilePath;
|
||||||
|
} else {
|
||||||
|
clientDirString = "same directory as 1st file";
|
||||||
|
}
|
||||||
|
clientFileLabel.setText(
|
||||||
|
String.format("<html>Selected: %s<br>in: %s </html>", clientFile, clientDirString));
|
||||||
|
selectClientFile.setEnabled(true);
|
||||||
|
}
|
||||||
|
// After user selected a config file enable buttons to set files to compare (can
|
||||||
|
// overwrite files listed in config file):
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Kontextmen<65>s erstellen
|
||||||
|
contextMenuMasterFile = new JPopupMenu();
|
||||||
|
contextMenuClientFile = new JPopupMenu();
|
||||||
|
JMenuItem renameFile1 = new JMenuItem("Rename File");
|
||||||
|
JMenuItem renameFile2 = new JMenuItem("Rename File");
|
||||||
|
contextMenuMasterFile.add(renameFile1);
|
||||||
|
contextMenuClientFile.add(renameFile2);
|
||||||
|
|
||||||
|
masterFileLabel = new JLabel(
|
||||||
|
String.format(" %s: %s", MASTER_FILE_LABEL, masterFile == null ? "Not selected" : masterFile));
|
||||||
|
|
||||||
|
selectMasterFile = new JButton("Select " + MASTER_FILE_LABEL);
|
||||||
|
leftButtonPanel.add(selectMasterFile);
|
||||||
|
rightTextPanel.add(masterFileLabel);
|
||||||
|
|
||||||
|
clientFileLabel = new JLabel(
|
||||||
|
String.format(" %s: %s", "Excel to compare", clientFile == null ? "Not selected" : clientFile));
|
||||||
|
|
||||||
|
selectClientFile = new JButton("Select Excel to Compare");
|
||||||
|
|
||||||
|
// MouseListener f<>r Kontextmen<65> auf den Labels
|
||||||
|
masterFileLabel.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (SwingUtilities.isRightMouseButton(e) && masterFile != null) {
|
||||||
|
contextMenuMasterFile.show(masterFileLabel, e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
clientFileLabel.addMouseListener(new MouseAdapter() {
|
||||||
|
@Override
|
||||||
|
public void mouseClicked(MouseEvent e) {
|
||||||
|
if (SwingUtilities.isRightMouseButton(e) && clientFile != null) {
|
||||||
|
contextMenuClientFile.show(clientFileLabel, e.getX(), e.getY());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
leftButtonPanel.add(selectClientFile);
|
||||||
|
rightTextPanel.add(clientFileLabel);
|
||||||
|
|
||||||
|
renameFile1.addActionListener(e -> renameFile(masterFile, masterFileLabel, "Datei 1"));
|
||||||
|
renameFile2.addActionListener(e -> renameFile(clientFile, clientFileLabel, "Datei 2"));
|
||||||
|
|
||||||
|
// File Chooser f<>r Datei 1 (nur Excel-Dateien)
|
||||||
|
selectMasterFile.setEnabled(false);
|
||||||
|
selectMasterFile.addActionListener(e -> {
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
JFileChooser fileChooser = new JFileChooser();
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Dateien", "xls", "xlsx");
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Files",
|
||||||
|
SUPPORTED_FILE_TYPES.toArray(new String[0]));
|
||||||
fileChooser.setFileFilter(filter);
|
fileChooser.setFileFilter(filter);
|
||||||
|
|
||||||
|
if (masterFile != null) {
|
||||||
|
Path masterFilePath = Path.of(masterFile);
|
||||||
|
masterDirecory = new File(masterFilePath.getParent().toString());
|
||||||
|
fileChooser.setCurrentDirectory(masterDirecory);
|
||||||
|
|
||||||
|
masterDirecory = new File(masterFilePath.getParent().toString());
|
||||||
|
masterFileLabel.setText(String.format("<html>Selected: %s<br>in: %s</html>", masterFile,
|
||||||
|
masterFilePath.getParent().toString()));
|
||||||
|
selectClientFile.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
file1 = fileChooser.getSelectedFile();
|
Path masterFilePath = Path.of(masterFile);
|
||||||
file1Label.setText("Datei 1: " + file1.getName());
|
masterFile = selectFile(fileChooser);
|
||||||
selectFile2.setEnabled(true);
|
masterDirecory = new File(masterFilePath.getParent().toString());
|
||||||
|
masterFileLabel.setText(String.format(" %s: %s", MASTER_FILE_LABEL, masterFilePath.getFileName()));
|
||||||
|
selectClientFile.setEnabled(true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// File Chooser f<>r Datei 2 (im selben Verzeichnis wie Datei 1, nur
|
// File Chooser f<>r Datei 2 (im selben Verzeichnis wie Datei 1, nur
|
||||||
// Excel-Dateien)
|
// Excel-Dateien)
|
||||||
selectFile2.setEnabled(false);
|
selectClientFile.setEnabled(false);
|
||||||
selectFile2.addActionListener(e -> {
|
selectClientFile.addActionListener(e -> {
|
||||||
if (file1 != null) {
|
if (masterDirecory != null) {
|
||||||
JFileChooser fileChooser = new JFileChooser(file1.getParentFile());
|
JFileChooser fileChooser = new JFileChooser(masterDirecory);
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Dateien", "xls", "xlsx");
|
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Dateien", "xls", "xlsx");
|
||||||
fileChooser.setFileFilter(filter);
|
fileChooser.setFileFilter(filter);
|
||||||
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
||||||
file2 = fileChooser.getSelectedFile();
|
clientFile = selectFile(fileChooser);
|
||||||
file2Label.setText("Datei 2: " + file2.getName());
|
clientFileLabel.setText("Datei 2: " + clientFile);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
add(selectFile1);
|
// Men<65> erstellen
|
||||||
add(file1Label);
|
|
||||||
add(selectFile2);
|
|
||||||
add(file2Label);
|
|
||||||
|
|
||||||
// Men<65> erstellen
|
|
||||||
menuBar = new JMenuBar();
|
menuBar = new JMenuBar();
|
||||||
actionsMenu = new JMenu("Aktionen");
|
actionsMenu = new JMenu("Actions");
|
||||||
openInExcelItem = new JMenuItem("Erste Datei in Excel <20>ffnen");
|
mergeAction = new JMenuItem("Merge 2nd into Main file");
|
||||||
|
|
||||||
actionsMenu.add(openInExcelItem);
|
mergeAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
|
||||||
|
mergeAction.addActionListener(e -> {
|
||||||
|
System.out.println("Ctrl-C pressed on menu");
|
||||||
|
});
|
||||||
|
|
||||||
|
actionsMenu.add(mergeAction);
|
||||||
menuBar.add(actionsMenu);
|
menuBar.add(actionsMenu);
|
||||||
setJMenuBar(menuBar);
|
setJMenuBar(menuBar);
|
||||||
|
|
||||||
// Aktion: Erste Datei in Excel <20>ffnen
|
// Aktion: Erste Datei in Excel <20>ffnen
|
||||||
openInExcelItem.addActionListener(e -> {
|
mergeAction.addActionListener(e -> {
|
||||||
if (file1 != null) {
|
mergeFiles(config, masterFile, clientFile);
|
||||||
try {
|
|
||||||
Desktop.getDesktop().open(file1);
|
|
||||||
} catch (IOException ex) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Fehler beim <20>ffnen der Datei in Excel.", "Fehler",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "Bitte w<>hle zuerst eine Datei aus!", "Fehler",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
add(mainPanel);
|
||||||
|
pack();
|
||||||
|
setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String selectFile(JFileChooser fileChooser) {
|
||||||
|
File result = fileChooser.getSelectedFile();
|
||||||
|
return FilenameUtils.separatorsToUnix(result.getAbsolutePath());
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mergeFiles(LcagProperties pConfig, String pMasterFilePathPattern, String pClientFilePathPattern) {
|
||||||
|
Pattern masterPattern = Pattern.compile(pMasterFilePathPattern);
|
||||||
|
List<Path> masterFiles = new ArrayList<>();
|
||||||
|
String masterDirectoryPathStr = masterDirecory.getAbsolutePath();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Path masterDirectoryPath = Path.of(masterDirectoryPathStr);
|
||||||
|
masterFiles = Files.walk(masterDirectoryPath).filter(p -> {
|
||||||
|
String filePath = FilenameUtils.separatorsToUnix(p.toString());
|
||||||
|
String fileName = LcagFileTools.getName(p.toString());
|
||||||
|
|
||||||
|
Matcher matcher = masterPattern.matcher(fileName);
|
||||||
|
boolean matches = matcher.matches();
|
||||||
|
return matches;
|
||||||
|
}).toList();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pConfig == null) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Pls select at least a config file!", "Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Path aMasterFilePath : masterFiles) {
|
||||||
|
String masterFileName = aMasterFilePath.getFileName().toString();
|
||||||
|
String fileType = LcagFileTools.getExtension(masterFileName);
|
||||||
|
|
||||||
|
if (!SUPPORTED_FILE_TYPES.contains(fileType)) {
|
||||||
|
System.err.printf("Comparision of file type %s not supported for %s\n", fileType, masterFileName);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
String s = FilenameUtils.separatorsToUnix(aMasterFilePath.normalize().toString());
|
||||||
|
|
||||||
|
String clientFilePathStr = clientDirecory.getAbsolutePath() + "/"
|
||||||
|
+ masterFileName.replaceFirst(pMasterFilePathPattern, pClientFilePathPattern);
|
||||||
|
Path clientFilePath = Path.of(clientFilePathStr);
|
||||||
|
String clientDirString = null;
|
||||||
|
|
||||||
|
if (clientFilePath.isAbsolute()) {
|
||||||
|
clientDirString = clientFilePath.getParent().toString();
|
||||||
|
} else {
|
||||||
|
// client file is relative expect it is same directory as master
|
||||||
|
Path dirPath = aMasterFilePath.getParent();
|
||||||
|
|
||||||
|
clientDirString = "same directory as 1st file";
|
||||||
|
clientFilePath = dirPath.resolve(clientFilePath);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (clientFilePath != null) {
|
||||||
|
String fileName = clientFilePath.getFileName().toString();
|
||||||
|
clientFileLabel
|
||||||
|
.setText(String.format("<html>Selected: %s<br>in: %s</html>", fileName, clientDirString));
|
||||||
|
selectClientFile.setEnabled(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
String keyFieldString = pConfig.getProperty("list_of_keys");
|
||||||
|
|
||||||
|
List<String> keyFields = LcagStringTools.asList(keyFieldString, ",\\s*");
|
||||||
|
|
||||||
|
if (aMasterFilePath != null && clientFilePath != null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
Path resultFilePath = LcagFileTools.appendStringToFilePath(aMasterFilePath, "-merged");
|
||||||
|
String fieldMapping = pConfig.getProperty("column.mapping.main2compare");
|
||||||
|
|
||||||
|
Files.copy(aMasterFilePath, resultFilePath, StandardCopyOption.REPLACE_EXISTING);
|
||||||
|
|
||||||
|
ExcelWorkbook excel1 = new ExcelWorkbook(resultFilePath.toString());
|
||||||
|
ExcelWorkbook excel2 = new ExcelWorkbook(clientFilePath.toString());
|
||||||
|
|
||||||
|
excel1.setKeyColumns(keyFields);
|
||||||
|
excel1.read();
|
||||||
|
excel2.setKeyColumns(keyFields);
|
||||||
|
excel2.read();
|
||||||
|
|
||||||
|
excel1.setOption(keyFieldString, FRAME_HEIGHT);
|
||||||
|
|
||||||
|
if (fieldMapping != null) {
|
||||||
|
MappingTable mappingTable = new MappingTable(fieldMapping, ";", "->");
|
||||||
|
|
||||||
|
excel2.setOption(Table.OPTION_USE_MAPPING, mappingTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
WorkbookComparisonResult compareResult = excel1.compareTo(excel2);
|
||||||
|
|
||||||
|
if (compareResult.tablesAreEquals()) {
|
||||||
|
System.out.printf("RESULT: Tables %s and %s are equal.\n", resultFilePath, clientFilePath);
|
||||||
|
} else {
|
||||||
|
ExcelWorkbook integratedTable = (ExcelWorkbook) compareResult.integrateDifferencesIntoMaster();
|
||||||
|
|
||||||
|
integratedTable.save();
|
||||||
|
|
||||||
|
Desktop.getDesktop().open(resultFilePath.toFile());
|
||||||
|
}
|
||||||
|
} catch (IOException ex) {
|
||||||
|
JOptionPane.showMessageDialog(this, "Cannot open comparison result file.", "Error",
|
||||||
|
JOptionPane.ERROR_MESSAGE);
|
||||||
|
} catch (ConfigurationException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path getPath(LcagProperties config, String pProperty, File pMasterFile) {
|
||||||
|
Path result = null;
|
||||||
|
String filePathString = (pMasterFile == null) ? config.getProperty(pProperty) : pMasterFile.getAbsolutePath();
|
||||||
|
|
||||||
|
if (!LcagStringTools.isEmpty(filePathString)) {
|
||||||
|
result = Path.of(filePathString);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Path renameFile(String pFile, JLabel label, String prefix) {
|
||||||
|
Path newPath = null;
|
||||||
|
if (pFile == null)
|
||||||
|
return newPath;
|
||||||
|
|
||||||
|
File file = new File(pFile.toString());
|
||||||
|
String newName = JOptionPane.showInputDialog(this, "Enter new name:", file.getName());
|
||||||
|
|
||||||
|
if (!LcagStringTools.isEmpty(newName)) {
|
||||||
|
Path filePath = Path.of(pFile);
|
||||||
|
newPath = filePath.getParent().resolve(newName);
|
||||||
|
|
||||||
|
File newFile = new File(newPath.toString());
|
||||||
|
if (file.renameTo(newFile)) {
|
||||||
|
file = newFile;
|
||||||
|
label.setText(prefix + ": " + newFile.getName());
|
||||||
|
if (prefix.equals("Datei 1"))
|
||||||
|
this.masterFile = newPath.toString();
|
||||||
|
else
|
||||||
|
this.clientFile = newPath.toString();
|
||||||
|
} else {
|
||||||
|
JOptionPane.showMessageDialog(this, "Umbenennung fehlgeschlagen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return newPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
|
String cfgFileDirectory = args.length < 1 ? System.getenv("_MY_DATA") + "/Tools" : args[0];
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
SwingUtilities.invokeLater(() -> {
|
||||||
FileActions gui = new FileActions();
|
FileActions gui = new FileActions();
|
||||||
|
|
||||||
|
gui.configFileDirectoryPath = new File(cfgFileDirectory);
|
||||||
gui.setVisible(true);
|
gui.setVisible(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,340 +0,0 @@
|
|||||||
package application;
|
|
||||||
|
|
||||||
import java.awt.BorderLayout;
|
|
||||||
import java.awt.Desktop;
|
|
||||||
import java.awt.Dimension;
|
|
||||||
import java.awt.GridLayout;
|
|
||||||
import java.awt.event.ActionEvent;
|
|
||||||
import java.awt.event.KeyEvent;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
|
||||||
import javax.swing.BorderFactory;
|
|
||||||
import javax.swing.JButton;
|
|
||||||
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.JPopupMenu;
|
|
||||||
import javax.swing.KeyStroke;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
|
||||||
|
|
||||||
import de.lcag.common.ExcelWorkbook;
|
|
||||||
import de.lcag.common.LcagProperties;
|
|
||||||
import de.lcag.common.MappingTable;
|
|
||||||
import de.lcag.common.WorkbookComparisonResult;
|
|
||||||
import routines.LcagFileTools;
|
|
||||||
import routines.LcagStringTools;
|
|
||||||
|
|
||||||
public class FileActionsV3 extends JFrame {
|
|
||||||
private static final int FRAME_HEIGHT = 150;
|
|
||||||
private static String MASTER_FILE_LABEL = "Main Excel File";
|
|
||||||
private static String CONFIG_FILE_LABEL = "Configuration File";
|
|
||||||
|
|
||||||
private JLabel masterFileLabel, clientFileLabel, configFileLabel;
|
|
||||||
private JButton selectMasterFile, selectClientFile, selectConfigFile;
|
|
||||||
private Path masterFile, clientFile, configFile;
|
|
||||||
private JMenuBar menuBar;
|
|
||||||
private JMenu actionsMenu;
|
|
||||||
private JMenuItem mergeAction;
|
|
||||||
private JPopupMenu contextMenuMasterFile, contextMenuClientFile;
|
|
||||||
private File configFileDirectoryPath = null;
|
|
||||||
private LcagProperties config = null;
|
|
||||||
private File masterDirecory = null;
|
|
||||||
|
|
||||||
public FileActionsV3() {
|
|
||||||
setTitle("Compare 2 Excel Files");
|
|
||||||
setSize(800, FRAME_HEIGHT);
|
|
||||||
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
|
|
||||||
JPanel mainPanel = new JPanel(new BorderLayout());
|
|
||||||
JPanel leftButtonPanel = new JPanel(new GridLayout(3, 1, 5, 5));
|
|
||||||
JPanel rightTextPanel = new JPanel(new GridLayout(3, 1, 5, 5));
|
|
||||||
// setLayout(new GridLayout(4, 2));
|
|
||||||
|
|
||||||
leftButtonPanel.setPreferredSize(new Dimension(200, FRAME_HEIGHT)); // Fixed width
|
|
||||||
|
|
||||||
// Add an empty border to create a gap on the right side of leftPanel
|
|
||||||
leftButtonPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); // right gap: 10px
|
|
||||||
|
|
||||||
rightTextPanel.setPreferredSize(new Dimension(500, FRAME_HEIGHT));
|
|
||||||
mainPanel.add(leftButtonPanel, BorderLayout.WEST);
|
|
||||||
mainPanel.add(rightTextPanel, BorderLayout.EAST);
|
|
||||||
|
|
||||||
configFileLabel = new JLabel(String.format(" %s: Not selected", CONFIG_FILE_LABEL));
|
|
||||||
|
|
||||||
selectConfigFile = new JButton("Select " + CONFIG_FILE_LABEL);
|
|
||||||
leftButtonPanel.add(selectConfigFile);
|
|
||||||
rightTextPanel.add(configFileLabel);
|
|
||||||
|
|
||||||
// File Chooser for config file
|
|
||||||
selectConfigFile.setEnabled(true);
|
|
||||||
selectConfigFile.addActionListener(e -> {
|
|
||||||
if (!configFileDirectoryPath.isDirectory()) {
|
|
||||||
System.err.println(String.format("ERROR: Config directory %s does not exist",
|
|
||||||
configFileDirectoryPath.getAbsolutePath()));
|
|
||||||
System.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
JFileChooser fileChooser = new JFileChooser(configFileDirectoryPath);
|
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Config Files", "properties");
|
|
||||||
fileChooser.setFileFilter(filter);
|
|
||||||
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
||||||
String clientDirString = null;
|
|
||||||
|
|
||||||
configFile = selectFile(fileChooser);
|
|
||||||
config = new LcagProperties(configFile.toString());
|
|
||||||
|
|
||||||
configFileLabel.setText(String.format(" %s: %s", CONFIG_FILE_LABEL, configFile));
|
|
||||||
|
|
||||||
masterFile = config.getOptionalFilePathProperty("main_file");
|
|
||||||
clientFile = config.getOptionalFilePathProperty("compare_file");
|
|
||||||
|
|
||||||
if (clientFile.isAbsolute()) {
|
|
||||||
clientDirString = clientFile.getParent().toString();
|
|
||||||
} else {
|
|
||||||
// client file is relative expect it is same directory as master
|
|
||||||
Path dirPath = masterFile.getParent();
|
|
||||||
|
|
||||||
clientDirString = "same directory as 1st file";
|
|
||||||
clientFile = dirPath.resolve(clientFile);
|
|
||||||
}
|
|
||||||
|
|
||||||
// After user selected a config file enable buttons to set files to compare (can
|
|
||||||
// overwrite files listed in config file):
|
|
||||||
selectMasterFile.setEnabled(true);
|
|
||||||
|
|
||||||
if (clientFile != null) {
|
|
||||||
String fileName = clientFile.getFileName().toString();
|
|
||||||
clientFileLabel
|
|
||||||
.setText(String.format("<html>Selected: %s<br>in: %s</html>", fileName, clientDirString));
|
|
||||||
selectClientFile.setEnabled(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (masterFile != null) {
|
|
||||||
String fileName = masterFile.getFileName().toString();
|
|
||||||
masterDirecory = new File(masterFile.getParent().toString());
|
|
||||||
masterFileLabel.setText(String.format("<html>Selected: %s<br>in: %s</html>", fileName,
|
|
||||||
masterFile.getParent().toString()));
|
|
||||||
selectClientFile.setEnabled(true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Kontextmen<65>s erstellen
|
|
||||||
contextMenuMasterFile = new JPopupMenu();
|
|
||||||
contextMenuClientFile = new JPopupMenu();
|
|
||||||
JMenuItem renameFile1 = new JMenuItem("Rename File");
|
|
||||||
JMenuItem renameFile2 = new JMenuItem("Rename File");
|
|
||||||
contextMenuMasterFile.add(renameFile1);
|
|
||||||
contextMenuClientFile.add(renameFile2);
|
|
||||||
|
|
||||||
masterFileLabel = new JLabel(String.format(" %s: %s", MASTER_FILE_LABEL,
|
|
||||||
masterFile == null ? "Not selected" : masterFile.getFileName()));
|
|
||||||
|
|
||||||
selectMasterFile = new JButton("Select " + MASTER_FILE_LABEL);
|
|
||||||
leftButtonPanel.add(selectMasterFile);
|
|
||||||
rightTextPanel.add(masterFileLabel);
|
|
||||||
|
|
||||||
clientFileLabel = new JLabel(String.format(" %s: %s", "Excel to compare",
|
|
||||||
clientFile == null ? "Not selected" : clientFile.getFileName()));
|
|
||||||
|
|
||||||
selectClientFile = new JButton("Select Excel to Compare");
|
|
||||||
|
|
||||||
// MouseListener f<>r Kontextmen<65> auf den Labels
|
|
||||||
masterFileLabel.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if (SwingUtilities.isRightMouseButton(e) && masterFile != null) {
|
|
||||||
contextMenuMasterFile.show(masterFileLabel, e.getX(), e.getY());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
clientFileLabel.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
if (SwingUtilities.isRightMouseButton(e) && clientFile != null) {
|
|
||||||
contextMenuClientFile.show(clientFileLabel, e.getX(), e.getY());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
leftButtonPanel.add(selectClientFile);
|
|
||||||
rightTextPanel.add(clientFileLabel);
|
|
||||||
|
|
||||||
renameFile1.addActionListener(e -> renameFile(masterFile, masterFileLabel, "Datei 1"));
|
|
||||||
renameFile2.addActionListener(e -> renameFile(clientFile, clientFileLabel, "Datei 2"));
|
|
||||||
|
|
||||||
// File Chooser f<>r Datei 1 (nur Excel-Dateien)
|
|
||||||
selectMasterFile.setEnabled(false);
|
|
||||||
selectMasterFile.addActionListener(e -> {
|
|
||||||
JFileChooser fileChooser = new JFileChooser();
|
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Files", "xls", "xlsx");
|
|
||||||
fileChooser.setFileFilter(filter);
|
|
||||||
if (masterFile != null) {
|
|
||||||
masterDirecory = new File(masterFile.getParent().toString());
|
|
||||||
fileChooser.setCurrentDirectory(masterDirecory);
|
|
||||||
}
|
|
||||||
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
||||||
masterFile = selectFile(fileChooser);
|
|
||||||
masterDirecory = new File(masterFile.getParent().toString());
|
|
||||||
masterFileLabel.setText(String.format(" %s: %s", MASTER_FILE_LABEL, masterFile.getFileName()));
|
|
||||||
selectClientFile.setEnabled(true);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// File Chooser f<>r Datei 2 (im selben Verzeichnis wie Datei 1, nur
|
|
||||||
// Excel-Dateien)
|
|
||||||
selectClientFile.setEnabled(false);
|
|
||||||
selectClientFile.addActionListener(e -> {
|
|
||||||
if (masterDirecory != null) {
|
|
||||||
JFileChooser fileChooser = new JFileChooser(masterDirecory);
|
|
||||||
FileNameExtensionFilter filter = new FileNameExtensionFilter("Excel-Dateien", "xls", "xlsx");
|
|
||||||
fileChooser.setFileFilter(filter);
|
|
||||||
if (fileChooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
|
|
||||||
clientFile = selectFile(fileChooser);
|
|
||||||
clientFileLabel.setText("Datei 2: " + clientFile.getFileName());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// Men<65> erstellen
|
|
||||||
menuBar = new JMenuBar();
|
|
||||||
actionsMenu = new JMenu("Actions");
|
|
||||||
mergeAction = new JMenuItem("Merge 2nd into Main file");
|
|
||||||
|
|
||||||
mergeAction.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, ActionEvent.CTRL_MASK));
|
|
||||||
mergeAction.addActionListener(e -> {
|
|
||||||
System.out.println("Ctrl-C pressed on menu");
|
|
||||||
});
|
|
||||||
|
|
||||||
actionsMenu.add(mergeAction);
|
|
||||||
menuBar.add(actionsMenu);
|
|
||||||
setJMenuBar(menuBar);
|
|
||||||
|
|
||||||
// Aktion: Erste Datei in Excel <20>ffnen
|
|
||||||
mergeAction.addActionListener(e -> {
|
|
||||||
mergeFiles(config, masterFile, clientFile);
|
|
||||||
});
|
|
||||||
|
|
||||||
add(mainPanel);
|
|
||||||
pack();
|
|
||||||
setVisible(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Path selectFile(JFileChooser fileChooser) {
|
|
||||||
File result = fileChooser.getSelectedFile();
|
|
||||||
return Path.of(result.getAbsolutePath());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void mergeFiles(LcagProperties pConfig, Path pMasterFilePath, Path pClientFilePath) {
|
|
||||||
if (pConfig != null) {
|
|
||||||
String keyFieldString = pConfig.getProperty("list_of_keys");
|
|
||||||
|
|
||||||
List<String> keyFields = LcagStringTools.asList(keyFieldString, ",\\s*");
|
|
||||||
|
|
||||||
if (pMasterFilePath != null && pClientFilePath != null)
|
|
||||||
try {
|
|
||||||
String masterFileName = pMasterFilePath.getFileName().toString();
|
|
||||||
Path resultFilePath = LcagFileTools.appendStringToFilePath(pMasterFilePath, "-merged");
|
|
||||||
String fieldMapping = pConfig.getProperty("column.mapping.main2compare");
|
|
||||||
|
|
||||||
Files.copy(pMasterFilePath, resultFilePath, StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
|
|
||||||
ExcelWorkbook excel1 = new ExcelWorkbook(resultFilePath.toString());
|
|
||||||
ExcelWorkbook excel2 = new ExcelWorkbook(pClientFilePath.toString());
|
|
||||||
|
|
||||||
excel1.setKeyColumns(keyFields);
|
|
||||||
excel1.read();
|
|
||||||
excel2.setKeyColumns(keyFields);
|
|
||||||
excel2.read();
|
|
||||||
|
|
||||||
excel1.setOption(keyFieldString, FRAME_HEIGHT);
|
|
||||||
|
|
||||||
if (fieldMapping != null) {
|
|
||||||
MappingTable mappingTable = new MappingTable(fieldMapping, ";", "->");
|
|
||||||
|
|
||||||
excel2.setOption(mappingTable);
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkbookComparisonResult compareResult = excel1.compareTo(excel2);
|
|
||||||
|
|
||||||
ExcelWorkbook integratedTable = (ExcelWorkbook) compareResult.integrateDifferencesIntoMaster();
|
|
||||||
|
|
||||||
integratedTable.save();
|
|
||||||
|
|
||||||
Desktop.getDesktop().open(resultFilePath.toFile());
|
|
||||||
} catch (IOException ex) {
|
|
||||||
JOptionPane.showMessageDialog(this, "Cannot open comparison result file.", "Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
} catch (ConfigurationException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "Pls select at least a config file!", "Error",
|
|
||||||
JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Path getPath(LcagProperties config, String pProperty, File pMasterFile) {
|
|
||||||
Path result = null;
|
|
||||||
String filePathString = (pMasterFile == null) ? config.getProperty(pProperty) : pMasterFile.getAbsolutePath();
|
|
||||||
|
|
||||||
if (!LcagStringTools.isEmpty(filePathString)) {
|
|
||||||
result = Path.of(filePathString);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Path renameFile(Path pFile, JLabel label, String prefix) {
|
|
||||||
Path newPath = null;
|
|
||||||
if (pFile == null)
|
|
||||||
return newPath;
|
|
||||||
|
|
||||||
File file = new File(pFile.toString());
|
|
||||||
String newName = JOptionPane.showInputDialog(this, "Enter new name:", file.getName());
|
|
||||||
|
|
||||||
if (!LcagStringTools.isEmpty(newName)) {
|
|
||||||
newPath = pFile.getParent().resolve(newName);
|
|
||||||
|
|
||||||
File newFile = new File(newPath.toString());
|
|
||||||
if (file.renameTo(newFile)) {
|
|
||||||
file = newFile;
|
|
||||||
label.setText(prefix + ": " + newFile.getName());
|
|
||||||
if (prefix.equals("Datei 1"))
|
|
||||||
this.masterFile = newPath;
|
|
||||||
else
|
|
||||||
this.clientFile = newPath;
|
|
||||||
} else {
|
|
||||||
JOptionPane.showMessageDialog(this, "Umbenennung fehlgeschlagen!", "Fehler", JOptionPane.ERROR_MESSAGE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return newPath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String cfgFileDirectory = args.length < 1 ? System.getenv("_MY_DATA") + "/Tools" : args[1];
|
|
||||||
|
|
||||||
SwingUtilities.invokeLater(() -> {
|
|
||||||
FileActionsV3 gui = new FileActionsV3();
|
|
||||||
|
|
||||||
gui.configFileDirectoryPath = new File(cfgFileDirectory);
|
|
||||||
gui.setVisible(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -50,6 +50,7 @@ public abstract class AbstractTable implements Table {
|
|||||||
|
|
||||||
private PositionOrderedMap<String, TableColumn> rowMap = new PositionOrderedMap<String, TableColumn>();
|
private PositionOrderedMap<String, TableColumn> rowMap = new PositionOrderedMap<String, TableColumn>();
|
||||||
private Set<String> keyColumns = new ListOrderedSet<>();
|
private Set<String> keyColumns = new ListOrderedSet<>();
|
||||||
|
private Set<String> nonKeyColumnNames = null;
|
||||||
private List<String> wantedColumns = new ArrayList<>();
|
private List<String> wantedColumns = new ArrayList<>();
|
||||||
private List<String> excludedColumns = new ArrayList<>();
|
private List<String> excludedColumns = new ArrayList<>();
|
||||||
protected Map<String, Object> options = new HashMap<>();
|
protected Map<String, Object> options = new HashMap<>();
|
||||||
@@ -61,7 +62,7 @@ public abstract class AbstractTable implements Table {
|
|||||||
|
|
||||||
public class ListColumn implements TableColumn {
|
public class ListColumn implements TableColumn {
|
||||||
List<Object> data = new ArrayList<>();
|
List<Object> data = new ArrayList<>();
|
||||||
private Object defaultValue = null;
|
private static Object defaultValue = null;
|
||||||
private String style = "";
|
private String style = "";
|
||||||
|
|
||||||
public ListColumn() {
|
public ListColumn() {
|
||||||
@@ -80,6 +81,11 @@ public abstract class AbstractTable implements Table {
|
|||||||
data.add(v);
|
data.add(v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getDefaultValue() {
|
||||||
|
return defaultValue;
|
||||||
|
}
|
||||||
|
|
||||||
public Object getValue(int i) {
|
public Object getValue(int i) {
|
||||||
Object result = null;
|
Object result = null;
|
||||||
int n = data.size();
|
int n = data.size();
|
||||||
@@ -96,6 +102,12 @@ public abstract class AbstractTable implements Table {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String aggregate(String pSeparator) {
|
||||||
|
String result = LcagStringTools.joinIgnoreNull(pSeparator, this.data);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public void setValue(int rowNo, Object v) {
|
public void setValue(int rowNo, Object v) {
|
||||||
int n = this.data.size();
|
int n = this.data.size();
|
||||||
|
|
||||||
@@ -339,6 +351,12 @@ public abstract class AbstractTable implements Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setCellValue(int row, int pColumnNumber, Object v) {
|
||||||
|
String colName = this.getColumnNameByPosition(pColumnNumber);
|
||||||
|
|
||||||
|
this.setCellValue(row, colName, v);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setCellValue(int row, String colName, Object v) {
|
public void setCellValue(int row, String colName, Object v) {
|
||||||
TableColumn col = getColumnByLabel(colName);
|
TableColumn col = getColumnByLabel(colName);
|
||||||
@@ -385,8 +403,14 @@ public abstract class AbstractTable implements Table {
|
|||||||
@Override
|
@Override
|
||||||
public <V> V getCellValue(int row, String colLabel) {
|
public <V> V getCellValue(int row, String colLabel) {
|
||||||
TableColumn col = getColumnByLabel(colLabel);
|
TableColumn col = getColumnByLabel(colLabel);
|
||||||
|
V result = null;
|
||||||
|
|
||||||
V result = col.getValue(row);
|
if (col == null) {
|
||||||
|
// FIXME: Shall throw a TableColumnException (bigger impact)
|
||||||
|
log.fatal("Column '%s' does not exist in %s", colLabel, this.getName());
|
||||||
|
} else {
|
||||||
|
result = col.getValue(row);
|
||||||
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -533,7 +557,7 @@ public abstract class AbstractTable implements Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!colNames.containsKey(colUniqueName)) {
|
if (!colNames.containsKey(colUniqueName)) {
|
||||||
int noItems = pColumn.length();
|
int noNewColumnRecords = pColumn.length();
|
||||||
|
|
||||||
if (col.length > 1) {
|
if (col.length > 1) {
|
||||||
pColumn.setStyle(col[1]);
|
pColumn.setStyle(col[1]);
|
||||||
@@ -553,11 +577,20 @@ public abstract class AbstractTable implements Table {
|
|||||||
rowMap.toString();
|
rowMap.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.noRows < noItems) {
|
//FIXME: Next block may need corrections: Not all cells become initialized.
|
||||||
this.noRows = noItems;
|
if (this.noRows < noNewColumnRecords) {
|
||||||
|
// New column has more entries than the table has rows => increase number of rows in table rows
|
||||||
|
this.noRows = noNewColumnRecords;
|
||||||
|
} else {
|
||||||
|
// Table has likely more rows then the new column (e.g. when adding an empty column) => init the new column with default value so it has the same number of value
|
||||||
|
Object v = pColumn.getDefaultValue();
|
||||||
|
for (int i = noNewColumnRecords; i < this.noRows; i++) {
|
||||||
|
pColumn.addValue(v);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
return colPosResult;
|
return colPosResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -606,17 +639,14 @@ public abstract class AbstractTable implements Table {
|
|||||||
@Override
|
@Override
|
||||||
public TableColumn getColumnByLabel(String pFormattedColName) {
|
public TableColumn getColumnByLabel(String pFormattedColName) {
|
||||||
String colName = pFormattedColName.split(PARAMETER_STYLE)[0];
|
String colName = pFormattedColName.split(PARAMETER_STYLE)[0];
|
||||||
|
TableColumn result = this.rowMap.get(getColumnNameByLabel(colName));
|
||||||
MappingTable mapping = getOption(OPTION_USE_MAPPING);
|
MappingTable mapping = getOption(OPTION_USE_MAPPING);
|
||||||
|
|
||||||
if (mapping != null) {
|
if (mapping != null) {
|
||||||
String mappedName = mapping.getColumnLableFor(colName);
|
String colLabel = mapping.getColumnLableFor(colName);
|
||||||
|
result = this.rowMap.get(getColumnNameByLabel(colLabel));
|
||||||
if (mappedName != null)
|
|
||||||
colName = mappedName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TableColumn result = this.rowMap.get(getColumnNameByLabel(colName));
|
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -627,6 +657,17 @@ public abstract class AbstractTable implements Table {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String aggregateColumn(String pColName, String pSeparator) {
|
||||||
|
String result = "";
|
||||||
|
ListColumn col = (ListColumn) this.getColumnByLabel(getColumnNameByLabel(pColName));
|
||||||
|
|
||||||
|
if (col != null) {
|
||||||
|
result = col.aggregate(pSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
public String asCsvData(TableColumn pOutputOrdering) {
|
public String asCsvData(TableColumn pOutputOrdering) {
|
||||||
String result = "";
|
String result = "";
|
||||||
boolean numberRows = this.optionIsSet(OPTION_NUMBER_ROWS);
|
boolean numberRows = this.optionIsSet(OPTION_NUMBER_ROWS);
|
||||||
@@ -797,33 +838,20 @@ public abstract class AbstractTable implements Table {
|
|||||||
return asHTML(null);
|
return asHTML(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int createHeaderRow(Collection<String> colNames) {
|
|
||||||
int noColumnsCreated = 0;
|
|
||||||
|
|
||||||
for (String colName : colNames) {
|
|
||||||
if (this.colNames.get(colName) == null) {
|
|
||||||
this.addColumn(colName);
|
|
||||||
|
|
||||||
noColumnsCreated += 1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return noColumnsCreated;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void append(Table pSrcTable) {
|
public void append(Table pSrcTable) {
|
||||||
int noRows = pSrcTable.lenght();
|
int noRows = pSrcTable.lenght();
|
||||||
Collection<String> colNames = pSrcTable.getColumnNames();
|
Collection<String> colNames = pSrcTable.getColumnNames();
|
||||||
|
|
||||||
createHeaderRow(colNames);
|
for (int rowNo = pSrcTable.getFirstRowNo(); rowNo < noRows; rowNo++) {
|
||||||
|
|
||||||
int firstRowNoInSrcTable = pSrcTable.getFirstRowNo();
|
|
||||||
for (int rowNo = firstRowNoInSrcTable; rowNo < noRows; rowNo++) {
|
|
||||||
int newRowNo = this.newRow();
|
int newRowNo = this.newRow();
|
||||||
|
|
||||||
for (String colName : colNames) {
|
for (String colName : colNames) {
|
||||||
Object value = pSrcTable.getCellValue(rowNo, colName);
|
Object value = pSrcTable.getCellValue(rowNo, colName);
|
||||||
|
|
||||||
|
if (rowNo == 0 && this.colNames.get(colName) == null) {
|
||||||
|
this.addColumn(colName);
|
||||||
|
}
|
||||||
|
|
||||||
this.setCellValue(newRowNo, colName, value);
|
this.setCellValue(newRowNo, colName, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -905,6 +933,7 @@ public abstract class AbstractTable implements Table {
|
|||||||
|
|
||||||
protected void setKeyColumns(List<String> pKeyColumns) {
|
protected void setKeyColumns(List<String> pKeyColumns) {
|
||||||
this.keyColumn = new KeyColumn();
|
this.keyColumn = new KeyColumn();
|
||||||
|
this.nonKeyColumnNames = null;
|
||||||
|
|
||||||
for (String s : pKeyColumns) {
|
for (String s : pKeyColumns) {
|
||||||
this.keyColumns.add(s);
|
this.keyColumns.add(s);
|
||||||
@@ -981,6 +1010,19 @@ public abstract class AbstractTable implements Table {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Set<String> getNonKeyColumnNames() {
|
||||||
|
if (this.nonKeyColumnNames == null) {
|
||||||
|
nonKeyColumnNames = new ListOrderedSet<String>();
|
||||||
|
|
||||||
|
nonKeyColumnNames.addAll(this.getColumnNames());
|
||||||
|
nonKeyColumnNames.removeAll(this.keyColumns);
|
||||||
|
|
||||||
|
nonKeyColumnNames.removeAll(this.keyColumns);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.nonKeyColumnNames;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String setUniqueKeyValue(int pRow) {
|
public String setUniqueKeyValue(int pRow) {
|
||||||
String resultKeyValue = calculateKeyFromColumns(pRow, this.keyColumns);
|
String resultKeyValue = calculateKeyFromColumns(pRow, this.keyColumns);
|
||||||
@@ -995,7 +1037,9 @@ public abstract class AbstractTable implements Table {
|
|||||||
Integer existingKeyValue = this.getRowByKey(resultKeyValue);
|
Integer existingKeyValue = this.getRowByKey(resultKeyValue);
|
||||||
|
|
||||||
if (existingKeyValue != null) {
|
if (existingKeyValue != null) {
|
||||||
resultKeyValue = calculateKeyFromColumns(pRow, this.getColumnNames());
|
Set<String> nonKeyColumnNames = this.getNonKeyColumnNames();
|
||||||
|
|
||||||
|
resultKeyValue = resultKeyValue + "_" + calculateKeyFromColumns(pRow, nonKeyColumnNames);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.keyColumn.setValue(pRow, resultKeyValue);
|
this.keyColumn.setValue(pRow, resultKeyValue);
|
||||||
@@ -1032,7 +1076,8 @@ public abstract class AbstractTable implements Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public String getColumnNameByLabel(String pStyledColName) {
|
public String getColumnNameByLabel(String pStyledColName) {
|
||||||
String colName = pStyledColName.split(PARAMETER_STYLE)[0];
|
final String[] split = pStyledColName.split(PARAMETER_STYLE);
|
||||||
|
String colName = split[0];
|
||||||
|
|
||||||
return colName.toUpperCase();
|
return colName.toUpperCase();
|
||||||
}
|
}
|
||||||
@@ -1056,7 +1101,9 @@ public abstract class AbstractTable implements Table {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public int getColumnPosition(TableColumn pCol) {
|
public int getColumnPosition(TableColumn pCol) {
|
||||||
return this.rowMap.getPositionOfValue(pCol);
|
final Integer positionOfValue = this.rowMap.getPositionOfValue(pCol);
|
||||||
|
|
||||||
|
return positionOfValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1164,10 +1211,6 @@ public abstract class AbstractTable implements Table {
|
|||||||
} else if (cmpValue instanceof String && !(thisValue instanceof String)) {
|
} else if (cmpValue instanceof String && !(thisValue instanceof String)) {
|
||||||
thisValue = thisValue.toString();
|
thisValue = thisValue.toString();
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
result.addCellDifference(thisKey, n, colName, cmpRowNo, colName);
|
|
||||||
rowsAreEqual = false;
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Objects.deepEquals(thisValue, cmpValue)) {
|
if (!Objects.deepEquals(thisValue, cmpValue)) {
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ import org.apache.poi.ss.util.CellRangeAddress;
|
|||||||
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
import org.apache.poi.xssf.usermodel.XSSFSheet;
|
||||||
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
||||||
|
|
||||||
import de.lcag.common.ExcelWorkbook.ExcelTable.ExcelColumn;
|
|
||||||
import de.lcag.common.TableComparisonResult.CellPair;
|
import de.lcag.common.TableComparisonResult.CellPair;
|
||||||
import routines.LcagGeneral;
|
import routines.LcagGeneral;
|
||||||
import routines.LcagLogger;
|
import routines.LcagLogger;
|
||||||
@@ -59,6 +58,7 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
private static String dateFormatString = "yyyy-MM-dd";
|
private static String dateFormatString = "yyyy-MM-dd";
|
||||||
private FormulaEvaluator evaluator = null;
|
private FormulaEvaluator evaluator = null;
|
||||||
private CreationHelper factory = null;
|
private CreationHelper factory = null;
|
||||||
|
private String name = null;
|
||||||
|
|
||||||
// Map styles as Excel limits to 64000:
|
// Map styles as Excel limits to 64000:
|
||||||
private HashMap<Object, CellStyle> styleMap = new HashMap<>();
|
private HashMap<Object, CellStyle> styleMap = new HashMap<>();
|
||||||
@@ -134,6 +134,11 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
return ExcelTable.this.shiftColumns(columnPosition);
|
return ExcelTable.this.shiftColumns(columnPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getDefaultValue() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getValue(int pRowNumber) {
|
public Object getValue(int pRowNumber) {
|
||||||
Object result = null;
|
Object result = null;
|
||||||
@@ -307,8 +312,7 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
// TODO Auto-generated method stub
|
return ExcelWorkbook.this.getName() + "." + sheet.getSheetName();
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -348,8 +352,16 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
srcColumnNames.add(colName);
|
srcColumnNames.add(colName);
|
||||||
|
|
||||||
if (useColumn(colName)) {
|
if (useColumn(colName)) {
|
||||||
|
int colDublicateNo = 1;
|
||||||
|
String newColname = colName;
|
||||||
ExcelColumn col = new ExcelColumn();
|
ExcelColumn col = new ExcelColumn();
|
||||||
this.addColumn(colName, col);
|
|
||||||
|
// Add the new column to the table. Number column name if the same name already
|
||||||
|
// exists.
|
||||||
|
while (this.addColumn(newColname, col) < 0) {
|
||||||
|
colDublicateNo += 1;
|
||||||
|
newColname = colName + "_" + colDublicateNo;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -434,29 +446,18 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int addColumn(String pStyledColumnLabel, TableColumn pColumn, String pAfterColumnNamed) {
|
public int addColumn(String pStyledColumnLabel, TableColumn pColumn, String pAfterColumnNamed) {
|
||||||
int firstRowNo = 0;
|
|
||||||
Row r = sheet.getRow(firstRowNo);
|
|
||||||
|
|
||||||
if (r == null)
|
|
||||||
sheet.createRow(firstRowNo);
|
|
||||||
|
|
||||||
int colPos = super.addColumn(pStyledColumnLabel, pColumn, pAfterColumnNamed);
|
int colPos = super.addColumn(pStyledColumnLabel, pColumn, pAfterColumnNamed);
|
||||||
|
|
||||||
pColumn.setValue(firstRowNo, pStyledColumnLabel);
|
if (colPos >= 0)
|
||||||
|
pColumn.setValue(0, pStyledColumnLabel);
|
||||||
return colPos;
|
return colPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addColumnAtPosition(String pStyledColumnLabel, TableColumn pColumn, int pColumnPosition) {
|
public void addColumnAtPosition(String pStyledColumnLabel, TableColumn pColumn, int pColumnPosition) {
|
||||||
int firstRowNo = 0;
|
|
||||||
Row r = sheet.getRow(firstRowNo);
|
|
||||||
|
|
||||||
if (r == null)
|
|
||||||
sheet.createRow(firstRowNo);
|
|
||||||
|
|
||||||
super.addColumnAtPosition(pStyledColumnLabel, pColumn, pColumnPosition);
|
super.addColumnAtPosition(pStyledColumnLabel, pColumn, pColumnPosition);
|
||||||
|
|
||||||
pColumn.setValue(firstRowNo, pStyledColumnLabel);
|
pColumn.setValue(0, pStyledColumnLabel);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void colorizeRow(int pRowNo, int noCells, IndexedColors pColor) {
|
private void colorizeRow(int pRowNo, int noCells, IndexedColors pColor) {
|
||||||
@@ -662,10 +663,11 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, ExcelTable> tables = new LinkedHashMap<>();
|
Map<String, AbstractTable> tables = new LinkedHashMap<>();
|
||||||
|
|
||||||
public ExcelWorkbook(String aFilePath, String... pColumnNameList) throws InvalidFormatException, IOException {
|
public ExcelWorkbook(String aFilePath, String... pColumnNameList) throws InvalidFormatException, IOException {
|
||||||
this.filePath = AbstractTable.resolveFilePath(aFilePath, new HashMap<String, Object>());
|
this.filePath = AbstractTable.resolveFilePath(aFilePath, new HashMap<String, Object>());
|
||||||
|
this.name = this.filePath.getFileName().toString();
|
||||||
|
|
||||||
workbook = new XSSFWorkbook();
|
workbook = new XSSFWorkbook();
|
||||||
XSSFSheet sheet = workbook.createSheet("Table1");
|
XSSFSheet sheet = workbook.createSheet("Table1");
|
||||||
@@ -684,6 +686,7 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
|
|
||||||
public ExcelWorkbook(String aFilePath, Map<String, Object> pParams) {
|
public ExcelWorkbook(String aFilePath, Map<String, Object> pParams) {
|
||||||
this.filePath = AbstractTable.resolveFilePath(aFilePath, pParams);
|
this.filePath = AbstractTable.resolveFilePath(aFilePath, pParams);
|
||||||
|
this.name = this.filePath.getFileName().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExcelWorkbook(String aFilePath) {
|
public ExcelWorkbook(String aFilePath) {
|
||||||
@@ -699,8 +702,19 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
return filePath;
|
return filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Sheet getSheet(String pSheetName) {
|
public List<String> getSheetNames() {
|
||||||
return workbook.getSheet(pSheetName);
|
List<String> result = new ArrayList<>();
|
||||||
|
int n = workbook.getNumberOfSheets();
|
||||||
|
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
result.add(workbook.getSheetName(i));
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public AbstractTable getSheet(String pSheetName) {
|
||||||
|
return tables.get(pSheetName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExcelTable addSheet(String pSheetName) {
|
public ExcelTable addSheet(String pSheetName) {
|
||||||
@@ -710,6 +724,16 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
return newTable;
|
return newTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public AbstractTable addSheet(String pSheetName, AbstractTable pTable) {
|
||||||
|
this.tables.put(pSheetName, pTable);
|
||||||
|
|
||||||
|
return pTable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSheet(String pSheetName, GenericComparisonResultTable pCmpResult) {
|
||||||
|
// TODO Auto-generated method stub, should add the data to a new Excel Sheet
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void saveAs(String pFilePath) throws IOException {
|
public void saveAs(String pFilePath) throws IOException {
|
||||||
File aFile = new File(pFilePath);
|
File aFile = new File(pFilePath);
|
||||||
@@ -815,13 +839,13 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ExcelColumn addColumn(String aName) {
|
public TableColumn addColumn(String aName) {
|
||||||
return getFirstTable().addColumn(aName);
|
return getFirstTable().addColumn(aName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return getFirstTable().getName();
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -835,33 +859,17 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
return getFirstTable().newRow();
|
return getFirstTable().newRow();
|
||||||
}
|
}
|
||||||
|
|
||||||
ExcelTable getFirstTable() {
|
public AbstractTable getFirstTable() {
|
||||||
ExcelTable result = firstTable;
|
AbstractTable result = firstTable;
|
||||||
|
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
String filePathString = this.filePath.toString();
|
String filePathString = this.filePath.toString();
|
||||||
File file = new File(filePathString);
|
FileInputStream inputStream;
|
||||||
XSSFWorkbook aWorkbook = null;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (file.canRead()) {
|
inputStream = new FileInputStream(new File(filePathString));
|
||||||
FileInputStream inputStream = new FileInputStream(file);
|
initWorkbook(new XSSFWorkbook(inputStream));
|
||||||
|
|
||||||
aWorkbook = new XSSFWorkbook(inputStream);
|
|
||||||
inputStream.close();
|
|
||||||
// Workbook workbook =
|
// Workbook workbook =
|
||||||
// StreamingReader.builder().rowCacheSize(100).bufferSize(4096).open(inputStream);
|
// StreamingReader.builder().rowCacheSize(100).bufferSize(4096).open(inputStream);
|
||||||
} else {
|
|
||||||
aWorkbook = new XSSFWorkbook();
|
|
||||||
|
|
||||||
aWorkbook.createSheet(EXCEL_DEFAULT_SHEET_NAME);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
// TODO Auto-generated catch block
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
initWorkbook(aWorkbook);
|
|
||||||
|
|
||||||
Sheet sheet = workbook.getSheetAt(0);
|
Sheet sheet = workbook.getSheetAt(0);
|
||||||
|
|
||||||
@@ -871,8 +879,13 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
this.tables.put(sheetName, firstTable);
|
this.tables.put(sheetName, firstTable);
|
||||||
|
|
||||||
// workbook.close();
|
// workbook.close();
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
// TODO Auto-generated catch block
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
Collection<ExcelTable> tableList = this.tables.values();
|
Collection<AbstractTable> tableList = this.tables.values();
|
||||||
result = tableList.iterator().next();
|
result = tableList.iterator().next();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -923,8 +936,8 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
|
|
||||||
public void integrateDifferences(WorkbookComparisonResult pDiff) throws IOException {
|
public void integrateDifferences(WorkbookComparisonResult pDiff) throws IOException {
|
||||||
for (String tableName : pDiff.getDifferencesPerTable().keySet()) {
|
for (String tableName : pDiff.getDifferencesPerTable().keySet()) {
|
||||||
ExcelTable myTable = this.tables.get(tableName);
|
AbstractTable myTable = this.tables.get(tableName);
|
||||||
ExcelTable cmpTable = pDiff.getClientWorkbook().tables.get(tableName);
|
AbstractTable cmpTable = pDiff.getClientWorkbook().tables.get(tableName);
|
||||||
|
|
||||||
TableComparisonResult diff = pDiff.getDifferencesPerTable().get(tableName);
|
TableComparisonResult diff = pDiff.getDifferencesPerTable().get(tableName);
|
||||||
|
|
||||||
@@ -979,7 +992,7 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxRows(int pMaxRows) {
|
public void setMaxRows(int pMaxRows) {
|
||||||
for (ExcelTable t : tables.values()) {
|
for (AbstractTable t : tables.values()) {
|
||||||
t.setMaxRows(pMaxRows);
|
t.setMaxRows(pMaxRows);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1044,8 +1057,8 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
this.compareStructureTo(result, pCmpWorkbook);
|
this.compareStructureTo(result, pCmpWorkbook);
|
||||||
|
|
||||||
for (String tableName : result.getCommonTables()) {
|
for (String tableName : result.getCommonTables()) {
|
||||||
ExcelTable myTable = this.tables.get(tableName);
|
AbstractTable myTable = this.tables.get(tableName);
|
||||||
ExcelTable cmpTable = pCmpWorkbook.tables.get(tableName);
|
AbstractTable cmpTable = pCmpWorkbook.tables.get(tableName);
|
||||||
|
|
||||||
TableComparisonResult diff = myTable.compareTo(cmpTable);
|
TableComparisonResult diff = myTable.compareTo(cmpTable);
|
||||||
|
|
||||||
@@ -1075,8 +1088,7 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void append(CsvTable csv) {
|
public void append(CsvTable csv) {
|
||||||
ExcelTable table = getFirstTable();
|
getFirstTable().append(csv);
|
||||||
table.append(csv);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -1088,8 +1100,8 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
getFirstTable().setKey(rowNo);
|
getFirstTable().setKey(rowNo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOption(MappingTable mappingTable) {
|
public void setOption(String optionUseMapping, MappingTable mappingTable) {
|
||||||
getFirstTable().setOption(Table.OPTION_USE_MAPPING, mappingTable);
|
getFirstTable().setOption(optionUseMapping, mappingTable);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1112,4 +1124,5 @@ public class ExcelWorkbook implements Table, Storage {
|
|||||||
public int getNoColumns() {
|
public int getNoColumns() {
|
||||||
return getFirstTable().getNoColumns();
|
return getFirstTable().getNoColumns();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import java.util.Set;
|
|||||||
|
|
||||||
import routines.LcagGeneral;
|
import routines.LcagGeneral;
|
||||||
|
|
||||||
public class GenericComparisonResultTable extends HashTable {
|
public class GenericComparisonResultTable extends ExcelHashTable {
|
||||||
public static final String FILE_PATH_COLUMN = "FilePath";
|
public static final String FILE_PATH_COLUMN = "FilePath";
|
||||||
public static final String SOURCE_ROW_NUMBER_COLUMN = "Src_RowNo";
|
public static final String SOURCE_ROW_NUMBER_COLUMN = "Src_RowNo";
|
||||||
public static final String COMPARE_ROW_NUMBER_COLUMN = "Cmp_RowNo";
|
public static final String COMPARE_ROW_NUMBER_COLUMN = "Cmp_RowNo";
|
||||||
@@ -27,6 +27,16 @@ public class GenericComparisonResultTable extends HashTable {
|
|||||||
compareTables();
|
compareTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericComparisonResultTable(ExcelWorkbook pSrcTable, ExcelWorkbook pCmpTable) {
|
||||||
|
super(KEY_COLUMN, SOURCE_ROW_NUMBER_COLUMN, COMPARE_ROW_NUMBER_COLUMN, COLUMN_NAME_COLUMN, SOURCE_VALUE_COLUMN,
|
||||||
|
COMPARE_VALUE_COLUMN, SOURCE_COLUMN_NUMBER_COLUMN, COMPARE_COLUMN_NUMBER_COLUMN);
|
||||||
|
|
||||||
|
this.sourceTable = pSrcTable.getFirstTable();
|
||||||
|
this.compareTable = pCmpTable.getFirstTable();
|
||||||
|
|
||||||
|
compareTables();
|
||||||
|
}
|
||||||
|
|
||||||
private void compareTables() {
|
private void compareTables() {
|
||||||
int noRows = sourceTable.lenght();
|
int noRows = sourceTable.lenght();
|
||||||
Set<String> columnNames = sourceTable.getColumnNames();
|
Set<String> columnNames = sourceTable.getColumnNames();
|
||||||
|
|||||||
@@ -19,6 +19,14 @@ public class GenericTable extends HashTable {
|
|||||||
convertToGenericTable();
|
convertToGenericTable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GenericTable(ExcelWorkbook pSrcTable) {
|
||||||
|
super(KEY_COLUMN, ROW_NUMBER_COLUMN, COLUMN_NUMBER_COLUMN, COLUMN_NAME_COLUMN, COLUMN_VALUE_COLUMN);
|
||||||
|
|
||||||
|
this.sourceTable = pSrcTable.getFirstTable();
|
||||||
|
|
||||||
|
convertToGenericTable();
|
||||||
|
}
|
||||||
|
|
||||||
private void convertToGenericTable() {
|
private void convertToGenericTable() {
|
||||||
AbstractTable srcTable = this.sourceTable;
|
AbstractTable srcTable = this.sourceTable;
|
||||||
int noRows = srcTable.lenght();
|
int noRows = srcTable.lenght();
|
||||||
|
|||||||
@@ -29,6 +29,8 @@ public interface Table {
|
|||||||
|
|
||||||
public <V> V getValue(int i);
|
public <V> V getValue(int i);
|
||||||
|
|
||||||
|
public <V> V getDefaultValue();
|
||||||
|
|
||||||
public void setValue(int rowNo, Object v);
|
public void setValue(int rowNo, Object v);
|
||||||
|
|
||||||
public int length();
|
public int length();
|
||||||
|
|||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package de.lcag.common;
|
||||||
|
|
||||||
|
// TODO Not yet used. In future use it if a table column cannot be found by name.
|
||||||
|
public class TableColumnException extends Exception {
|
||||||
|
TableColumnException(String s) {
|
||||||
|
super(s);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -85,7 +85,7 @@ public class WorkbookComparisonResult {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean tablesAreEquals() {
|
public boolean tablesAreEquals() {
|
||||||
boolean result = masterIncludesClientTables() && tablesToDeleteFromMaster.isEmpty();
|
boolean result = masterIncludesClientTables() && tablesToDeleteFromMaster.isEmpty();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -9,6 +9,8 @@ import org.junit.jupiter.api.BeforeAll;
|
|||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import de.lcag.common.Table.TableColumn;
|
||||||
|
|
||||||
class CsvTableTest {
|
class CsvTableTest {
|
||||||
|
|
||||||
@BeforeAll
|
@BeforeAll
|
||||||
@@ -51,4 +53,28 @@ class CsvTableTest {
|
|||||||
|
|
||||||
assertEquals(37780, n);
|
assertEquals(37780, n);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Important Testcase: Function used in EBX
|
||||||
|
*
|
||||||
|
* @throws IOException
|
||||||
|
*/
|
||||||
|
@Test
|
||||||
|
void testAddColumn() throws IOException {
|
||||||
|
CsvTable csv = null;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
csv = new CsvTable("CsvTable/City_change_history_ok.csv");
|
||||||
|
csv.read();
|
||||||
|
|
||||||
|
TableColumn newCol = csv.addColumn("myNewColumn");
|
||||||
|
n = csv.lenght();
|
||||||
|
assertEquals(37780, n);
|
||||||
|
|
||||||
|
newCol.setValue(n - 1, 28);
|
||||||
|
Object val = csv.getCellValue(n - 1, "myNewColumn");
|
||||||
|
|
||||||
|
assertEquals(28, val);
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ class DbTableTest {
|
|||||||
void testAppendString() {
|
void testAppendString() {
|
||||||
DbTable table = new DbTable(dbProp);
|
DbTable table = new DbTable(dbProp);
|
||||||
|
|
||||||
table.append("select * from vlcag_sys_util_stationefreightcapabilities");
|
table.append("select * from util_stationefreightcapabilities");
|
||||||
|
|
||||||
String csv = table.asCsvData();
|
String csv = table.asCsvData();
|
||||||
|
|
||||||
|
|||||||
@@ -11,16 +11,20 @@ import java.util.List;
|
|||||||
|
|
||||||
import javax.naming.ConfigurationException;
|
import javax.naming.ConfigurationException;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
import de.lcag.common.Table.TableColumn;
|
import de.lcag.common.Table.TableColumn;
|
||||||
import routines.LcagFileTools;
|
import routines.LcagFileTools;
|
||||||
import testutils.CleanupBeforeTestCase;
|
|
||||||
|
|
||||||
class ExcelWorkbookTest extends CleanupBeforeTestCase {
|
class ExcelWorkbookTest {
|
||||||
private Path resDir = Path.of("src/test/resources/ExcelTable");
|
private Path resDir = Path.of("src/test/resources/ExcelTable");
|
||||||
|
|
||||||
|
@BeforeAll
|
||||||
|
static void setUpBeforeClass() throws Exception {
|
||||||
|
}
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUp() throws Exception {
|
void setUp() throws Exception {
|
||||||
}
|
}
|
||||||
@@ -28,18 +32,12 @@ class ExcelWorkbookTest extends CleanupBeforeTestCase {
|
|||||||
@Test
|
@Test
|
||||||
void testSave() throws IOException {
|
void testSave() throws IOException {
|
||||||
CsvTable csv = new CsvTable("CsvTable/NameList.csv");
|
CsvTable csv = new CsvTable("CsvTable/NameList.csv");
|
||||||
int noRows, expectedNoRows;
|
|
||||||
|
|
||||||
csv.read();
|
csv.read();
|
||||||
expectedNoRows = csv.lenght();
|
|
||||||
|
|
||||||
ExcelWorkbook excel = new ExcelWorkbook("src/test/resources/results/NameList.xlsx");
|
ExcelWorkbook excel = new ExcelWorkbook("src/test/resources/results/NameList.xlsx");
|
||||||
|
|
||||||
excel.append(csv);
|
excel.append(csv);
|
||||||
excel.save();
|
excel.save();
|
||||||
|
|
||||||
noRows = excel.lenght();
|
|
||||||
assertEquals(expectedNoRows, noRows, "Creating an Excel from a CSV should have the same number of rows");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -68,28 +66,20 @@ class ExcelWorkbookTest extends CleanupBeforeTestCase {
|
|||||||
void testRead() throws IOException, ConfigurationException {
|
void testRead() throws IOException, ConfigurationException {
|
||||||
ExcelWorkbook excel;
|
ExcelWorkbook excel;
|
||||||
int noRows = -1;
|
int noRows = -1;
|
||||||
String value = null;
|
CsvTable mappingTableCSV = new CsvTable("EntityFieldMapping.csv");
|
||||||
|
|
||||||
excel = new ExcelWorkbook("src/test/resources/ExcelTable/NameList.xlsx");
|
mappingTableCSV.read();
|
||||||
|
noRows = mappingTableCSV.lenght();
|
||||||
|
assertEquals(37, noRows);
|
||||||
|
|
||||||
|
excel = new ExcelWorkbook("src/test/resources/results/NameList.xlsx");
|
||||||
excel.read();
|
excel.read();
|
||||||
noRows = excel.lenght();
|
noRows = excel.lenght();
|
||||||
assertEquals(4, noRows, "Table should have 4 rows");
|
assertEquals(4, noRows);
|
||||||
|
|
||||||
MappingTable mappingTable = new MappingTable("Nachname->LastName", ",", "->");
|
// TODO: Test read using mapping table
|
||||||
excel.setOption(mappingTable);
|
MappingTable mappingTable = new MappingTable(mappingTableCSV);
|
||||||
|
|
||||||
excel.read();
|
|
||||||
noRows = excel.lenght();
|
|
||||||
assertEquals(4, noRows, "Re-reding the table should not change the number of rows");
|
|
||||||
|
|
||||||
value = excel.getFirstTable().getCellValue(2, "Nachname");
|
|
||||||
assertEquals("Schulze", value, "Sould resolve mapped column name and get correct value");
|
|
||||||
|
|
||||||
value = excel.getFirstTable().getCellValue(2, "LastName");
|
|
||||||
assertEquals("Schulze", value, "Using the direct name istead of mapped one should find the same value");
|
|
||||||
|
|
||||||
value = excel.getFirstTable().getCellValue(2, "FirstName");
|
|
||||||
assertEquals("Hermann", value, "Using the name of a non-mapped field should find the correct value");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.lcag.common;
|
package de.lcag.common;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package de.lcag.common;
|
package de.lcag.common;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
import static org.junit.Assert.assertThrows;
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||||
import static org.junit.jupiter.api.Assertions.fail;
|
import static org.junit.jupiter.api.Assertions.fail;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,12 @@
|
|||||||
|
# Configuration file for S:\WS\eclipse-2024\MDM-LCAG-JavaFunctions\src\main\java\application\FileActions.java
|
||||||
|
|
||||||
|
main_file = S:/WS/eclipse-2024/MDM-LCAG-JavaFunctions/src/test/resources/ExcelTable/CompareMasterOrig.xlsx
|
||||||
|
compare_file = CompareClient1.xlsx
|
||||||
|
list_of_keys = Name, FirstName
|
||||||
|
|
||||||
|
# Not yet implemented:
|
||||||
|
# Sheet mappings: Values
|
||||||
|
# "use sequence": compare first sheets in files, then second sheets, ...
|
||||||
|
# <main_file_sheet_name1> -> <compare_file_sheet_name1> ; <main_file_sheet_name2> -> <compare_file_sheet_name2>; ...
|
||||||
|
# Default: Sheet names must match 1:1
|
||||||
|
sheets.mapping = use sequence
|
||||||
@@ -0,0 +1,12 @@
|
|||||||
|
# Configuration file for S:\WS\eclipse-2024\MDM-LCAG-JavaFunctions\src\main\java\application\FileActions.java
|
||||||
|
|
||||||
|
main_file = S:/WS/eclipse-2024/MDM-LCAG-JavaFunctions/src/test/resources/ExcelTable/CompareMasterOrig.xlsx
|
||||||
|
compare_file = CompareClient1.xlsx
|
||||||
|
list_of_keys = Name, FirstName
|
||||||
|
|
||||||
|
# Not yet implemented:
|
||||||
|
# Sheet mappings: Values
|
||||||
|
# "use sequence": compare first sheets in files, then second sheets, ...
|
||||||
|
# <main_file_sheet_name1> -> <compare_file_sheet_name1> ; <main_file_sheet_name2> -> <compare_file_sheet_name2>; ...
|
||||||
|
# Default: Sheet names must match 1:1
|
||||||
|
sheets.mapping = M1 -> C1; M1->C2
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Configuration file for S:\WS\eclipse-2024\MDM-LCAG-JavaFunctions\src\main\java\application\FileActions.java
|
||||||
|
|
||||||
|
main_file = S:/WS/eclipse-2024/MDM-LCAG-JavaFunctions/src/test/resources/ExcelTable/CompareMasterOrig.xlsx
|
||||||
|
compare_file = CompareClient1.xlsx
|
||||||
|
list_of_keys = Name, FirstName
|
||||||
|
|
||||||
|
# Not yet implemented:
|
||||||
|
main_file.colums.ignore =
|
||||||
|
compare_file.colums.ignore =
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
# Configuration file for S:\WS\eclipse-2024\MDM-LCAG-JavaFunctions\src\main\java\application\FileActions.java
|
||||||
|
|
||||||
|
main_file = S:/WS/eclipse-2024/MDM-LCAG-JavaFunctions/src/test/resources/ExcelTable/CompareMasterOrig.xlsx
|
||||||
|
compare_file = CompareClient1.xlsx
|
||||||
|
list_of_keys = Name, FirstName
|
||||||
|
|
||||||
|
# Not yet implemented:
|
||||||
|
main_file.columns.mapping = A->A1; B->A2
|
||||||
|
compare_file.columns.mapping =
|
||||||
|
|
||||||
|
main_file.columns.mapping = <sheet-name1>:A->A1;<sheet-name2>:B->A1
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
# Configuration file for V:/EBX/workspace/MDM-LCAG-JavaFunctions/src/main/java/application/FileActions.java
|
||||||
|
|
||||||
|
main_file = s:/WS/eclipse-2024-git/MDM-LCAG-JavaFunctions/MDM-LCAG-JavaFunctions/src/test/resources/CompareTables/MDM_compare_FilePairs/([0-9\-]*)_storeShipment_request.xml$
|
||||||
|
compare_file = $1_getShipment_reply.xml
|
||||||
|
list_of_keys = Variant
|
||||||
|
|
||||||
|
#column.mapping.main2compare=Code->Code;ValidFrom->ValidFrom
|
||||||
Binary file not shown.
Reference in New Issue
Block a user