You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
220 lines
6.7 KiB
220 lines
6.7 KiB
package de.superx.bin; |
|
|
|
import java.io.File; |
|
import java.io.IOException; |
|
import java.nio.file.Files; |
|
import java.nio.file.StandardOpenOption; |
|
import java.sql.Connection; |
|
import java.sql.ResultSet; |
|
import java.sql.Statement; |
|
import java.util.Collection; |
|
import java.util.Iterator; |
|
import java.util.LinkedList; |
|
import java.util.logging.Level; |
|
|
|
import org.w3c.dom.Document; |
|
import org.w3c.dom.Node; |
|
import org.xml.sax.SAXException; |
|
|
|
import de.memtext.util.DateUtils; |
|
import de.memtext.util.GetOpts; |
|
import de.memtext.util.GetOpts.Options; |
|
import de.memtext.util.LogUtils; |
|
import de.memtext.util.StringUtils; |
|
import de.memtext.util.XMLUtils; |
|
|
|
public class WebserviceClientSummendaten extends AbstractWebserviceClient { |
|
|
|
private Collection<String> finanzstellen = new LinkedList<String>(); |
|
private Document configDocument; |
|
|
|
private String hsnr; |
|
|
|
private String xmlConfig, datentyp; |
|
private String url; |
|
private StringBuffer data = new StringBuffer(); |
|
private String soap, replaceNodeName; |
|
|
|
private String xslpfad, outfile; |
|
private boolean isDeleteTmpXmlFileWanted = true; |
|
|
|
private String jahr; |
|
|
|
private boolean isDBConnectionPossible = true; |
|
|
|
private String dbpropfile; |
|
|
|
public static void main(String args[]) { |
|
System.out.println("SuperX-WebserviceClientSummendaten Version 1.3"); |
|
WebserviceClientSummendaten tc = new WebserviceClientSummendaten(); |
|
tc.run(args); |
|
|
|
} |
|
|
|
public WebserviceClientSummendaten() { |
|
|
|
} |
|
|
|
public void run(String args[]) { |
|
try { |
|
initLogging(); |
|
GetOpts.setOpts(args); |
|
String isdrin = GetOpts.isAllRequiredOptionsPresent(new Options[] { Options.opt_xmlconfig, |
|
Options.opt_xslPfad, Options.opt_hsnr, Options.opt_jahr, Options.opt_out, Options.opt_datentyp }); |
|
if (isdrin != null) { |
|
System.err.println("Folgende Optionen fehlen: " + isdrin); |
|
// System.err.println(usage); |
|
System.exit(1); |
|
} |
|
readConfig(); |
|
readFinanzstellen(); |
|
perform(); |
|
|
|
String msg = " fertig: " + DateUtils.getTodayString() + " " + DateUtils.getNowString(); |
|
logger.info(msg); |
|
System.out.println(msg); |
|
} catch (Exception e) { |
|
logger.severe(e.getMessage()); |
|
System.out.println("Error " + e.getMessage()); |
|
e.printStackTrace(); |
|
LogUtils.close("wc"); |
|
System.exit(1); |
|
} finally { |
|
LogUtils.close("wc"); |
|
|
|
} |
|
} |
|
|
|
private void readFinanzstellen() throws Exception { |
|
if (isDBConnectionPossible) { |
|
SxConnection myConnection = new SxConnection(); |
|
myConnection.setPropfile(dbpropfile); |
|
Connection con = myConnection.getConnection(); |
|
Statement stm = con.createStatement(); |
|
|
|
ResultSet rs = stm.executeQuery("select distinct fmfctr_fictr from gxstage_sap_sc11 ; "); |
|
//for debugging |
|
//ResultSet rs = stm.executeQuery("select distinct fmfctr_fictr from gxstage_sap_sc11 where fmfctr_fictr='8056216104'"); |
|
// gxstage_inst sind auch Hilfskostenstellen (Hierarchie enthalten) |
|
while (rs.next()) { |
|
String instnr = rs.getString(1); |
|
finanzstellen.add(instnr); |
|
} |
|
rs.close(); |
|
stm.close(); |
|
con.close(); |
|
|
|
} |
|
String msg = finanzstellen.size() + " Finanzstellen gefunden"; |
|
logger.log(Level.INFO, msg); |
|
System.out.println(msg); |
|
} |
|
|
|
private void perform() throws Exception { |
|
|
|
Node n = XMLUtils.getFirstNode(configDocument, datentyp + "sumurl"); |
|
url = XMLUtils.getTheValue(n); |
|
url = adaptURL(url); |
|
logger.fine("URL:" + url); |
|
System.out.println("URL:" + url); |
|
n = XMLUtils.getFirstNode(configDocument, datentyp + "sumsoap"); |
|
soap = XMLUtils.getTheValue(n); |
|
soap = soap.replace("XXHSNRXX", hsnr); |
|
soap = soap.replace("XXJAHRXX", jahr); |
|
System.out.println(datentyp + "\n" + soap); |
|
n = XMLUtils.getFirstNode(configDocument, datentyp + "sumreplacenode"); |
|
replaceNodeName = XMLUtils.getAttribValue(n, "from"); |
|
|
|
logger.fine(datentyp + "\nSOAP Aufruf:\n" + soap); |
|
|
|
// Schleife über Kostenstellen |
|
Iterator<String> it = finanzstellen.iterator(); |
|
int i = 0; |
|
while (it.hasNext()) { |
|
String fistl = it.next(); |
|
//System.out.println("Debug: " + fistl); |
|
i++; |
|
if (i % 10 == 0) |
|
System.out.print(i + " "); |
|
|
|
String tmpsoap = soap.replace("XXFISTLXX", fistl); |
|
StringBuffer result = readSOAP(tmpsoap, url); |
|
|
|
if (!isReplyOk(result)) { |
|
String msg = "Error: Aufruf von Webservice fuer Summendaten " + datentyp + " (" + xmlConfig + ") FISTL:" |
|
+ fistl + " fehlgeschlagen\n" + result; |
|
System.out.println(msg); |
|
logger.severe(msg); |
|
LogUtils.close("wc"); |
|
System.exit(-1); |
|
} |
|
|
|
if (result.indexOf("Es wurden 0000") > -1 || result.indexOf("<EX_FMBDT/>") > -1 |
|
// || result.indexOf("<EX_FMIFIIT/>") > -1) |
|
) |
|
continue; |
|
//System.out.println("Debug:" +result); |
|
String resultAdapted = removeXmlHeader(result.toString()); |
|
resultAdapted = purge(resultAdapted, true); |
|
resultAdapted = StringUtils.replace(resultAdapted, replaceNodeName, "response"); |
|
|
|
data.append(format(resultAdapted)); |
|
|
|
} |
|
System.out.println(""); |
|
writeChangeXml(); |
|
|
|
} |
|
|
|
private void readConfig() throws IOException, SAXException { |
|
|
|
xmlConfig = GetOpts.getValue(Options.opt_xmlconfig); |
|
outfile = GetOpts.getValue(Options.opt_out); |
|
xslpfad = GetOpts.getValue(Options.opt_xslPfad); |
|
hsnr = GetOpts.getValue(Options.opt_hsnr); |
|
jahr = GetOpts.getValue(Options.opt_jahr); |
|
datentyp = GetOpts.getValue(Options.opt_datentyp); |
|
if (!datentyp.contentEquals("fmbdt") && !datentyp.contentEquals("fmit")) { |
|
System.out.println("Fehler: Unbekannter Datentyp " + datentyp + " als Parameter"); |
|
System.exit(-1); |
|
|
|
} |
|
dbpropfile = GetOpts.getValue(Options.opt_dbprops); |
|
|
|
System.out.println( |
|
"\n" + DateUtils.getTodayString() + " " + DateUtils.getNowString() + "\nHochschulnummer " + hsnr); |
|
logger.info("\nHochschulnummer " + hsnr); |
|
if (GetOpts.isPresent(Options.opt_noDelete)) |
|
isDeleteTmpXmlFileWanted = false; |
|
logger.log(Level.INFO, "Geschaeftsjahr " + jahr); |
|
System.out.println("Geschaeftsjahr " + jahr); |
|
|
|
logger.log(Level.INFO, "Verarbeite " + xmlConfig); |
|
System.out.println("Verarbeite " + xmlConfig); |
|
configDocument = XMLUtils.buildDocument(new File(xmlConfig)); |
|
|
|
} |
|
|
|
private void writeChangeXml() throws Exception { |
|
File f = File.createTempFile("webservicedata", ".xml"); |
|
if (!isDeleteTmpXmlFileWanted) { |
|
System.out.println("Temp Datei: " + f.getAbsolutePath()); |
|
logger.info("Temp Datei: " + f.getAbsolutePath()); |
|
} |
|
if (f.exists()) |
|
f.delete(); |
|
Files.writeString(f.toPath(), "<newdata>\n", StandardOpenOption.CREATE); |
|
Files.writeString(f.toPath(), data, StandardOpenOption.APPEND); |
|
Files.writeString(f.toPath(), "\n</newdata>\n", StandardOpenOption.APPEND); |
|
|
|
SxTransformer sxTrans = new SxTransformer(logger, outfile); |
|
sxTrans.quellstring = f.getAbsolutePath(); |
|
sxTrans.stylesheet = xslpfad + File.separator + "sum_soap_to_csv_" + datentyp + ".xsl"; |
|
sxTrans.params = "ignoreElements=EX_JEST"; |
|
sxTrans.transformFile("text"); |
|
if (isDeleteTmpXmlFileWanted) |
|
f.delete(); |
|
|
|
} |
|
|
|
} |