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.
183 lines
5.0 KiB
183 lines
5.0 KiB
/* |
|
* de.superx.etl - a package for controlling ETL routines |
|
* Copyright (C) 2021 Daniel Quathamer <danielq@memtext.de> |
|
* |
|
* This package is licensed under the CampusSource License; |
|
* http://www.campussource.de/org/license/ |
|
*/ |
|
package de.superx.sxrest; |
|
import javax.ws.rs.Consumes; |
|
import javax.ws.rs.DELETE; |
|
import javax.ws.rs.FormParam; |
|
import javax.ws.rs.GET; |
|
import javax.ws.rs.HEAD; |
|
import javax.ws.rs.POST; |
|
import javax.ws.rs.PUT; |
|
import javax.ws.rs.Path; |
|
import javax.ws.rs.PathParam; |
|
import javax.ws.rs.core.Response; |
|
import javax.xml.parsers.ParserConfigurationException; |
|
import javax.xml.xpath.XPath; |
|
import javax.xml.xpath.XPathConstants; |
|
import javax.xml.xpath.XPathExpressionException; |
|
import javax.xml.xpath.XPathFactory; |
|
|
|
|
|
import org.w3c.dom.Document; |
|
import org.w3c.dom.Node; |
|
import org.w3c.dom.NodeList; |
|
import org.xml.sax.SAXException; |
|
|
|
import javax.ws.rs.Produces; |
|
import javax.ws.rs.QueryParam; |
|
import javax.ws.rs.core.Context; |
|
import javax.ws.rs.core.MediaType; |
|
import javax.ws.rs.core.Request; |
|
import de.memtext.util.DateUtils; |
|
import de.superx.common.SxUser; |
|
import de.superx.etl.EtlActionJob; |
|
import de.superx.etl.EtlUtils; |
|
import de.superx.servlet.SuperXManager; |
|
|
|
import java.io.BufferedWriter; |
|
import java.io.File; |
|
import java.io.FileWriter; |
|
import java.io.IOException; |
|
|
|
import javax.servlet.http.HttpServletRequest; |
|
|
|
|
|
@Path("/maskxml") |
|
|
|
public class MaskXml { |
|
@Context |
|
Request request; |
|
|
|
@GET |
|
@Path("/get/{param}") |
|
@Produces(MediaType.TEXT_PLAIN) |
|
|
|
|
|
public String printXml(@PathParam("param") String tid,@Context HttpServletRequest request) { |
|
String returntext=""; |
|
SxUser user = (SxUser) request.getSession().getAttribute("user"); |
|
String mandantenid= (String) request.getSession().getAttribute("MandantenID"); |
|
if(mandantenid==null || mandantenid.equals("")) |
|
mandantenid="default"; |
|
|
|
if (user == null || !user.isAdmin()) { |
|
returntext="Fehlende Rechte"; |
|
} |
|
else |
|
{ |
|
String job="sx_select_mask"; |
|
String params="TID="+tid; |
|
int returnCode=0; |
|
EtlActionJob myJob=new EtlActionJob(job); //TODO:Mandantid |
|
try { |
|
myJob.initJob(job,params); |
|
} catch (Exception e) { |
|
// TODO Auto-generated catch block |
|
|
|
returntext=e.toString(); |
|
returntext+=myJob.getLogoutput(); |
|
|
|
} |
|
System.out.println("Job "+ job+" initialized"); |
|
try { |
|
returnCode= myJob.execute(""); |
|
returntext=myJob.getSw().toString(); |
|
|
|
} catch (Exception e) { |
|
// TODO Auto-generated catch block |
|
returntext=e.toString(); |
|
returntext+=myJob.getLogoutput(); |
|
} |
|
} |
|
|
|
return returntext; |
|
} |
|
@GET |
|
@Path("/saveget/{params}") |
|
@Produces(MediaType.TEXT_PLAIN) |
|
|
|
|
|
public String saveGetXml(@QueryParam("param") String tid, |
|
@QueryParam("Inhalt") String src, |
|
@Context HttpServletRequest request) { |
|
String returntext=""; |
|
SxUser user = (SxUser) request.getSession().getAttribute("user"); |
|
String mandantenid= (String) request.getSession().getAttribute("MandantenID"); |
|
if(mandantenid==null || mandantenid.equals("")) |
|
mandantenid="default"; |
|
|
|
if (user == null || !user.isAdmin()) { |
|
returntext="Fehlende Rechte"; |
|
} |
|
else |
|
{ |
|
returntext="tid="+tid+"-src="+src; |
|
} |
|
|
|
return returntext; |
|
} |
|
@POST |
|
@Path("/save") |
|
@Consumes("application/x-www-form-urlencoded") |
|
//@Consumes(MediaType.APPLICATION_FORM_URLENCODED) |
|
@Produces(MediaType.TEXT_PLAIN) |
|
|
|
public String saveXml(@FormParam("tid") String tid, |
|
@FormParam("Inhalt") String src, |
|
@Context HttpServletRequest request) { |
|
String returntext=""; |
|
int returnCode=0; |
|
tid="16000"; |
|
SxUser user = (SxUser) request.getSession().getAttribute("user"); |
|
String mandantenid= (String) request.getSession().getAttribute("MandantenID"); |
|
String searchString="/etlAction[@name=\"sx_select_mask\"]/unload[@name=\"unload_maskeninfo\"]/rs/row/fld[@name=\"tid\"]"; |
|
if(mandantenid==null || mandantenid.equals("")) |
|
mandantenid="default"; |
|
|
|
if (user == null || !user.isAdmin()) { |
|
returntext="Fehlende Rechte"; |
|
|
|
} |
|
else |
|
{ |
|
try { |
|
if(de.superx.etl.EtlUtils.isNodeValueInXml(src,searchString,tid)) |
|
{ |
|
String job="sx_insert_mask"; |
|
returntext="TID="+tid; |
|
String params="TID="+tid; |
|
File temp; |
|
temp = File.createTempFile("myTempFile", ".xml"); |
|
|
|
BufferedWriter bw = new BufferedWriter(new FileWriter(temp)); |
|
bw.write(src); |
|
|
|
bw.close(); |
|
params+=EtlUtils.NEWLINE+"PATH_TO_INPUTFILE="+temp.getAbsolutePath(); |
|
params+=EtlUtils.NEWLINE+"FORMAT=XML"; |
|
EtlActionJob myJob=new EtlActionJob(job); //TODO:Mandantid |
|
myJob.initJob(job,params); |
|
returnCode= myJob.execute(""); |
|
returntext=myJob.getSw().toString(); |
|
|
|
|
|
|
|
} |
|
else |
|
returntext="Übergebene TID "+tid+" entspricht nicht der XML-Datei "; |
|
} catch (Exception e) { |
|
returntext=e.toString(); |
|
e.printStackTrace(); |
|
} |
|
|
|
|
|
} |
|
return returntext; |
|
} |
|
|
|
}
|
|
|