Search in sources :

Example 51 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class ProcessSwapInTask method run.

/**
 * Aufruf als Thread ================================================================
 */
@SuppressWarnings("deprecation")
@Override
public void run() {
    setStatusProgress(5);
    String swapPath = null;
    // ProzessDAO dao = new ProzessDAO();
    String processDirectory = "";
    if (ConfigurationHelper.getInstance().isUseSwapping()) {
        swapPath = ConfigurationHelper.getInstance().getSwapPath();
    } else {
        setStatusMessage("swapping not activated");
        setStatusProgress(-1);
        return;
    }
    if (swapPath == null || swapPath.length() == 0) {
        setStatusMessage("no swappingPath defined");
        setStatusProgress(-1);
        return;
    }
    Path swapFile = Paths.get(swapPath);
    if (!StorageProvider.getInstance().isFileExists(swapFile)) {
        setStatusMessage("Swap folder does not exist or is not mounted");
        setStatusProgress(-1);
        return;
    }
    try {
        processDirectory = getProzess().getProcessDataDirectoryIgnoreSwapping();
    // TODO: Don't catch Exception (the super class)
    } catch (Exception e) {
        log.warn("Exception:", e);
        setStatusMessage("Error while getting process data folder: " + e.getClass().getName() + " - " + e.getMessage());
        setStatusProgress(-1);
        return;
    }
    Path fileIn = Paths.get(processDirectory);
    Path fileOut = Paths.get(swapPath + getProzess().getId() + FileSystems.getDefault().getSeparator());
    if (!StorageProvider.getInstance().isFileExists(fileOut)) {
        setStatusMessage(getProzess().getTitel() + ": swappingOutTarget does not exist");
        setStatusProgress(-1);
        return;
    }
    if (!StorageProvider.getInstance().isFileExists(fileIn)) {
        setStatusMessage(getProzess().getTitel() + ": process data folder does not exist");
        setStatusProgress(-1);
        return;
    }
    SAXBuilder builder = new SAXBuilder();
    Document docOld;
    try {
        Path swapLogFile = Paths.get(processDirectory, "swapped.xml");
        docOld = builder.build(swapLogFile.toFile());
    // TODO: Don't catch Exception (the super class)
    } catch (Exception e) {
        log.warn("Exception:", e);
        setStatusMessage("Error while reading swapped.xml in process data folder: " + e.getClass().getName() + " - " + e.getMessage());
        setStatusProgress(-1);
        return;
    }
    /*
         * --------------------- alte Checksummen in HashMap schreiben -------------------
         */
    setStatusMessage("reading checksums");
    Element rootOld = docOld.getRootElement();
    HashMap<String, String> crcMap = new HashMap<String, String>();
    // TODO: Don't use Iterators
    for (Iterator<Element> it = rootOld.getChildren("file").iterator(); it.hasNext(); ) {
        Element el = it.next();
        crcMap.put(el.getAttribute("path").getValue(), el.getAttribute("crc32").getValue());
    }
    StorageProvider.getInstance().deleteDataInDir(fileIn);
    /*
         * --------------------- Dateien kopieren und Checksummen ermitteln -------------------
         */
    Document doc = new Document();
    Element root = new Element("goobiArchive");
    doc.setRootElement(root);
    /*
         * --------------------- Verzeichnisse und Dateien kopieren und anschliessend den Ordner leeren -------------------
         */
    setStatusProgress(50);
    try {
        setStatusMessage("copying process files");
        Helper.copyDirectoryWithCrc32Check(fileOut, fileIn, swapPath.length(), root);
    } catch (IOException e) {
        log.warn("IOException:", e);
        setStatusMessage("IOException in copyDirectory: " + e.getMessage());
        setStatusProgress(-1);
        return;
    }
    setStatusProgress(80);
    /*
         * --------------------- Checksummen vergleichen -------------------
         */
    setStatusMessage("checking checksums");
    // TODO: Don't use Iterators
    for (Iterator<Element> it = root.getChildren("file").iterator(); it.hasNext(); ) {
        Element el = it.next();
        String newPath = el.getAttribute("path").getValue();
        String newCrc = el.getAttribute("crc32").getValue();
        if (crcMap.containsKey(newPath)) {
            if (!crcMap.get(newPath).equals(newCrc)) {
                setLongMessage(getLongMessage() + "File " + newPath + " has different checksum<br/>");
            }
            crcMap.remove(newPath);
        }
    }
    setStatusProgress(85);
    /*
         * --------------------- prüfen, ob noch Dateien fehlen -------------------
         */
    setStatusMessage("checking missing files");
    if (crcMap.size() > 0) {
        for (String myFile : crcMap.keySet()) {
            setLongMessage(getLongMessage() + "File " + myFile + " is missing<br/>");
        }
    }
    setStatusProgress(90);
    /* in Prozess speichern */
    StorageProvider.getInstance().deleteDir(fileOut);
    try {
        setStatusMessage("saving process");
        Process myProzess = ProcessManager.getProcessById(getProzess().getId());
        myProzess.setSwappedOutGui(false);
        ProcessManager.saveProcess(myProzess);
    } catch (DAOException e) {
        setStatusMessage("DAOException while saving process: " + e.getMessage());
        log.warn("DAOException:", e);
        setStatusProgress(-1);
        return;
    }
    setStatusMessage("done");
    setStatusProgress(100);
}
Also used : Path(java.nio.file.Path) DAOException(de.sub.goobi.helper.exceptions.DAOException) SAXBuilder(org.jdom2.input.SAXBuilder) HashMap(java.util.HashMap) Element(org.jdom2.Element) Process(org.goobi.beans.Process) IOException(java.io.IOException) Document(org.jdom2.Document) DAOException(de.sub.goobi.helper.exceptions.DAOException) IOException(java.io.IOException)

Example 52 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class MassImportForm method initializePossibleDigitalCollections.

/**
 * generate a list with all possible collections for given project
 */
private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();
    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext(); ) {
            Element projekt = iter.next();
            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                    Element col = it2.next();
                    if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }
                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext(); ) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.template.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                            Element col = it2.next();
                            if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }
                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }
    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) DocstructElement(org.goobi.production.importer.DocstructElement) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 53 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class ProzesskopieForm method initializePossibleDigitalCollections.

private void initializePossibleDigitalCollections() {
    this.possibleDigitalCollection = new ArrayList<>();
    ArrayList<String> defaultCollections = new ArrayList<>();
    String filename = this.help.getGoobiConfigDirectory() + "goobi_digitalCollections.xml";
    if (!StorageProvider.getInstance().isFileExists(Paths.get(filename))) {
        Helper.setFehlerMeldung("File not found: ", filename);
        return;
    }
    this.digitalCollections = new ArrayList<>();
    try {
        /* Datei einlesen und Root ermitteln */
        SAXBuilder builder = new SAXBuilder();
        Document doc = builder.build(filename);
        Element root = doc.getRootElement();
        /* alle Projekte durchlaufen */
        List<Element> projekte = root.getChildren();
        for (Iterator<Element> iter = projekte.iterator(); iter.hasNext(); ) {
            Element projekt = iter.next();
            // collect default collections
            if (projekt.getName().equals("default")) {
                List<Element> myCols = projekt.getChildren("DigitalCollection");
                for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                    Element col = it2.next();
                    if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                        digitalCollections.add(col.getText());
                    }
                    defaultCollections.add(col.getText());
                }
            } else {
                // run through the projects
                List<Element> projektnamen = projekt.getChildren("name");
                for (Iterator<Element> iterator = projektnamen.iterator(); iterator.hasNext(); ) {
                    Element projektname = iterator.next();
                    // all all collections to list
                    if (projektname.getText().equalsIgnoreCase(this.prozessKopie.getProjekt().getTitel())) {
                        List<Element> myCols = projekt.getChildren("DigitalCollection");
                        for (Iterator<Element> it2 = myCols.iterator(); it2.hasNext(); ) {
                            Element col = it2.next();
                            if (col.getAttribute("default") != null && col.getAttributeValue("default").equalsIgnoreCase("true")) {
                                digitalCollections.add(col.getText());
                            }
                            this.possibleDigitalCollection.add(col.getText());
                        }
                    }
                }
            }
        }
    } catch (JDOMException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    } catch (IOException e1) {
        log.error("error while parsing digital collections", e1);
        Helper.setFehlerMeldung("Error while parsing digital collections", e1);
    }
    if (this.possibleDigitalCollection.size() == 0) {
        this.possibleDigitalCollection = defaultCollections;
    }
    if (isSingleChoiceCollection()) {
        this.digitalCollections.add(getDigitalCollectionIfSingleChoice());
    }
}
Also used : SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) JDOMException(org.jdom2.JDOMException)

Example 54 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class HelperSchritte method extractAuthorityMetadata.

public static void extractAuthorityMetadata(Path metadataFile, Map<String, List<String>> metadataPairs) {
    XPathFactory xFactory = XPathFactory.instance();
    XPathExpression<Element> authorityMetaXpath = xFactory.compile("//mets:xmlData/mods:mods/mods:extension/goobi:goobi/goobi:metadata[goobi:authorityValue]", Filters.element(), null, mods, mets, goobiNamespace);
    SAXBuilder builder = new SAXBuilder();
    Document doc;
    try {
        doc = builder.build(metadataFile.toString());
    } catch (JDOMException | IOException e1) {
        return;
    }
    for (Element meta : authorityMetaXpath.evaluate(doc)) {
        String name = meta.getAttributeValue("name");
        if (name == null) {
            continue;
        } else {
            String key = name + "_authority";
            List<String> values = metadataPairs.get(key);
            if (values == null) {
                values = new ArrayList<>();
                metadataPairs.put(key, values);
            }
            values.add(meta.getChildText("authorityValue", goobiNamespace));
        }
    }
}
Also used : XPathFactory(org.jdom2.xpath.XPathFactory) SAXBuilder(org.jdom2.input.SAXBuilder) Element(org.jdom2.Element) JsonElement(com.google.gson.JsonElement) IOException(java.io.IOException) Document(org.jdom2.Document) DigitalDocument(ugh.dl.DigitalDocument) JDOMException(org.jdom2.JDOMException)

Example 55 with Document

use of com.forgerock.openbanking.common.model.openbanking.obie.pain00200109.Document in project goobi-workflow by intranda.

the class PluginInstaller method parsePlugin.

private static PluginInstallInfo parsePlugin(Path pluginFolder) throws JDOMException, IOException {
    // TODO: error checking...
    Document pluginPomDocument = parsePomXml(pluginFolder, "pom.xml");
    String name = extractPluginName(pluginPomDocument, pluginFolder);
    String type = extractPluginTypeFromName(name);
    String pluginVersion = pluginVersionXpath.evaluateFirst(pluginPomDocument).getTextTrim();
    Element goobiVersionEle = goobiVersionXpath.evaluateFirst(pluginPomDocument);
    if (goobiVersionEle == null) {
        goobiVersionEle = secondGoobiVersionXpath.evaluateFirst(pluginPomDocument);
    }
    String goobiVersion = goobiVersionEle.getTextTrim();
    List<PluginVersion> versions = Collections.singletonList(new PluginVersion(null, null, goobiVersion, goobiVersion, pluginVersion));
    return new PluginInstallInfo(0, name, type, null, null, versions);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document)

Aggregations

Document (org.jdom2.Document)1034 Element (org.jdom2.Element)587 Test (org.junit.Test)340 SAXBuilder (org.jdom2.input.SAXBuilder)271 IOException (java.io.IOException)266 XMLOutputter (org.jdom2.output.XMLOutputter)182 JDOMException (org.jdom2.JDOMException)162 File (java.io.File)148 ArrayList (java.util.ArrayList)75 InputStream (java.io.InputStream)74 StringReader (java.io.StringReader)63 Path (java.nio.file.Path)59 HashMap (java.util.HashMap)57 DocumentHelper.getDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getDocument)53 DocumentHelper.getElementsFromDocument (com.mulesoft.tools.migration.helper.DocumentHelper.getElementsFromDocument)53 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)48 PID (edu.unc.lib.boxc.model.api.ids.PID)47 Attribute (org.jdom2.Attribute)44 List (java.util.List)42 Namespace (org.jdom2.Namespace)39