SuperX-Kernmodul
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.
 
 
 
 
 
 

284 lines
8.4 KiB

package de.superx.bin;
import java.io.BufferedWriter;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;
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;
/**
* @deprecated
* @author superx
*
*/
@Deprecated
public class WebserviceClientBewegungsdatenAlt extends AbstractWebserviceClient {
private Document resultDocument, configDocument;
private String hsnr;
private final Calendar calendar = Calendar.getInstance();
private String xmlConfig, datentyp;
private String url;
private String data;
private String soap, replaceNodeName;
private String xslpfad, outfile;
private File tempFile;
private String jahr;
private PrintWriter fw;
private BufferedWriter bfw;
private static final Logger log = Logger.getLogger("wc");
public static void main(String args[]) {
System.out
.println("SuperX-WebserviceClientBewegungsdaten Version 0.9.3");
WebserviceClientBewegungsdatenAlt tc = new WebserviceClientBewegungsdatenAlt();
tc.run(args);
}
public WebserviceClientBewegungsdatenAlt() {
}
public void run(String args[]) {
try {
// LogUtils.initRaw(log);
LogUtils.initRawFileDateTime("wc", "WebserviceClient.log", 100000,
1, true, false);
log.setLevel(Level.FINEST);
log.getHandlers()[0].setLevel(Level.FINEST);
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();
perform();
String msg = " fertig: " + DateUtils.getTodayString() + " "
+ DateUtils.getNowString();
log.info(msg);
System.out.println(msg);
} catch (Exception e) {
log.severe(e.getMessage());
System.out.println("Error " + e.getMessage());
e.printStackTrace();
System.exit(1);
} finally {
LogUtils.close("wc");
}
}
private void perform() throws Exception {
Node n = XMLUtils.getFirstNode(configDocument, datentyp + "detailurl");
url = XMLUtils.getTheValue(n);
url = adaptURL(url);
n = XMLUtils.getFirstNode(configDocument, datentyp + "detailsoap");
soap = XMLUtils.getTheValue(n);
soap = soap.replace("XXHSNRXX", hsnr);
soap = soap.replace("XXJAHRXX", jahr);
System.out.println(datentyp + "\n14x " + soap);
n = XMLUtils.getFirstNode(configDocument, datentyp
+ "detailreplacenode");
replaceNodeName = XMLUtils.getAttribValue(n, "from");
initTempFile();
// monat 0 ist Vorjahr, Monat 13 ist Folgejahr
for (int monat = 0; monat <= 4; monat++) {
String monatssoap = getMonatsoap(monat);
log.fine(datentyp + "\nSOAP Aufruf:\n" + monatssoap);
System.out.print("starte Aufruf " + (monat + 1));
data = readSOAP(monatssoap, url).toString();
System.gc();
System.out.println(" - empfangen ");
data = data
.replaceAll("<\\?xml.*\\?>", "");
System.gc();
data = XMLUtils.removeTroublesomeCharacters(data);
System.gc();
data = data.replaceAll("\u20AC", "EUR");
System.gc();
data = data.replaceAll("\u2013", "-");// dash
System.gc();
data = data.replaceAll("\u2026", "...");// ...
System.gc();
data = StringUtils.replace(data, replaceNodeName, "response");
System.gc();
resultDocument = XMLUtils.buildDocumentFromString(data, false);
if (isReplyOk()) {
if (data.indexOf("<EX_FMIFIIT/>")>-1||
data.indexOf("<EX_FMBDP/>")>-1||
data.indexOf("<EX_FMIOI/>")>-1) continue;
else
appendData();
} else {
String msg = "Error: Aufruf von Webservice für Bewegungsdaten "
+ datentyp + " (" + xmlConfig + ") fehlgeschlagen";
System.out.println(msg);
log.severe(msg);
LogUtils.close("wc");
System.exit(-1);
}
System.gc();
}
closeFileAndTransform();
}
private String getMonatsoap(int monat) {
String tempsoap = soap;
if (monat == 0) {
int vorjahr = Integer.parseInt(jahr);
vorjahr--;
tempsoap = tempsoap.replaceAll("XXSTARTXX", vorjahr + "-01-01");
tempsoap = tempsoap.replaceAll("XXENDEXX", vorjahr + "-12-31");
}
if (monat >= 1 && monat <= 12) {
int jahrint = Integer.parseInt(jahr);
calendar.set(Calendar.YEAR, jahrint);
calendar.set(Calendar.MONTH, monat - 1);
String monatstr;
if (monat < 10)
monatstr = "0" + monat;
else
monatstr = monat + "";
tempsoap = tempsoap.replaceAll("XXSTARTXX", jahr + "-" + monatstr
+ "-01");
int maxDay = calendar.getActualMaximum(Calendar.DATE);
tempsoap = tempsoap.replaceAll("XXENDEXX", jahr + "-" + monatstr
+ "-" + maxDay);
}
if (monat == 13) {
int folgejahr = Integer.parseInt(jahr);
folgejahr++;
tempsoap = tempsoap.replaceAll("XXSTARTXX", folgejahr + "-01-01");
tempsoap = tempsoap.replaceAll("XXENDEXX", folgejahr + "-12-31");
}
return tempsoap;
}
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);
System.out.println("\n" + DateUtils.getTodayString() + " "
+ DateUtils.getNowString() + "\nHochschulnummer " + hsnr);
log.info("\nHochschulnummer " + hsnr);
if (GetOpts.isPresent(Options.opt_noDelete))
isDeleteTmpXmlFileWanted = false;
log.log(Level.INFO, "Geschaeftsjahr " + jahr);
System.out.println("Geschaeftsjahr " + jahr);
log.log(Level.INFO, "Verarbeite " + xmlConfig);
System.out.println("Verarbeite " + xmlConfig);
configDocument = XMLUtils.buildDocument(new File(xmlConfig));
}
private void appendData() throws Exception {
bfw.write(data);
bfw.flush();
}
private void initTempFile() throws Exception {
tempFile = File.createTempFile("webservicedata", ".xml");
// File f=new File("tmpwebservice.xml");
if (!isDeleteTmpXmlFileWanted) {
System.out.println("Temp Datei: " + tempFile.getAbsolutePath());
log.info("Temp Datei: " + tempFile.getAbsolutePath());
}
if (tempFile.exists())
tempFile.delete();
// FileWriter fw = new FileWriter(f);
fw = new PrintWriter(tempFile, "UTF-8");
// FileOutputStream fos = new FileOutputStream(f, false);
// BufferedWriter bfw = new BufferedWriter(new OutputStreamWriter(fos));
bfw = new BufferedWriter(fw);
bfw.write("<newdata>\n");
}
private void closeFileAndTransform() throws Exception {
bfw.write("\n</newdata>\n");
bfw.close();
fw.close();
SxTransformer sxTrans = new SxTransformer(log, outfile);
sxTrans.quellstring = tempFile.getAbsolutePath();
sxTrans.stylesheet = xslpfad + File.separator + "soap_to_csv_"
+ datentyp + ".xsl";
sxTrans.params = "ignoreElements=EX_JEST";
sxTrans.transformFile("text");
//bei Fmiit auch HeaderDatei erzeugen
if (datentyp.equals("fmifiit"))
{
sxTrans.outfile=StringUtils.replace(outfile, ".", "hd.");
sxTrans.stylesheet=StringUtils.replace(sxTrans.stylesheet,"soap_to_csv_fmifiit.xsl","soap_to_csv_fmifihd.xsl");
String msg="Erzeuge zusaetzliche Header_Datei "+sxTrans.outfile;
log.log(Level.INFO, msg);
System.out.println(msg);
sxTrans.transformFile("text");
}
if (isDeleteTmpXmlFileWanted)
tempFile.delete();
}
private boolean isReplyOk() {
boolean result = false;
/**
* TODO eigentlich sicherheitshalber gucken unter <RETURN> <item>
* <TYPE>I</TYPE> TYPE kommt aber nur einmal vor
*/
if (!XMLUtils.hasANodeWithName(resultDocument, "TYPE")) {
System.out.println(data);
log.severe(data);
} else {
Node type = XMLUtils.getFirstNode(resultDocument, "TYPE");
if (XMLUtils.getTheValue(type).equals("I"))
result = true;
}
return result;
}
}