Search in sources :

Example 1 with Metadata

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

the class Metadaten method createAddableData.

private void createAddableData() {
    String docstructName = "";
    int selection = Integer.valueOf(neuesElementWohin).intValue();
    if (selection < 3) {
        docstructName = getAddDocStructType1();
    } else {
        docstructName = getAddDocStructType2();
    }
    if (StringUtils.isNotBlank(docstructName) && (oldDocstructName.isEmpty() || !oldDocstructName.equals(docstructName))) {
        oldDocstructName = docstructName;
        addableMetadata = new LinkedList<>();
        if (docstructName != null) {
            DocStructType dst = this.myPrefs.getDocStrctTypeByName(docstructName);
            try {
                DocStruct ds = this.document.createDocStruct(dst);
                List<? extends Metadata> myTempMetadata = this.metahelper.getMetadataInclDefaultDisplay(ds, Helper.getMetadataLanguage(), MetadataTypes.METATDATA, this.myProzess, displayHiddenMetadata);
                if (myTempMetadata != null) {
                    for (Metadata metadata : myTempMetadata) {
                        MetadatumImpl meta = new MetadatumImpl(metadata, 0, this.myPrefs, this.myProzess, this);
                        // meta.getSelectedItem();
                        addableMetadata.add(meta);
                    }
                }
            } catch (TypeNotAllowedForParentException e) {
                log.error(e);
            }
        }
        addablePersondata = new LinkedList<>();
        if (docstructName != null) {
            DocStructType dst = this.myPrefs.getDocStrctTypeByName(docstructName);
            try {
                DocStruct ds = this.document.createDocStruct(dst);
                List<? extends Metadata> myTempMetadata = this.metahelper.getMetadataInclDefaultDisplay(ds, Helper.getMetadataLanguage(), MetadataTypes.PERSON, this.myProzess, displayHiddenMetadata);
                if (myTempMetadata != null) {
                    for (Metadata metadata : myTempMetadata) {
                        MetaPerson meta = new MetaPerson((Person) metadata, 0, this.myPrefs, ds, myProzess, this);
                        addablePersondata.add(meta);
                    }
                }
            } catch (TypeNotAllowedForParentException e) {
                log.error(e);
            }
        }
        addableCorporates = new LinkedList<>();
        if (docstructName != null) {
            DocStructType dst = this.myPrefs.getDocStrctTypeByName(docstructName);
            try {
                DocStruct ds = this.document.createDocStruct(dst);
                List<? extends Metadata> myTempMetadata = this.metahelper.getMetadataInclDefaultDisplay(ds, Helper.getMetadataLanguage(), MetadataTypes.CORPORATE, this.myProzess, displayHiddenMetadata);
                if (myTempMetadata != null) {
                    for (Metadata metadata : myTempMetadata) {
                        addableCorporates.add(new MetaCorporate((Corporate) metadata, myPrefs, ds, myProzess, this));
                    }
                }
            } catch (TypeNotAllowedForParentException e) {
                log.error(e);
            }
        }
    }
}
Also used : TypeNotAllowedForParentException(ugh.exceptions.TypeNotAllowedForParentException) DocStructType(ugh.dl.DocStructType) Corporate(ugh.dl.Corporate) Metadata(ugh.dl.Metadata) DocStruct(ugh.dl.DocStruct)

Example 2 with Metadata

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

the class Metadaten method XMLlesenStart.

/**
 * Metadaten Einlesen
 *
 * @throws ReadException
 * @throws InterruptedException
 * @throws IOException
 * @throws PreferencesException ============================================================ == ==
 * @throws DAOException
 * @throws SwapException
 * @throws WriteException
 */
public String XMLlesenStart() throws ReadException, IOException, InterruptedException, PreferencesException, SwapException, DAOException, WriteException {
    currentRepresentativePage = "";
    this.myPrefs = this.myProzess.getRegelsatz().getPreferences();
    enablePageArea = myPrefs.getDocStrctTypeByName("area") != null;
    this.modusHinzufuegen = false;
    this.modusHinzufuegenPerson = false;
    this.modusStrukturelementVerschieben = false;
    this.modusCopyDocstructFromOtherProcess = false;
    this.currentTifFolder = null;
    readAllTifFolders();
    /*
         * -------------------------------- Dokument einlesen --------------------------------
         */
    this.gdzfile = this.myProzess.readMetadataFile();
    if (gdzfile == null) {
        return null;
    }
    this.document = this.gdzfile.getDigitalDocument();
    this.document.addAllContentFiles();
    this.metahelper = new MetadatenHelper(this.myPrefs, this.document);
    this.imagehelper = new MetadatenImagesHelper(this.myPrefs, this.document);
    /*
         * -------------------------------- Das Hauptelement ermitteln --------------------------------
         */
    this.logicalTopstruct = this.document.getLogicalDocStruct();
    // this exception needs some serious feedback because data is corrupted
    if (this.logicalTopstruct == null) {
        throw new ReadException(Helper.getTranslation("metaDataError"));
    }
    // initialize page area editor
    this.pageAreaManager = new PageAreaManager(this.myPrefs, this.document);
    checkImageNames();
    retrieveAllImages();
    // check filenames, correct them
    // initialize image list
    numberOfImagesPerPage = ConfigurationHelper.getInstance().getMetsEditorNumberOfImagesPerPage();
    thumbnailSizeInPixel = ConfigurationHelper.getInstance().getMetsEditorThumbnailSize();
    pageNo = 0;
    imageIndex = 0;
    loadCurrentImages(true);
    if (this.document.getPhysicalDocStruct().getAllMetadata() != null && this.document.getPhysicalDocStruct().getAllMetadata().size() > 0) {
        List<Metadata> lstMetadata = this.document.getPhysicalDocStruct().getAllMetadata();
        for (Metadata md : lstMetadata) {
            if (md.getType().getName().equals("_representative")) {
                try {
                    Integer value = Integer.valueOf(md.getValue());
                    currentRepresentativePage = String.valueOf(value);
                    updateRepresentativePage();
                } catch (Exception e) {
                }
            }
        }
        DocStruct docstruct = logicalTopstruct;
        if (docstruct.getType().isAnchor()) {
            docstruct = docstruct.getAllChildren().get(0);
        }
        lstMetadata = docstruct.getAllMetadata();
        if (lstMetadata != null) {
            for (Metadata md : lstMetadata) {
                if (md.getType().getName().equals("_directionRTL")) {
                    try {
                        Boolean value = Boolean.valueOf(md.getValue());
                        this.pagesRTL = value;
                    } catch (Exception e) {
                    }
                }
            }
        }
    }
    createDefaultValues(this.logicalTopstruct);
    MetadatenalsBeanSpeichern(this.logicalTopstruct);
    MetadatenalsTree3Einlesen1(this.tree3, this.logicalTopstruct, false);
    physicalTopstruct = document.getPhysicalDocStruct();
    currentTopstruct = logicalTopstruct;
    if (this.nurLesenModus || allImages.isEmpty()) {
        // inserted to make Paginierung the starting view
        this.modusAnsicht = "Metadaten";
    }
    return "metseditor";
}
Also used : ReadException(ugh.exceptions.ReadException) Metadata(ugh.dl.Metadata) 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) DocStruct(ugh.dl.DocStruct)

Example 3 with Metadata

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

the class MetadatenImagesHelper method createPagination.

/**
 * Markus baut eine Seitenstruktur aus den vorhandenen Images ---------------- Steps - ---------------- Validation of images compare existing
 * number images with existing number of page DocStructs if it is the same don't do anything if DocStructs are less add new pages to
 * physicalDocStruct if images are less delete pages from the end of pyhsicalDocStruct --------------------------------
 *
 * @return null
 * @throws TypeNotAllowedForParentException
 * @throws TypeNotAllowedForParentException
 * @throws InterruptedException
 * @throws IOException
 * @throws InterruptedException
 * @throws IOException
 * @throws DAOException
 * @throws SwapException
 */
public void createPagination(Process inProzess, String directory) throws TypeNotAllowedForParentException, IOException, InterruptedException, SwapException, DAOException {
    String mediaFolder = inProzess.getImagesTifDirectory(false);
    String mediaFolderWithFallback = inProzess.getImagesTifDirectory(true);
    DocStruct physicaldocstruct = this.mydocument.getPhysicalDocStruct();
    DocStruct logical = this.mydocument.getLogicalDocStruct();
    if (logical.getType().isAnchor()) {
        if (logical.getAllChildren() != null && logical.getAllChildren().size() > 0) {
            logical = logical.getAllChildren().get(0);
        }
    }
    MetadataType MDTypeForPath = this.myPrefs.getMetadataTypeByName("pathimagefiles");
    /*--------------------------------
         * der physische Baum wird nur
         * angelegt, wenn er noch nicht existierte
         * --------------------------------*/
    if (physicaldocstruct == null) {
        DocStructType dst = this.myPrefs.getDocStrctTypeByName("BoundBook");
        physicaldocstruct = this.mydocument.createDocStruct(dst);
        this.mydocument.setPhysicalDocStruct(physicaldocstruct);
    }
    // check for valid filepath
    try {
        List<? extends Metadata> filepath = physicaldocstruct.getAllMetadataByType(MDTypeForPath);
        if (filepath == null || filepath.isEmpty()) {
            Metadata mdForPath = new Metadata(MDTypeForPath);
            if (SystemUtils.IS_OS_WINDOWS) {
                mdForPath.setValue("file:/" + mediaFolder);
            } else {
                mdForPath.setValue("file://" + mediaFolder);
            }
            physicaldocstruct.addMetadata(mdForPath);
        }
    } catch (Exception e) {
        log.error(e);
    }
    Path folderToCheck = null;
    if (directory == null) {
        folderToCheck = Paths.get(mediaFolderWithFallback);
        checkIfImagesValid(inProzess.getTitel(), mediaFolderWithFallback);
    } else {
        folderToCheck = Paths.get(directory);
        if (!folderToCheck.isAbsolute()) {
            folderToCheck = Paths.get(inProzess.getImagesDirectory(), directory);
        }
        checkIfImagesValid(inProzess.getTitel(), folderToCheck.toString());
    }
    DocStructType typePage = this.myPrefs.getDocStrctTypeByName("page");
    DocStructType typeAudio = this.myPrefs.getDocStrctTypeByName("audio");
    DocStructType typeVideo = this.myPrefs.getDocStrctTypeByName("video");
    DocStructType type3dObject = this.myPrefs.getDocStrctTypeByName("object");
    // use fallback to 'page', if additional types are not configured in ruleset
    if (typeAudio == null) {
        typeAudio = typePage;
    }
    if (typeVideo == null) {
        typeVideo = typePage;
    }
    if (type3dObject == null) {
        type3dObject = typePage;
    }
    /*-------------------------------
         * retrieve existing pages/images
         * -------------------------------*/
    List<DocStruct> oldPages = physicaldocstruct.getAllChildren();
    if (oldPages == null) {
        oldPages = new ArrayList<>();
    }
    if (oldPages.size() == this.myLastImage) {
        return;
    }
    String defaultPagination = ConfigurationHelper.getInstance().getMetsEditorDefaultPagination();
    Map<String, DocStruct> assignedImages = new HashMap<>();
    List<DocStruct> pageElementsWithoutImages = new ArrayList<>();
    List<String> imagesWithoutPageElements = new ArrayList<>();
    if (physicaldocstruct.getAllChildren() != null && !physicaldocstruct.getAllChildren().isEmpty()) {
        List<String> imageFileList = null;
        imageFileList = StorageProvider.getInstance().list(folderToCheck.toString());
        Set<String> imageFileSet = new HashSet<>(imageFileList);
        for (DocStruct page : physicaldocstruct.getAllChildren()) {
            if (page.getImageName() != null) {
                if (imageFileSet.contains(page.getImageName())) {
                    assignedImages.put(page.getImageName(), page);
                } else {
                    try {
                        page.removeContentFile(page.getAllContentFiles().get(0));
                        pageElementsWithoutImages.add(page);
                    } catch (ContentFileNotLinkedException e) {
                        log.error(e);
                    }
                }
            } else {
                pageElementsWithoutImages.add(page);
            }
        }
    }
    try {
        List<String> imageNamesInMediaFolder = getDataFiles(inProzess, directory);
        if (imageNamesInMediaFolder != null && !imageNamesInMediaFolder.isEmpty()) {
            for (String imageName : imageNamesInMediaFolder) {
                if (!assignedImages.containsKey(imageName)) {
                    imagesWithoutPageElements.add(imageName);
                }
            }
        }
    } catch (InvalidImagesException e1) {
        log.error(e1);
    }
    // case 1: existing pages but no images (some images are removed)
    if (!pageElementsWithoutImages.isEmpty() && imagesWithoutPageElements.isEmpty()) {
        for (DocStruct pageToRemove : pageElementsWithoutImages) {
            physicaldocstruct.removeChild(pageToRemove);
            List<Reference> refs = new ArrayList<>(pageToRemove.getAllFromReferences());
            for (ugh.dl.Reference ref : refs) {
                DocStruct source = ref.getSource();
                for (Reference reference : source.getAllToReferences()) {
                    if (reference.getTarget().equals(pageToRemove)) {
                        source.getAllToReferences().remove(reference);
                        break;
                    }
                }
            }
        }
    } else // case 2: no page docs but images (some images are added)
    if (pageElementsWithoutImages.isEmpty() && !imagesWithoutPageElements.isEmpty()) {
        int currentPhysicalOrder = assignedImages.size();
        for (String newImage : imagesWithoutPageElements) {
            String mimetype = NIOFileUtils.getMimeTypeFromFile(Paths.get(newImage));
            DocStruct dsPage = null;
            if (mimetype.startsWith("image")) {
                dsPage = this.mydocument.createDocStruct(typePage);
            } else if (mimetype.startsWith("video") || mimetype.equals("application/mxf")) {
                dsPage = mydocument.createDocStruct(typeVideo);
            } else if (mimetype.startsWith("audio")) {
                dsPage = mydocument.createDocStruct(typeAudio);
            } else if (mimetype.startsWith("object")) {
                dsPage = mydocument.createDocStruct(type3dObject);
            } else if (mimetype.startsWith("model")) {
                dsPage = mydocument.createDocStruct(type3dObject);
            } else {
                // use old implementation as default
                dsPage = mydocument.createDocStruct(typePage);
            }
            try {
                // physical page no
                physicaldocstruct.addChild(dsPage);
                MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
                Metadata mdTemp = new Metadata(mdt);
                mdTemp.setValue(String.valueOf(++currentPhysicalOrder));
                dsPage.addMetadata(mdTemp);
                // logical page no
                mdt = this.myPrefs.getMetadataTypeByName("logicalPageNumber");
                mdTemp = new Metadata(mdt);
                if (defaultPagination.equalsIgnoreCase("arabic")) {
                    mdTemp.setValue(String.valueOf(currentPhysicalOrder));
                } else if (defaultPagination.equalsIgnoreCase("roman")) {
                    RomanNumeral roman = new RomanNumeral();
                    roman.setValue(currentPhysicalOrder);
                    mdTemp.setValue(roman.getNumber());
                } else {
                    mdTemp.setValue("uncounted");
                }
                dsPage.addMetadata(mdTemp);
                logical.addReferenceTo(dsPage, "logical_physical");
                // image name
                ContentFile cf = new ContentFile();
                cf.setMimetype(mimetype);
                if (SystemUtils.IS_OS_WINDOWS) {
                    cf.setLocation("file:/" + mediaFolder + newImage);
                } else {
                    cf.setLocation("file://" + mediaFolder + newImage);
                }
                dsPage.addContentFile(cf);
            } catch (TypeNotAllowedAsChildException e) {
                log.error(e);
            } catch (MetadataTypeNotAllowedException e) {
                log.error(e);
            }
        }
    } else // case 3: empty page docs and unassinged images
    {
        for (DocStruct page : pageElementsWithoutImages) {
            if (!imagesWithoutPageElements.isEmpty()) {
                // assign new image name to page
                String newImageName = imagesWithoutPageElements.get(0);
                imagesWithoutPageElements.remove(0);
                ContentFile cf = new ContentFile();
                if (SystemUtils.IS_OS_WINDOWS) {
                    cf.setLocation("file:/" + mediaFolder + newImageName);
                } else {
                    cf.setLocation("file://" + mediaFolder + newImageName);
                }
                page.addContentFile(cf);
            } else {
                // remove page
                physicaldocstruct.removeChild(page);
                List<Reference> refs = new ArrayList<>(page.getAllFromReferences());
                for (ugh.dl.Reference ref : refs) {
                    ref.getSource().removeReferenceTo(page);
                }
            }
        }
        if (!imagesWithoutPageElements.isEmpty()) {
            // create new page elements
            int currentPhysicalOrder = physicaldocstruct.getAllChildren().size();
            for (String newImage : imagesWithoutPageElements) {
                String mimetype = NIOFileUtils.getMimeTypeFromFile(Paths.get(newImage));
                DocStruct dsPage = null;
                if (mimetype.startsWith("image")) {
                    dsPage = this.mydocument.createDocStruct(typePage);
                } else if (mimetype.startsWith("video") || mimetype.equals("application/mxf")) {
                    dsPage = mydocument.createDocStruct(typeVideo);
                } else if (mimetype.startsWith("audio")) {
                    dsPage = mydocument.createDocStruct(typeAudio);
                } else if (mimetype.startsWith("object")) {
                    dsPage = mydocument.createDocStruct(type3dObject);
                } else if (mimetype.startsWith("model")) {
                    dsPage = mydocument.createDocStruct(type3dObject);
                } else {
                    // use old implementation as default
                    dsPage = mydocument.createDocStruct(typePage);
                }
                try {
                    // physical page no
                    physicaldocstruct.addChild(dsPage);
                    MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
                    Metadata mdTemp = new Metadata(mdt);
                    mdTemp.setValue(String.valueOf(++currentPhysicalOrder));
                    dsPage.addMetadata(mdTemp);
                    // logical page no
                    mdt = this.myPrefs.getMetadataTypeByName("logicalPageNumber");
                    mdTemp = new Metadata(mdt);
                    if (defaultPagination.equalsIgnoreCase("arabic")) {
                        mdTemp.setValue(String.valueOf(currentPhysicalOrder));
                    } else if (defaultPagination.equalsIgnoreCase("roman")) {
                        RomanNumeral roman = new RomanNumeral();
                        roman.setValue(currentPhysicalOrder);
                        mdTemp.setValue(roman.getNumber());
                    } else {
                        mdTemp.setValue("uncounted");
                    }
                    dsPage.addMetadata(mdTemp);
                    logical.addReferenceTo(dsPage, "logical_physical");
                    // image name
                    ContentFile cf = new ContentFile();
                    cf.setMimetype(mimetype);
                    if (SystemUtils.IS_OS_WINDOWS) {
                        cf.setLocation("file:/" + mediaFolder + newImage);
                    } else {
                        cf.setLocation("file://" + mediaFolder + newImage);
                    }
                    dsPage.addContentFile(cf);
                } catch (TypeNotAllowedAsChildException e) {
                    log.error(e);
                } catch (MetadataTypeNotAllowedException e) {
                    log.error(e);
                }
            }
        }
    }
    int currentPhysicalOrder = 1;
    MetadataType mdt = this.myPrefs.getMetadataTypeByName("physPageNumber");
    if (physicaldocstruct.getAllChildren() != null) {
        for (DocStruct page : physicaldocstruct.getAllChildren()) {
            List<? extends Metadata> pageNoMetadata = page.getAllMetadataByType(mdt);
            if (pageNoMetadata == null || pageNoMetadata.size() == 0) {
                currentPhysicalOrder++;
                break;
            }
            for (Metadata pageNo : pageNoMetadata) {
                pageNo.setValue(String.valueOf(currentPhysicalOrder));
            }
            currentPhysicalOrder++;
        }
    }
}
Also used : RomanNumeral(ugh.dl.RomanNumeral) ContentFile(ugh.dl.ContentFile) HashMap(java.util.HashMap) Metadata(ugh.dl.Metadata) ArrayList(java.util.ArrayList) ContentFileNotLinkedException(ugh.exceptions.ContentFileNotLinkedException) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) DocStruct(ugh.dl.DocStruct) HashSet(java.util.HashSet) Path(java.nio.file.Path) TypeNotAllowedAsChildException(ugh.exceptions.TypeNotAllowedAsChildException) Reference(ugh.dl.Reference) MetadataType(ugh.dl.MetadataType) Reference(ugh.dl.Reference) URISyntaxException(java.net.URISyntaxException) TypeNotAllowedAsChildException(ugh.exceptions.TypeNotAllowedAsChildException) DAOException(de.sub.goobi.helper.exceptions.DAOException) SwapException(de.sub.goobi.helper.exceptions.SwapException) ContentLibException(de.unigoettingen.sub.commons.contentlib.exceptions.ContentLibException) TypeNotAllowedForParentException(ugh.exceptions.TypeNotAllowedForParentException) ImageManipulatorException(de.unigoettingen.sub.commons.contentlib.exceptions.ImageManipulatorException) ImageManagerException(de.unigoettingen.sub.commons.contentlib.exceptions.ImageManagerException) IOException(java.io.IOException) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) InvalidImagesException(de.sub.goobi.helper.exceptions.InvalidImagesException) ContentFileNotLinkedException(ugh.exceptions.ContentFileNotLinkedException) InvalidImagesException(de.sub.goobi.helper.exceptions.InvalidImagesException) DocStructType(ugh.dl.DocStructType) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException)

Example 4 with Metadata

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

the class Metadaten method StructSeitenErmitteln2.

/**
 * alle Seiten des aktuellen Strukturelements ermitteln 2 ================================================================
 */
private void StructSeitenErmitteln2(DocStruct inStrukturelement, int inZaehler, List<DocStruct> physicalDocStructs) {
    MetadataType mdt = this.myPrefs.getMetadataTypeByName("logicalPageNumber");
    List<? extends Metadata> listMetadaten = inStrukturelement.getAllMetadataByType(mdt);
    if (listMetadaten == null || listMetadaten.size() == 0) {
        return;
    }
    String pageIdentifier = null;
    if (inStrukturelement.getDocstructType().equals("div")) {
        pageIdentifier = MetadatenErmitteln(inStrukturelement, "physPageNumber");
    } else {
        pageIdentifier = this.pageAreaManager.createPhysicalPageNumberForArea(inStrukturelement, inStrukturelement.getParent());
    }
    for (Metadata meineSeite : listMetadaten) {
        this.structSeitenNeu[inZaehler] = new MetadatumImpl(meineSeite, inZaehler, this.myPrefs, this.myProzess, this);
        DocStruct ds = (DocStruct) meineSeite.getParent();
        if (inStrukturelement.getDocstructType().equals("div")) {
            this.structSeiten[inZaehler] = new SelectItem(pageIdentifier, MetadatenErmitteln(ds, "physPageNumber").trim() + ": " + meineSeite.getValue());
        } else {
            this.structSeiten[inZaehler] = new SelectItem(pageIdentifier, Helper.getTranslation("mets_pageArea", MetadatenErmitteln(ds, "physPageNumber") + ": " + meineSeite.getValue()));
        }
    }
}
Also used : SelectItem(javax.faces.model.SelectItem) MetadataType(ugh.dl.MetadataType) Metadata(ugh.dl.Metadata) DocStruct(ugh.dl.DocStruct)

Example 5 with Metadata

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

the class Metadaten method setRepresentativeMetadata.

public void setRepresentativeMetadata() {
    DocStruct logical = document.getLogicalDocStruct();
    if (logical.getType().isAnchor()) {
        logical = logical.getAllChildren().get(0);
    }
    if (logical.getAllMetadata() != null) {
        boolean match = false;
        for (Metadata md : logical.getAllMetadata()) {
            if (md.getType().getName().equals("_directionRTL")) {
                md.setValue(String.valueOf(this.pagesRTL));
                match = true;
            }
        }
        if (!match) {
            MetadataType mdt = myPrefs.getMetadataTypeByName("_directionRTL");
            if (mdt != null) {
                try {
                    Metadata md = new Metadata(mdt);
                    md.setValue(String.valueOf(this.pagesRTL));
                    logical.addMetadata(md);
                } catch (MetadataTypeNotAllowedException e) {
                }
            }
        }
    }
    boolean match = false;
    if (this.document.getPhysicalDocStruct() != null && this.document.getPhysicalDocStruct().getAllMetadata() != null && this.document.getPhysicalDocStruct().getAllMetadata().size() > 0) {
        for (Metadata md : this.document.getPhysicalDocStruct().getAllMetadata()) {
            if (md.getType().getName().equals("_representative")) {
                if (StringUtils.isNotBlank(currentRepresentativePage)) {
                    Integer value = Integer.valueOf(currentRepresentativePage);
                    md.setValue(String.valueOf(value));
                } else {
                    md.setValue("");
                }
                match = true;
            }
        }
    }
    if (!match) {
        MetadataType mdt = myPrefs.getMetadataTypeByName("_representative");
        try {
            Metadata md = new Metadata(mdt);
            if (StringUtils.isNotBlank(currentRepresentativePage)) {
                Integer value = Integer.valueOf(currentRepresentativePage);
                md.setValue(String.valueOf(value));
            } else {
                md.setValue("");
            }
            this.document.getPhysicalDocStruct().addMetadata(md);
        } catch (MetadataTypeNotAllowedException e) {
        }
    }
}
Also used : MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) Metadata(ugh.dl.Metadata) MetadataType(ugh.dl.MetadataType) DocStruct(ugh.dl.DocStruct)

Aggregations

Metadata (ugh.dl.Metadata)81 MetadataType (ugh.dl.MetadataType)33 DocStruct (ugh.dl.DocStruct)31 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)31 AbstractTest (de.sub.goobi.AbstractTest)18 ArrayList (java.util.ArrayList)18 Test (org.junit.Test)18 DocStructHasNoTypeException (ugh.exceptions.DocStructHasNoTypeException)16 UghHelperException (de.sub.goobi.helper.exceptions.UghHelperException)15 Person (ugh.dl.Person)15 MetadataGroup (ugh.dl.MetadataGroup)12 IOException (java.io.IOException)11 Corporate (ugh.dl.Corporate)11 DocStructType (ugh.dl.DocStructType)10 DAOException (de.sub.goobi.helper.exceptions.DAOException)9 PreferencesException (ugh.exceptions.PreferencesException)9 SwapException (de.sub.goobi.helper.exceptions.SwapException)8 List (java.util.List)8 Reference (ugh.dl.Reference)8 TypeNotAllowedForParentException (ugh.exceptions.TypeNotAllowedForParentException)8