Search in sources :

Example 1 with RestMetadata

use of org.goobi.api.rest.model.RestMetadata in project goobi-workflow by intranda.

the class MetadataUtils method extractMetadataFromFile.

private static void extractMetadataFromFile(Path metsPath, RestProcess p, Map<String, Map<String, String>> labelMap, SearchRequest req) {
    if (!Files.exists(metsPath)) {
        return;
    }
    Document doc;
    try (InputStream in = Files.newInputStream(metsPath)) {
        doc = builder.build(in);
    } catch (JDOMException | IOException e) {
        log.error(e);
        return;
    }
    for (Element el : authorityMetaXpath.evaluate(doc)) {
        RestMetadata meta = new RestMetadata();
        String name = el.getAttributeValue("name");
        if (req.getWantedFields() != null && !req.getWantedFields().contains(name)) {
            continue;
        }
        String type = el.getAttributeValue("type");
        if ("person".equals(type)) {
            meta.setValue(el.getChildText("displayName", goobiNamespace));
        } else {
            meta.setValue(el.getText());
        }
        meta.setAuthorityID(el.getChildText("authorityID", goobiNamespace));
        meta.setAuthorityURI(el.getChildText("authorityURI", goobiNamespace));
        meta.setAuthorityValue(el.getChildText("authorityValue", goobiNamespace));
        meta.setLabels(labelMap.get(name));
        p.addMetadata(name, meta);
    }
}
Also used : InputStream(java.io.InputStream) Element(org.jdom2.Element) RestMetadata(org.goobi.api.rest.model.RestMetadata) IOException(java.io.IOException) Document(org.jdom2.Document) JDOMException(org.jdom2.JDOMException)

Example 2 with RestMetadata

use of org.goobi.api.rest.model.RestMetadata in project goobi-workflow by intranda.

the class MetadatumImpl method linkProcess.

public void linkProcess(RestProcess rp) {
    Project p = this.getBean().getMyProzess().getProjekt();
    XMLConfiguration xmlConf = ConfigPlugins.getPluginConfig("ProcessPlugin");
    if (xmlConf == null) {
        return;
    }
    HierarchicalConfiguration use = getConfigForProject(p, xmlConf);
    Map<String, List<RestMetadata>> addMetadata = new HashMap<>();
    List<HierarchicalConfiguration> mappings = use.configurationsAt("mapping");
    for (HierarchicalConfiguration mapping : mappings) {
        String from = mapping.getString("[@from]");
        String to = mapping.getString("[@to]");
        List<RestMetadata> fromMeta = rp.getMetadata().get(from);
        if (fromMeta != null) {
            addMetadata.put(to, fromMeta);
        }
    }
    Prefs prefs = this.getBean().getMyPrefs();
    DocStruct ds = this.getBean().getMyDocStruct();
    for (String name : addMetadata.keySet()) {
        try {
            for (RestMetadata rmd : addMetadata.get(name)) {
                if (!rmd.anyValue()) {
                    continue;
                }
                if (name.contains("/")) {
                    String[] split = name.split("/");
                    String group = split[0];
                    String metaName = split[1];
                    MetadataGroupType mgt = prefs.getMetadataGroupTypeByName(group);
                    MetadataGroup addGroup = null;
                    addGroup = new MetadataGroup(mgt);
                    List<Metadata> metaList = addGroup.getMetadataByType(metaName);
                    Metadata md;
                    if (metaList.isEmpty()) {
                        md = new Metadata(prefs.getMetadataTypeByName(metaName));
                        addGroup.addMetadata(md);
                    } else {
                        md = metaList.get(0);
                    }
                    if (rmd.getValue() != null) {
                        md.setValue(rmd.getValue());
                    }
                    if (rmd.getAuthorityID() != null) {
                        md.setAuthorityID(rmd.getAuthorityID());
                    }
                    if (rmd.getAuthorityURI() != null) {
                        md.setAuthorityURI(rmd.getAuthorityURI());
                    }
                    if (rmd.getAuthorityValue() != null) {
                        md.setAuthorityValue(rmd.getAuthorityValue());
                    }
                    ds.addMetadataGroup(addGroup);
                } else {
                    Metadata md = new Metadata(prefs.getMetadataTypeByName(name));
                    if (rmd.getValue() != null) {
                        md.setValue(rmd.getValue());
                    }
                    if (rmd.getAuthorityID() != null) {
                        md.setAuthorityID(rmd.getAuthorityID());
                    }
                    if (rmd.getAuthorityURI() != null) {
                        md.setAuthorityURI(rmd.getAuthorityURI());
                    }
                    if (rmd.getAuthorityValue() != null) {
                        md.setAuthorityValue(rmd.getAuthorityValue());
                    }
                    ds.addMetadata(md);
                }
            }
        } catch (MetadataTypeNotAllowedException e) {
            Helper.setFehlerMeldung("Metadata " + name + " not allowed in preferences.", e);
        }
    }
    this.getBean().reloadMetadataList();
}
Also used : HashMap(java.util.HashMap) MetadataGroup(ugh.dl.MetadataGroup) Metadata(ugh.dl.Metadata) RestMetadata(org.goobi.api.rest.model.RestMetadata) RestMetadata(org.goobi.api.rest.model.RestMetadata) HierarchicalConfiguration(org.apache.commons.configuration.HierarchicalConfiguration) Prefs(ugh.dl.Prefs) MetadataGroupType(ugh.dl.MetadataGroupType) Project(org.goobi.beans.Project) XMLConfiguration(org.apache.commons.configuration.XMLConfiguration) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) List(java.util.List) ArrayList(java.util.ArrayList) DocStruct(ugh.dl.DocStruct)

Aggregations

RestMetadata (org.goobi.api.rest.model.RestMetadata)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 HierarchicalConfiguration (org.apache.commons.configuration.HierarchicalConfiguration)1 XMLConfiguration (org.apache.commons.configuration.XMLConfiguration)1 Project (org.goobi.beans.Project)1 Document (org.jdom2.Document)1 Element (org.jdom2.Element)1 JDOMException (org.jdom2.JDOMException)1 DocStruct (ugh.dl.DocStruct)1 Metadata (ugh.dl.Metadata)1 MetadataGroup (ugh.dl.MetadataGroup)1 MetadataGroupType (ugh.dl.MetadataGroupType)1 Prefs (ugh.dl.Prefs)1 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)1