Search in sources :

Example 1 with MetadataGroupType

use of ugh.dl.MetadataGroupType in project goobi-workflow by intranda.

the class Metadaten method getMetadataGroupTypes.

public SelectItem[] getMetadataGroupTypes() {
    /*
         * -------------------------------- zuerst mal die addierbaren Metadatentypen ermitteln --------------------------------
         */
    List<MetadataGroupType> types = this.myDocStruct.getAddableMetadataGroupTypes();
    if (types == null) {
        return new SelectItem[0];
    }
    /*
         * -------------------------------- die Metadatentypen sortieren --------------------------------
         */
    HelperComparator c = new HelperComparator();
    c.setSortierart("MetadatenGroupTypes");
    Collections.sort(types, c);
    /*
         * -------------------------------- nun ein Array mit der richtigen Größe anlegen --------------------------------
         */
    int zaehler = types.size();
    SelectItem[] myTypen = new SelectItem[zaehler];
    /*
         * -------------------------------- und anschliessend alle Elemente in das Array packen --------------------------------
         */
    zaehler = 0;
    for (MetadataGroupType mdt : types) {
        myTypen[zaehler] = new SelectItem(mdt.getName(), this.metahelper.getMetadataGroupTypeLanguage(mdt));
        zaehler++;
    }
    /*
         * -------------------------------- alle Typen, die einen Unterstrich haben nochmal rausschmeissen --------------------------------
         */
    SelectItem[] myTypenOhneUnterstrich = new SelectItem[zaehler];
    for (int i = 0; i < zaehler; i++) {
        myTypenOhneUnterstrich[i] = myTypen[i];
    }
    return myTypenOhneUnterstrich;
}
Also used : MetadataGroupType(ugh.dl.MetadataGroupType) SelectItem(javax.faces.model.SelectItem) HelperComparator(de.sub.goobi.helper.HelperComparator)

Example 2 with MetadataGroupType

use of ugh.dl.MetadataGroupType in project goobi-workflow by intranda.

the class Metadaten method getAddableMetadataGroupTypes.

public List<SelectItem> getAddableMetadataGroupTypes() {
    List<SelectItem> myList = new ArrayList<>();
    List<MetadataGroupType> types = null;
    if (currentGroup != null) {
        List<String> groupNames = currentGroup.getMetadataGroup().getAddableMetadataGroupTypes();
        if (groupNames != null) {
            types = new ArrayList<>();
            for (String groupName : groupNames) {
                MetadataGroupType mgt = myPrefs.getMetadataGroupTypeByName(groupName);
                types.add(mgt);
            }
        }
    } else {
        types = this.myDocStruct.getAddableMetadataGroupTypes();
    }
    if (types == null) {
        return myList;
    }
    /*
         * -------------------------------- die Metadatentypen sortieren --------------------------------
         */
    HelperComparator c = new HelperComparator();
    c.setSortierart("MetadatenGroupTypes");
    Collections.sort(types, c);
    for (MetadataGroupType mdt : types) {
        myList.add(new SelectItem(mdt.getName(), this.metahelper.getMetadataGroupTypeLanguage(mdt)));
        try {
            MetadataGroup md = new MetadataGroup(mdt);
            MetadataGroupImpl mdum = new MetadataGroupImpl(myPrefs, myProzess, md, this, metahelper.getMetadataGroupTypeLanguage(mdt), null, 0);
            this.tempMetadataGroups.add(mdum);
        // TODO initialize all fields
        } catch (MetadataTypeNotAllowedException e) {
            log.error("Fehler beim sortieren der Metadaten: " + e.getMessage());
        }
    }
    return myList;
}
Also used : MetadataGroupType(ugh.dl.MetadataGroupType) SelectItem(javax.faces.model.SelectItem) HelperComparator(de.sub.goobi.helper.HelperComparator) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) ArrayList(java.util.ArrayList) MetadataGroup(ugh.dl.MetadataGroup)

Example 3 with MetadataGroupType

use of ugh.dl.MetadataGroupType in project goobi-workflow by intranda.

the class HelperComparator method compareMetadataGroupTypes.

private int compareMetadataGroupTypes(Object o1, Object o2) {
    MetadataGroupType s1 = (MetadataGroupType) o1;
    MetadataGroupType s2 = (MetadataGroupType) o2;
    String name1 = s1.getLanguage(Helper.getMetadataLanguage());
    String name2 = s2.getLanguage(Helper.getMetadataLanguage());
    if (name1 == null) {
        name1 = "";
    }
    if (name2 == null) {
        name2 = "";
    }
    return name1.compareToIgnoreCase(name2);
}
Also used : MetadataGroupType(ugh.dl.MetadataGroupType)

Example 4 with MetadataGroupType

use of ugh.dl.MetadataGroupType 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)

Example 5 with MetadataGroupType

use of ugh.dl.MetadataGroupType in project goobi-workflow by intranda.

the class MetadatenHelper method getMetadataGroupsInclDefaultDisplay.

/**
 * vom übergebenen DocStruct alle Metadaten ermitteln und um die fehlenden DefaultDisplay-Metadaten ergänzen
 * ================================================================
 */
public List<MetadataGroup> getMetadataGroupsInclDefaultDisplay(DocStruct inStruct, String inLanguage, Process inProzess) {
    List<MetadataGroupType> displayMetadataTypes = inStruct.getDefaultDisplayMetadataGroupTypes();
    /* sofern Default-Metadaten vorhanden sind, diese ggf. ergänzen */
    if (displayMetadataTypes != null) {
        for (MetadataGroupType mdt : displayMetadataTypes) {
            // - add it
            if (!(inStruct.getAllMetadataGroupsByType(mdt) != null && inStruct.getAllMetadataGroupsByType(mdt).size() != 0)) {
                try {
                    MetadataGroup md = new MetadataGroup(mdt);
                    // add this new metadata
                    inStruct.addMetadataGroup(md);
                // element
                } catch (DocStructHasNoTypeException e) {
                    continue;
                } catch (MetadataTypeNotAllowedException e) {
                    continue;
                }
            }
        }
    }
    /*
         * wenn keine Sortierung nach Regelsatz erfolgen soll, hier alphabetisch sortieren
         */
    List<MetadataGroup> answer = inStruct.getAllMetadataGroups();
    if (answer != null && !inProzess.getRegelsatz().isOrderMetadataByRuleset()) {
        // order metadata within each group
        for (MetadataGroup mg : answer) {
            Collections.sort(mg.getMetadataList(), new MetadataComparator(inLanguage));
            Collections.sort(mg.getPersonList(), new MetadataComparator(inLanguage));
            Collections.sort(mg.getCorporateList(), new MetadataComparator(inLanguage));
        }
    }
    return answer;
}
Also used : MetadataGroupType(ugh.dl.MetadataGroupType) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) MetadataGroup(ugh.dl.MetadataGroup) DocStructHasNoTypeException(ugh.exceptions.DocStructHasNoTypeException)

Aggregations

MetadataGroupType (ugh.dl.MetadataGroupType)8 MetadataGroup (ugh.dl.MetadataGroup)6 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)5 DocStruct (ugh.dl.DocStruct)3 Metadata (ugh.dl.Metadata)3 HelperComparator (de.sub.goobi.helper.HelperComparator)2 ArrayList (java.util.ArrayList)2 SelectItem (javax.faces.model.SelectItem)2 DocStructType (ugh.dl.DocStructType)2 MetadataType (ugh.dl.MetadataType)2 Person (ugh.dl.Person)2 DocStructHasNoTypeException (ugh.exceptions.DocStructHasNoTypeException)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)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 RestMetadata (org.goobi.api.rest.model.RestMetadata)1 Project (org.goobi.beans.Project)1