Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package de.tsl2.nano.specification;
import java.io.File;
import java.io.FileNotFoundException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import de.tsl2.nano.core.cls.BeanClass;
import de.tsl2.nano.core.execution.IRunnable;
import de.tsl2.nano.core.execution.SystemUtil;
import de.tsl2.nano.core.util.CollectionUtil;
import de.tsl2.nano.core.util.NetUtil;
import de.tsl2.nano.core.util.StringUtil;
import de.tsl2.nano.core.util.Util;
/**
* Reads data lines from a given flat or CSV file to give each line to a worker,
* executing an action with parameters (given in line). The Excel/CSV sheet
* has to have the following structure:
*
*
* 1. line: Title or Action definition line
* 2. line: data headers
* n. line: if exactly one column or starting with BLOCK: name of a block combining the following data lines
* else a data line with columns:
* 1. column: row identifier (has to match property "tsl2nano.excelworker.id.match"="\\d+")
* following columns in any order, but:
* if column-name: 'ACTION' -> name of action to be executed by the worker
* if column-name starts with 'PAR' -> action parameter (given as type Object, on multiple: type Object[])
* if column-value: 'ACTIONDEF' -> the following column value in line will be used as action definition:
* if 'SQL' -> next column value is an sql statement to be used as action with query parameters. the
* connection is done through a persistence context (unit-name: EXCELWORKER) that has to
* be in path 'META-INF/persistence.xml'
* if 'CLS' -> full class name implementing the actions to be excecuted by the worker
* if 'URL' -> url with placeholders to be executed
* if 'CMD' -> system call with arguments
* if 'PRN' -> (default) do nothing but print output to console
*
* The expression in an ACTIONDEF cell (e.g.: !:URL:https://myserver.de/%1$s/show.html:!) may be a formatted expression with placeholders like %s.
* The placeholders are filled through the action parameters: {id, all-values-with-columnheaders-starting-with-PAR:}. The formatter is
* defined here: https://docs.oracle.com/javase/7/docs/api/java/util/Formatter.html
*
* The action name will always converted to lowercase!
*
* To execute the ExcelWorker the sheet has to be exported from Excel to a csv or any other delimited (default: \t) file.
* You are able to configure some properties:
*
* * tsl2nano.excelworker.tag.block="BLOCK"
* * tsl2nano.excelworker.delimiter="\t"
* * tsl2nano.excelworker.persistenceunit="EXCELWORKER"
* * tsl2nano.excelworker.id.match"="\\d+"
* * tsl2nano.excelworker.swallowtabs="false"
* * tsl2nano.excelworker.dryrun="false"
* * tsl2nano.excelworker.blocks.parallel="false"
*
* start it with: ExcelWorker my-delimited-file.csv
*
* In Excel it is possible to define a cell starting a VBA-script that executes the ExcelWorker. It would be something
* like 'Call Shell("program location" & " " & Target)'.
*
*
* @author Thomas Schneider
*/
public class ExcelWorker implements Runnable {
String file;
private static final String BLOCK = System.getProperty("tsl2nano.excelworker.tag.block", "BLOCK");
private static final String ACTION = System.getProperty("tsl2nano.excelworker.tag.action", "ACTION");
private static final String PAR = System.getProperty("tsl2nano.excelworker.tag.par", "PAR:");
private static final String ACTIONDEF = System.getProperty("tsl2nano.excelworker.tag.actiondef", "!:");
private static final String ACTIONDEFEND = System.getProperty("tsl2nano.excelworker.tag.actiondef", ":!");
private static final String DELIMITER = System.getProperty("tsl2nano.excelworker.delimiter", "\t");
private static final String ID_MATCH = System.getProperty("tsl2nano.excelworker.id.match", "\\d+");
private static final int ID_INDEX = Util.trY( () -> Integer.valueOf(System.getProperty("tsl2nano.excelworker.id.index", "0")));
private static final Boolean SWALLOWTABS = Boolean.getBoolean("tsl2nano.excelworker.swallowtabs");
private static final Boolean PARALLEL = Boolean.getBoolean("tsl2nano.excelworker.blocks.parallel");
public ExcelWorker(String file) {
this.file = file;
}
@Override
public void run() {
Collection