Search in sources :

Example 1 with MetadataGroup

use of ugh.dl.MetadataGroup 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 2 with MetadataGroup

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

the class Metadaten method saveGroup.

public String saveGroup() {
    try {
        MetadataGroup md = new MetadataGroup(this.myPrefs.getMetadataGroupTypeByName(this.tempGroupType));
        for (MetadatumImpl mdi : selectedGroup.getMetadataList()) {
            if (StringUtils.isNotBlank(mdi.getMd().getValue())) {
                Metadata metadata = new Metadata(mdi.getMd().getType());
                metadata.setValue(mdi.getMd().getValue());
                md.addMetadata(metadata);
            }
        }
        for (MetaPerson mp : selectedGroup.getPersonList()) {
            Person p = new Person(mp.getP().getType());
            p.setFirstname(mp.getP().getFirstname());
            p.setLastname(mp.getP().getLastname());
            p.setAutorityFile(mp.getP().getAuthorityID(), mp.getP().getAuthorityURI(), mp.getP().getAuthorityValue());
            md.addPerson(p);
        }
        for (MetaCorporate mc : selectedGroup.getCorporateList()) {
            Corporate corporate = new Corporate(mc.getCorporate().getType());
            corporate.setMainName(mc.getCorporate().getMainName());
            corporate.setSubNames(mc.getCorporate().getSubNames());
            corporate.setPartName(mc.getCorporate().getPartName());
            md.addCorporate(currentCorporate);
        }
        if (currentGroup != null) {
            currentGroup.getMetadataGroup().addMetadataGroup(md);
        } else {
            this.myDocStruct.addMetadataGroup(md);
        }
    } catch (MetadataTypeNotAllowedException e) {
        log.error("Error while adding metadata (MetadataTypeNotAllowedException): " + e.getMessage());
    }
    this.modeAddGroup = false;
    for (MetadatumImpl mdi : selectedGroup.getMetadataList()) {
        mdi.setValue("");
    }
    for (MetaPerson mp : selectedGroup.getPersonList()) {
        mp.setVorname("");
        mp.setNachname("");
    }
    for (MetaCorporate mc : selectedGroup.getCorporateList()) {
        mc.setMainName("");
        mc.getSubNames().clear();
        mc.addSubName();
        mc.setPartName("");
    }
    MetadatenalsBeanSpeichern(this.myDocStruct);
    if (!SperrungAktualisieren()) {
        return "metseditor_timeout";
    }
    MetadatenalsTree3Einlesen1(this.tree3, this.currentTopstruct, false);
    return "";
}
Also used : MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) Corporate(ugh.dl.Corporate) MetadataGroup(ugh.dl.MetadataGroup) Metadata(ugh.dl.Metadata) Person(ugh.dl.Person)

Example 3 with MetadataGroup

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

the class Metadaten method AddMetadaFromOpacPpn.

/**
 * eine PPN aus dem Opac abfragen und dessen Metadaten dem aktuellen Strukturelement zuweisen
 * ================================================================
 */
public String AddMetadaFromOpacPpn() {
    StringTokenizer tokenizer = new StringTokenizer(this.additionalOpacPpns, "\n");
    while (tokenizer.hasMoreTokens()) {
        String tok = tokenizer.nextToken();
        try {
            ConfigOpacCatalogue coc = ConfigOpac.getInstance().getCatalogueByName(getOpacKatalog());
            IOpacPlugin iopac = (IOpacPlugin) PluginLoader.getPluginByTitle(PluginType.Opac, coc.getOpacType());
            Fileformat addrdf = iopac.search(this.opacSuchfeld, tok, coc, this.myPrefs);
            if (addrdf != null) {
                // remove empty default elements
                List<Metadata> metadataList = this.myDocStruct.getAllMetadata();
                if (metadataList != null) {
                    List<Metadata> metadataListClone = new ArrayList<>(metadataList);
                    for (Metadata md : metadataListClone) {
                        if (md.getValue() == null || md.getValue().isEmpty()) {
                            this.myDocStruct.removeMetadata(md, true);
                        }
                    }
                }
                List<Person> personList = myDocStruct.getAllPersons();
                if (personList != null) {
                    List<Person> personListClone = new ArrayList<>(personList);
                    for (Person p : personListClone) {
                        if (p.getFirstname().isEmpty() && p.getLastname().isEmpty()) {
                            myDocStruct.removePerson(p);
                        }
                    }
                }
                /* die Liste aller erlaubten Metadatenelemente erstellen */
                List<String> erlaubte = new ArrayList<>();
                for (MetadataType mt : this.myDocStruct.getAddableMetadataTypes(false)) {
                    erlaubte.add(mt.getName());
                }
                /*
                     * wenn der Metadatentyp in der Liste der erlaubten Typen, dann hinzufügen
                     */
                for (Metadata m : addrdf.getDigitalDocument().getLogicalDocStruct().getAllMetadata()) {
                    if (erlaubte.contains(m.getType().getName())) {
                        this.myDocStruct.addMetadata(m);
                    }
                }
                for (Person m : addrdf.getDigitalDocument().getLogicalDocStruct().getAllPersons()) {
                    if (erlaubte.contains(m.getType().getName())) {
                        this.myDocStruct.addPerson(m);
                    }
                }
                for (MetadataGroup m : addrdf.getDigitalDocument().getLogicalDocStruct().getAllMetadataGroups()) {
                    if (myDocStruct.getAddableMetadataGroupTypes().contains(m.getType())) {
                        myDocStruct.addMetadataGroup(m);
                    }
                }
                MetadatenalsTree3Einlesen1(this.tree3, this.currentTopstruct, false);
            } else {
                Helper.setMeldung(null, "Opac abgefragt: ", "kein Ergebnis");
            }
        } catch (Exception e) {
            log.error("Error while importing from catalogue: " + e.getMessage());
        }
    }
    MetadatenalsBeanSpeichern(this.myDocStruct);
    this.modusAnsicht = "Metadaten";
    return "";
}
Also used : IOpacPlugin(org.goobi.production.plugin.interfaces.IOpacPlugin) Metadata(ugh.dl.Metadata) ArrayList(java.util.ArrayList) MetadataType(ugh.dl.MetadataType) MetadataGroup(ugh.dl.MetadataGroup) Fileformat(ugh.dl.Fileformat) TypeNotAllowedAsChildException(ugh.exceptions.TypeNotAllowedAsChildException) JDOMException(org.jdom2.JDOMException) DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) PreferencesException(ugh.exceptions.PreferencesException) WriteException(ugh.exceptions.WriteException) TypeNotAllowedForParentException(ugh.exceptions.TypeNotAllowedForParentException) IncompletePersonObjectException(ugh.exceptions.IncompletePersonObjectException) IOException(java.io.IOException) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) ReadException(ugh.exceptions.ReadException) InvalidImagesException(de.sub.goobi.helper.exceptions.InvalidImagesException) DocStructHasNoTypeException(ugh.exceptions.DocStructHasNoTypeException) StringTokenizer(java.util.StringTokenizer) ConfigOpacCatalogue(de.unigoettingen.sub.search.opac.ConfigOpacCatalogue) Person(ugh.dl.Person)

Example 4 with MetadataGroup

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

the class MetadataGroupImplTest method testGetMyPrefs.

@Test
public void testGetMyPrefs() throws MetadataTypeNotAllowedException {
    MetadataGroup md = new MetadataGroup(prefs.getMetadataGroupTypeByName("junitgrp"));
    MetadataGroupImpl fixture = new MetadataGroupImpl(prefs, process, md, null, "", "", 0);
    assertEquals(prefs, fixture.getMyPrefs());
}
Also used : MetadataGroup(ugh.dl.MetadataGroup) AbstractTest(de.sub.goobi.AbstractTest) Test(org.junit.Test)

Example 5 with MetadataGroup

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

the class MetadataGroupImplTest method testMetadataGroup.

@Test
public void testMetadataGroup() throws MetadataTypeNotAllowedException {
    MetadataGroup md = new MetadataGroup(prefs.getMetadataGroupTypeByName("junitgrp"));
    MetadataGroupImpl fixture = new MetadataGroupImpl(prefs, process, md, null, "", "", 0);
    fixture.setMetadataGroup(md);
    assertEquals(md, fixture.getMetadataGroup());
}
Also used : MetadataGroup(ugh.dl.MetadataGroup) AbstractTest(de.sub.goobi.AbstractTest) Test(org.junit.Test)

Aggregations

MetadataGroup (ugh.dl.MetadataGroup)30 AbstractTest (de.sub.goobi.AbstractTest)14 Test (org.junit.Test)14 Metadata (ugh.dl.Metadata)11 Person (ugh.dl.Person)9 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)8 Corporate (ugh.dl.Corporate)7 MetadataGroupType (ugh.dl.MetadataGroupType)6 ArrayList (java.util.ArrayList)5 DocStruct (ugh.dl.DocStruct)4 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)3 MetadataType (ugh.dl.MetadataType)3 DocStructHasNoTypeException (ugh.exceptions.DocStructHasNoTypeException)3 IOException (java.io.IOException)2 DocStructType (ugh.dl.DocStructType)2 NamePart (ugh.dl.NamePart)2 PreferencesException (ugh.exceptions.PreferencesException)2 TypeNotAllowedAsChildException (ugh.exceptions.TypeNotAllowedAsChildException)2 TypeNotAllowedForParentException (ugh.exceptions.TypeNotAllowedForParentException)2 HelperComparator (de.sub.goobi.helper.HelperComparator)1