Search in sources :

Example 1 with XsltPreparatorDocket

use of io.goobi.workflow.xslt.XsltPreparatorDocket in project goobi-workflow by intranda.

the class GoobiScriptExportDatabaseInformation method execute.

@Override
public void execute(GoobiScriptResult gsr) {
    Process p = ProcessManager.getProcessById(gsr.getProcessId());
    try {
        gsr.setProcessTitle(p.getTitel());
        gsr.setResultType(GoobiScriptResultType.RUNNING);
        gsr.updateTimestamp();
        Path dest = null;
        try {
            dest = Paths.get(p.getProcessDataDirectoryIgnoreSwapping(), p.getId() + "_db_export.xml");
        } catch (IOException | InterruptedException | SwapException | DAOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot read process folder " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        }
        OutputStream os = null;
        try {
            os = Files.newOutputStream(dest);
        } catch (IOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot write into export file " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        }
        try {
            Document doc = new XsltPreparatorDocket().createExtendedDocument(p);
            XMLOutputter outp = new XMLOutputter();
            outp.setFormat(Format.getPrettyFormat());
            outp.output(doc, os);
        } catch (IOException e) {
            log.error(e);
            gsr.setResultMessage("Cannot write into export file " + e.getMessage());
            gsr.setResultType(GoobiScriptResultType.ERROR);
        } finally {
            if (os != null) {
                os.close();
            }
        }
        if (gsr.getResultType() != GoobiScriptResultType.ERROR) {
            gsr.setResultMessage("Export done successfully");
            gsr.setResultType(GoobiScriptResultType.OK);
        }
    } catch (NoSuchMethodError | Exception e) {
        gsr.setResultMessage(e.getMessage());
        gsr.setResultType(GoobiScriptResultType.ERROR);
        gsr.setErrorText(e.getMessage());
        log.error("Exception during the export of database information for id " + p.getId(), e);
    }
    gsr.updateTimestamp();
}
Also used : Path(java.nio.file.Path) XMLOutputter(org.jdom2.output.XMLOutputter) SwapException(de.sub.goobi.helper.exceptions.SwapException) OutputStream(java.io.OutputStream) Process(org.goobi.beans.Process) IOException(java.io.IOException) Document(org.jdom2.Document) DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) IOException(java.io.IOException) DAOException(de.sub.goobi.helper.exceptions.DAOException) XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket)

Example 2 with XsltPreparatorDocket

use of io.goobi.workflow.xslt.XsltPreparatorDocket in project goobi-workflow by intranda.

the class ProcessBean method downloadProcessDatebaseInformation.

/**
 * Create the database information xml file and send it to the servlet output stream
 */
public void downloadProcessDatebaseInformation() {
    FacesContext facesContext = FacesContextHelper.getCurrentFacesContext();
    if (!facesContext.getResponseComplete()) {
        org.jdom2.Document doc = new XsltPreparatorDocket().createExtendedDocument(myProzess);
        String outputFileName = myProzess.getId() + "_db_export.xml";
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String contentType = servletContext.getMimeType(outputFileName);
        response.setContentType(contentType);
        response.setHeader("Content-Disposition", "attachment;filename=\"" + outputFileName + "\"");
        try {
            ServletOutputStream out = response.getOutputStream();
            XMLOutputter outp = new XMLOutputter();
            outp.setFormat(Format.getPrettyFormat());
            outp.output(doc, out);
            out.flush();
        } catch (IOException e) {
            Helper.setFehlerMeldung("could not export database information: ", e);
        }
        facesContext.responseComplete();
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket) XMLOutputter(org.jdom2.output.XMLOutputter) ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException)

Example 3 with XsltPreparatorDocket

use of io.goobi.workflow.xslt.XsltPreparatorDocket in project goobi-workflow by intranda.

the class ProcessBean method CreateXML.

/**
 * starts generation of xml logfile for current process
 */
public void CreateXML() {
    XsltPreparatorDocket xmlExport = new XsltPreparatorDocket();
    try {
        String ziel = Helper.getCurrentUser().getHomeDir() + this.myProzess.getTitel() + "_log.xml";
        xmlExport.startExport(this.myProzess, ziel);
    } catch (IOException e) {
        Helper.setFehlerMeldung("could not write logfile to home directory: ", e);
    } catch (InterruptedException e) {
        Helper.setFehlerMeldung("could not execute command to write logfile to home directory", e);
    }
}
Also used : XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket) IOException(java.io.IOException)

Example 4 with XsltPreparatorDocket

use of io.goobi.workflow.xslt.XsltPreparatorDocket in project goobi-workflow by intranda.

the class Process method downloadDocket.

public String downloadDocket() {
    if (log.isDebugEnabled()) {
        log.debug("generate docket for process " + this.id);
    }
    String rootpath = ConfigurationHelper.getInstance().getXsltFolder();
    Path xsltfile = Paths.get(rootpath, "docket.xsl");
    if (docket != null) {
        xsltfile = Paths.get(rootpath, docket.getFile());
        if (!StorageProvider.getInstance().isFileExists(xsltfile)) {
            Helper.setFehlerMeldung("docketMissing");
            return "";
        }
    }
    FacesContext facesContext = FacesContextHelper.getCurrentFacesContext();
    if (!facesContext.getResponseComplete()) {
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        String fileName = this.titel + ".pdf";
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String contentType = servletContext.getMimeType(fileName);
        response.setContentType(contentType);
        response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
        // write run note to servlet output stream
        try {
            ServletOutputStream out = response.getOutputStream();
            XsltToPdf ern = new XsltToPdf();
            ern.startExport(this, out, xsltfile.toString(), new XsltPreparatorDocket());
            out.flush();
        } catch (IOException e) {
            log.error("IOException while exporting run note", e);
        }
        facesContext.responseComplete();
    }
    return "";
}
Also used : Path(java.nio.file.Path) FacesContext(javax.faces.context.FacesContext) XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket) ServletOutputStream(javax.servlet.ServletOutputStream) XsltToPdf(io.goobi.workflow.xslt.XsltToPdf) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException)

Example 5 with XsltPreparatorDocket

use of io.goobi.workflow.xslt.XsltPreparatorDocket in project goobi-workflow by intranda.

the class Process method downloadLogFile.

/**
 * download xml logfile for current process
 */
public void downloadLogFile() {
    XsltPreparatorDocket xmlExport = new XsltPreparatorDocket();
    FacesContext facesContext = FacesContextHelper.getCurrentFacesContext();
    if (!facesContext.getResponseComplete()) {
        HttpServletResponse response = (HttpServletResponse) facesContext.getExternalContext().getResponse();
        String fileName = getTitel() + "_log.xml";
        ServletContext servletContext = (ServletContext) facesContext.getExternalContext().getContext();
        String contentType = servletContext.getMimeType(fileName);
        response.setContentType(contentType);
        response.setHeader("Content-Disposition", "attachment;filename=\"" + fileName + "\"");
        // write to servlet output stream
        try {
            ServletOutputStream out = response.getOutputStream();
            xmlExport.startExport(this, out);
            out.flush();
        } catch (IOException e) {
            log.error("IOException while exporting run note", e);
        }
        facesContext.responseComplete();
    }
    return;
}
Also used : XsltPreparatorDocket(io.goobi.workflow.xslt.XsltPreparatorDocket) FacesContext(javax.faces.context.FacesContext) ServletOutputStream(javax.servlet.ServletOutputStream) HttpServletResponse(javax.servlet.http.HttpServletResponse) ServletContext(javax.servlet.ServletContext) IOException(java.io.IOException)

Aggregations

XsltPreparatorDocket (io.goobi.workflow.xslt.XsltPreparatorDocket)7 IOException (java.io.IOException)7 FacesContext (javax.faces.context.FacesContext)4 ServletContext (javax.servlet.ServletContext)4 ServletOutputStream (javax.servlet.ServletOutputStream)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 Path (java.nio.file.Path)2 XMLOutputter (org.jdom2.output.XMLOutputter)2 DAOException (de.sub.goobi.helper.exceptions.DAOException)1 SwapException (de.sub.goobi.helper.exceptions.SwapException)1 XsltToPdf (io.goobi.workflow.xslt.XsltToPdf)1 OutputStream (java.io.OutputStream)1 ConfigurationException (org.apache.commons.configuration.ConfigurationException)1 Process (org.goobi.beans.Process)1 Document (org.jdom2.Document)1 XSLTransformException (org.jdom2.transform.XSLTransformException)1