Search in sources :

Example 1 with DigitalDocument

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

the class FileManipulation method updatePagination.

private void updatePagination(String filename) throws TypeNotAllowedForParentException, IOException, InterruptedException, SwapException, DAOException, MetadataTypeNotAllowedException {
    if (!matchesFileConfiguration(filename)) {
        return;
    }
    if (insertPage.equals("lastPage")) {
        metadataBean.createPagination();
    } else {
        Prefs prefs = metadataBean.getMyProzess().getRegelsatz().getPreferences();
        DigitalDocument doc = metadataBean.getDocument();
        DocStruct physical = doc.getPhysicalDocStruct();
        List<DocStruct> pageList = physical.getAllChildren();
        int indexToImport = Math.max(Integer.parseInt(insertPage) - 1, 0);
        DocStructType newPageType = prefs.getDocStrctTypeByName("page");
        DocStruct newPage = doc.createDocStruct(newPageType);
        MetadataType physicalPageNoType = prefs.getMetadataTypeByName("physPageNumber");
        MetadataType logicalPageNoType = prefs.getMetadataTypeByName("logicalPageNumber");
        for (int index = 0; index < pageList.size(); index++) {
            if (index == indexToImport) {
                DocStruct oldPage = pageList.get(index);
                // physical page no for new page
                Metadata mdTemp = new Metadata(physicalPageNoType);
                mdTemp.setValue(String.valueOf(indexToImport + 1));
                newPage.addMetadata(mdTemp);
                // new physical page no for old page
                oldPage.getAllMetadataByType(physicalPageNoType).get(0).setValue(String.valueOf(indexToImport + 2));
                // logical page no
                // logicalPageNoType = prefs.getMetadataTypeByName("logicalPageNumber");
                mdTemp = new Metadata(logicalPageNoType);
                if (insertMode.equalsIgnoreCase("uncounted")) {
                    mdTemp.setValue("uncounted");
                } else {
                    // set new logical no. for new and old page
                    Metadata oldPageNo = oldPage.getAllMetadataByType(logicalPageNoType).get(0);
                    mdTemp.setValue(oldPageNo.getValue());
                    if (index + 1 < pageList.size()) {
                        Metadata pageNoOfFollowingElement = pageList.get(index + 1).getAllMetadataByType(logicalPageNoType).get(0);
                        oldPageNo.setValue(pageNoOfFollowingElement.getValue());
                    } else {
                        oldPageNo.setValue("uncounted");
                    }
                }
                newPage.addMetadata(mdTemp);
                doc.getLogicalDocStruct().addReferenceTo(newPage, "logical_physical");
                ContentFile cf = new ContentFile();
                cf.setLocation(filename);
                newPage.addContentFile(cf);
                doc.getFileSet().addFile(cf);
            }
            if (index > indexToImport) {
                DocStruct currentPage = pageList.get(index);
                // check if element is last element
                currentPage.getAllMetadataByType(physicalPageNoType).get(0).setValue(String.valueOf(index + 2));
                if (!insertMode.equalsIgnoreCase("uncounted")) {
                    if (index + 1 == pageList.size()) {
                        currentPage.getAllMetadataByType(logicalPageNoType).get(0).setValue("uncounted");
                    } else {
                        DocStruct followingPage = pageList.get(index + 1);
                        currentPage.getAllMetadataByType(logicalPageNoType).get(0).setValue(followingPage.getAllMetadataByType(logicalPageNoType).get(0).getValue());
                    }
                }
            }
        }
        pageList.add(indexToImport, newPage);
    }
}
Also used : ContentFile(ugh.dl.ContentFile) DocStructType(ugh.dl.DocStructType) MetadataType(ugh.dl.MetadataType) Metadata(ugh.dl.Metadata) Prefs(ugh.dl.Prefs) DigitalDocument(ugh.dl.DigitalDocument) DocStruct(ugh.dl.DocStruct)

Example 2 with DigitalDocument

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

the class XmlArtikelZaehlen method getNumberOfUghElements.

/**
 * Anzahl der Strukturelemente ermitteln
 *
 * @param myProzess
 */
public int getNumberOfUghElements(Process myProzess, CountType inType) {
    int rueckgabe = 0;
    /* --------------------------------
         * Dokument einlesen
         * --------------------------------*/
    Fileformat gdzfile;
    try {
        gdzfile = myProzess.readMetadataFile();
    } catch (Exception e) {
        Helper.setFehlerMeldung("xml error", e.getMessage());
        return -1;
    }
    /* --------------------------------
         * DocStruct rukursiv durchlaufen
         * --------------------------------*/
    DigitalDocument mydocument = null;
    try {
        mydocument = gdzfile.getDigitalDocument();
        DocStruct logicalTopstruct = mydocument.getLogicalDocStruct();
        rueckgabe += getNumberOfUghElements(logicalTopstruct, inType);
    } catch (PreferencesException e1) {
        Helper.setFehlerMeldung("[" + myProzess.getId() + "] Can not get DigitalDocument: ", e1.getMessage());
        log.error(e1);
        rueckgabe = 0;
    }
    /* --------------------------------
         * die ermittelte Zahl im Prozess speichern
         * --------------------------------*/
    myProzess.setSortHelperArticles(Integer.valueOf(rueckgabe));
    try {
        ProcessManager.saveProcess(myProzess);
    } catch (DAOException e) {
        log.error(e);
    }
    return rueckgabe;
}
Also used : DAOException(de.sub.goobi.helper.exceptions.DAOException) Fileformat(ugh.dl.Fileformat) DigitalDocument(ugh.dl.DigitalDocument) PreferencesException(ugh.exceptions.PreferencesException) DAOException(de.sub.goobi.helper.exceptions.DAOException) PreferencesException(ugh.exceptions.PreferencesException) DocStruct(ugh.dl.DocStruct)

Example 3 with DigitalDocument

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

the class CopyProcess method NeuenProzessAnlegen2.

/**
 * Anlegen des Prozesses und Speichern der Metadaten ================================================================
 *
 * @throws DAOException
 * @throws SwapException
 * @throws WriteException
 */
public Process NeuenProzessAnlegen2() throws ReadException, IOException, InterruptedException, PreferencesException, SwapException, DAOException, WriteException {
    this.prozessKopie.setId(null);
    EigenschaftenHinzufuegen(null);
    for (Step step : this.prozessKopie.getSchritteList()) {
        /*
             * -------------------------------- always save date and user for each step --------------------------------
             */
        step.setBearbeitungszeitpunkt(this.prozessKopie.getErstellungsdatum());
        step.setEditTypeEnum(StepEditType.AUTOMATIC);
        User user = Helper.getCurrentUser();
        if (user != null) {
            step.setBearbeitungsbenutzer(user);
        }
        /*
             * -------------------------------- only if its done, set edit start and end date --------------------------------
             */
        if (step.getBearbeitungsstatusEnum() == StepStatus.DONE) {
            step.setBearbeitungsbeginn(this.prozessKopie.getErstellungsdatum());
            // this concerns steps, which are set as done right on creation
            // bearbeitungsbeginn is set to creation timestamp of process
            // because the creation of it is basically begin of work
            Date myDate = new Date();
            step.setBearbeitungszeitpunkt(myDate);
            step.setBearbeitungsende(myDate);
        }
    }
    try {
        ProcessManager.saveProcess(this.prozessKopie);
    // dao.refresh(this.prozessKopie);
    } catch (DAOException e) {
        e.printStackTrace();
        log.error("error on save: ", e);
        return this.prozessKopie;
    }
    /*
         * wenn noch keine RDF-Datei vorhanden ist (weil keine Opac-Abfrage stattfand, dann jetzt eine anlegen
         */
    if (this.myRdf == null) {
        createNewFileformat();
    }
    // * --------------------------------*/
    if (this.updateData) {
        if (this.myRdf != null) {
            for (AdditionalField field : this.additionalFields) {
                if (field.isUghbinding() && field.getShowDependingOnDoctype(getDocType())) {
                    /* welches Docstruct */
                    DocStruct myTempStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();
                    DocStruct myTempChild = null;
                    if (field.getDocstruct().equals("firstchild")) {
                        try {
                            myTempStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct().getAllChildren().get(0);
                        } catch (RuntimeException e) {
                        /*
                                 * das Firstchild unterhalb des Topstructs konnte nicht ermittelt werden
                                 */
                        }
                    }
                    /*
                         * falls topstruct und firstchild das Metadatum bekommen sollen
                         */
                    if (!field.getDocstruct().equals("firstchild") && field.getDocstruct().contains("firstchild")) {
                        try {
                            myTempChild = this.myRdf.getDigitalDocument().getLogicalDocStruct().getAllChildren().get(0);
                        } catch (RuntimeException e) {
                        }
                    }
                    if (field.getDocstruct().equals("boundbook")) {
                        myTempStruct = this.myRdf.getDigitalDocument().getPhysicalDocStruct();
                    }
                    /* welches Metadatum */
                    try {
                        /*
                             * bis auf die Autoren alle additionals in die Metadaten übernehmen
                             */
                        if (!field.getMetadata().equals("ListOfCreators")) {
                            MetadataType mdt = this.ughHelp.getMetadataType(this.prozessKopie.getRegelsatz().getPreferences(), field.getMetadata());
                            Metadata md = this.ughHelp.getMetadata(myTempStruct, mdt);
                            /*
                                 * wenn das Metadatum null ist, dann jetzt initialisieren
                                 */
                            if (md == null) {
                                md = new Metadata(mdt);
                                md.setParent(myTempStruct);
                                myTempStruct.addMetadata(md);
                            }
                            md.setValue(field.getWert());
                            /*
                                 * wenn dem Topstruct und dem Firstchild der Wert gegeben werden soll
                                 */
                            if (myTempChild != null) {
                                md = this.ughHelp.getMetadata(myTempChild, mdt);
                                md.setValue(field.getWert());
                            }
                        }
                    } catch (NullPointerException e) {
                    } catch (UghHelperException e) {
                    } catch (MetadataTypeNotAllowedException e) {
                    }
                }
            // end if ughbinding
            }
            // end for
            /*
                 * -------------------------------- Collectionen hinzufügen --------------------------------
                 */
            DocStruct colStruct = this.myRdf.getDigitalDocument().getLogicalDocStruct();
            try {
                addCollections(colStruct);
                /*
                     * falls ein erstes Kind vorhanden ist, sind die Collectionen dafür
                     */
                colStruct = colStruct.getAllChildren().get(0);
                addCollections(colStruct);
            } catch (RuntimeException e) {
            /*
                     * das Firstchild unterhalb des Topstructs konnte nicht ermittelt werden
                     */
            }
            /*
                 * -------------------------------- Imagepfad hinzufügen (evtl. vorhandene zunächst löschen) --------------------------------
                 */
            try {
                DigitalDocument dd = this.myRdf.getDigitalDocument();
                DocStructType dst = this.prozessVorlage.getRegelsatz().getPreferences().getDocStrctTypeByName("BoundBook");
                DocStruct dsBoundBook = dd.createDocStruct(dst);
                dd.setPhysicalDocStruct(dsBoundBook);
                UghHelper ughhelp = new UghHelper();
                MetadataType mdt = ughhelp.getMetadataType(this.prozessKopie, "pathimagefiles");
                if (this.myRdf != null && this.myRdf.getDigitalDocument() != null && this.myRdf.getDigitalDocument().getPhysicalDocStruct() != null) {
                    List<? extends Metadata> alleImagepfade = this.myRdf.getDigitalDocument().getPhysicalDocStruct().getAllMetadataByType(mdt);
                    if (alleImagepfade != null && alleImagepfade.size() > 0) {
                        for (Metadata md : alleImagepfade) {
                            this.myRdf.getDigitalDocument().getPhysicalDocStruct().getAllMetadata().remove(md);
                        }
                    }
                    Metadata newmd = new Metadata(mdt);
                    newmd.setValue(prozessKopie.getImagesTifDirectory(false));
                    this.myRdf.getDigitalDocument().getPhysicalDocStruct().addMetadata(newmd);
                }
                /* Rdf-File schreiben */
                this.prozessKopie.writeMetadataFile(this.myRdf);
                /*
                     * -------------------------------- soll der Prozess als Vorlage verwendet werden? --------------------------------
                     */
                if (this.useTemplates && this.prozessKopie.isInAuswahllisteAnzeigen()) {
                    this.prozessKopie.writeMetadataAsTemplateFile(this.myRdf);
                }
            } catch (ugh.exceptions.DocStructHasNoTypeException e) {
                Helper.setFehlerMeldung("DocStructHasNoTypeException", e.getMessage());
                log.error("creation of new process throws an error: ", e);
            } catch (UghHelperException e) {
                Helper.setFehlerMeldung("UghHelperException", e.getMessage());
                log.error("creation of new process throws an error: ", e);
            } catch (MetadataTypeNotAllowedException e) {
                Helper.setFehlerMeldung("MetadataTypeNotAllowedException", e.getMessage());
                log.error("creation of new process throws an error: ", e);
            } catch (TypeNotAllowedForParentException e) {
                log.error(e);
            }
        }
    } else {
        this.prozessKopie.writeMetadataFile(this.myRdf);
    }
    // Adding process to history
    if (!HistoryAnalyserJob.updateHistoryForProzess(this.prozessKopie)) {
        Helper.setFehlerMeldung("historyNotUpdated");
    } else {
        try {
            ProcessManager.saveProcess(this.prozessKopie);
        } catch (DAOException e) {
            e.printStackTrace();
            log.error("error on save: ", e);
            return this.prozessKopie;
        }
    }
    this.prozessKopie.readMetadataFile();
    return this.prozessKopie;
}
Also used : TypeNotAllowedForParentException(ugh.exceptions.TypeNotAllowedForParentException) User(org.goobi.beans.User) MetadataType(ugh.dl.MetadataType) Metadata(ugh.dl.Metadata) Step(org.goobi.beans.Step) DigitalDocument(ugh.dl.DigitalDocument) Date(java.util.Date) DAOException(de.sub.goobi.helper.exceptions.DAOException) DocStructHasNoTypeException(ugh.exceptions.DocStructHasNoTypeException) AdditionalField(de.sub.goobi.forms.AdditionalField) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) DocStructType(ugh.dl.DocStructType) UghHelperException(de.sub.goobi.helper.exceptions.UghHelperException) UghHelper(de.sub.goobi.helper.UghHelper) DocStruct(ugh.dl.DocStruct)

Example 4 with DigitalDocument

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

the class ExportMets method collectMetadataToSave.

private ExportFileformat collectMetadataToSave(Process myProzess, Fileformat gdzfile, boolean writeLocalFilegroup, ConfigurationHelper config) throws IOException, InterruptedException, SwapException, DAOException, PreferencesException, TypeNotAllowedForParentException {
    ExportFileformat mm = MetadatenHelper.getExportFileformatByName(myProzess.getProjekt().getFileFormatDmsExport(), myProzess.getRegelsatz());
    mm.setWriteLocal(writeLocalFilegroup);
    mm.setCreateUUIDs(config.isExportCreateUUIDsAsFileIDs());
    String imageFolderPath = myProzess.getImagesTifDirectory(true);
    Path imageFolder = Paths.get(imageFolderPath);
    /*
         * before creating mets file, change relative path to absolute -
         */
    DigitalDocument dd = gdzfile.getDigitalDocument();
    MetadatenImagesHelper mih = new MetadatenImagesHelper(this.myPrefs, dd);
    if (dd.getFileSet() == null || dd.getFileSet().getAllFiles().isEmpty()) {
        Helper.setMeldung(myProzess.getTitel() + ": digital document does not contain images; adding them for mets file creation");
        mih.createPagination(myProzess, null);
        try {
            myProzess.writeMetadataFile(gdzfile);
        } catch (UGHException | IOException | InterruptedException | SwapException | DAOException e) {
            log.error(e);
        }
    } else {
        mih.checkImageNames(myProzess, imageFolder.getFileName().toString());
    }
    /*
         * get the topstruct element of the digital document depending on anchor property
         */
    DocStruct topElement = dd.getLogicalDocStruct();
    if (topElement.getType().isAnchor()) {
        if (topElement.getAllChildren() == null || topElement.getAllChildren().size() == 0) {
            throw new PreferencesException(myProzess.getTitel() + ": the topstruct element is marked as anchor, but does not have any children for physical docstrucs");
        } else {
            topElement = topElement.getAllChildren().get(0);
        }
    }
    if (config.isExportValidateImages()) {
        if (topElement.getAllToReferences("logical_physical") == null || topElement.getAllToReferences("logical_physical").size() == 0) {
            if (dd.getPhysicalDocStruct() != null && dd.getPhysicalDocStruct().getAllChildren() != null) {
                Helper.setMeldung(myProzess.getTitel() + ": topstruct element does not have any referenced images yet; temporarily adding them for mets file creation");
                for (DocStruct mySeitenDocStruct : dd.getPhysicalDocStruct().getAllChildren()) {
                    topElement.addReferenceTo(mySeitenDocStruct, "logical_physical");
                }
            } else {
                Helper.setFehlerMeldung(myProzess.getTitel() + ": could not find any referenced images, export aborted");
                dd = null;
                return null;
            }
        }
        for (ContentFile cf : dd.getFileSet().getAllFiles()) {
            String location = cf.getLocation();
            // use the file protocol.
            if (!location.contains("://")) {
                if (!location.matches("^[A-Z]:.*") && !location.matches("^\\/.*")) {
                    // is a relative path
                    Path f = Paths.get(imageFolder.toString(), location);
                    location = f.toString();
                }
                location = "file://" + location;
            }
            cf.setLocation(location);
        }
    }
    mm.setDigitalDocument(dd);
    // if configured, extract metadata from files and store them as techMd premis
    if (config.isExportCreateTechnicalMetadata()) {
        int counter = 1;
        for (DocStruct page : dd.getPhysicalDocStruct().getAllChildren()) {
            Path path = Paths.get(page.getImageName());
            if (!path.isAbsolute()) {
                path = Paths.get(imageFolder.toString(), page.getImageName());
            }
            Element techMd = createTechMd(path);
            if (techMd != null) {
                Md md = new Md(techMd);
                md.setType("techMD");
                md.setId(String.format("AMD_%04d", counter++));
                dd.addTechMd(md);
                page.setAdmId(md.getId());
            }
        }
    }
    Map<String, String> additionalMetadataMap = config.getExportWriteAdditionalMetadata();
    if (!additionalMetadataMap.isEmpty()) {
        String projectMetadataName = additionalMetadataMap.get("Project");
        String institutionMetadataName = additionalMetadataMap.get("Institution");
        Prefs prefs = myProzess.getRegelsatz().getPreferences();
        if (StringUtils.isNotBlank(projectMetadataName)) {
            MetadataType mdt = prefs.getMetadataTypeByName(projectMetadataName);
            if (mdt != null) {
                try {
                    ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
                    md.setValue(myProzess.getProjekt().getTitel());
                    topElement.addMetadata(md);
                } catch (MetadataTypeNotAllowedException e) {
                    log.warn("Configured metadata for project name is unknown or not allowed.");
                }
                if (topElement.getParent() != null) {
                    try {
                        ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
                        md.setValue(myProzess.getProjekt().getTitel());
                        topElement.getParent().addMetadata(md);
                    } catch (MetadataTypeNotAllowedException e) {
                        log.warn("Configured metadata for project name is unknown or not allowed.");
                    }
                }
            }
        }
        if (StringUtils.isNotBlank(institutionMetadataName)) {
            MetadataType mdt = prefs.getMetadataTypeByName(institutionMetadataName);
            if (mdt != null) {
                try {
                    ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
                    md.setValue(myProzess.getProjekt().getInstitution().getLongName());
                    topElement.addMetadata(md);
                } catch (MetadataTypeNotAllowedException e) {
                    log.warn("Configured metadata for institution name is unknown or not allowed.");
                }
                if (topElement.getParent() != null) {
                    try {
                        ugh.dl.Metadata md = new ugh.dl.Metadata(mdt);
                        md.setValue(myProzess.getProjekt().getInstitution().getLongName());
                        topElement.getParent().addMetadata(md);
                    } catch (MetadataTypeNotAllowedException e) {
                        log.warn("Configured metadata for institution name is unknown or not allowed.");
                    }
                }
            }
        }
    }
    /*
         * -------------------------------- wenn Filegroups definiert wurden, werden diese jetzt in die Metsstruktur übernommen
         * --------------------------------
         */
    // Replace all pathes with the given VariableReplacer, also the file
    // group pathes!
    VariableReplacer vp = new VariableReplacer(mm.getDigitalDocument(), this.myPrefs, myProzess, null);
    List<ProjectFileGroup> myFilegroups = myProzess.getProjekt().getFilegroups();
    boolean useOriginalFiles = false;
    if (myFilegroups != null && myFilegroups.size() > 0) {
        for (ProjectFileGroup pfg : myFilegroups) {
            if (pfg.isUseOriginalFiles()) {
                useOriginalFiles = true;
            }
            // check if source files exists
            if (pfg.getFolder() != null && pfg.getFolder().length() > 0) {
                String foldername = myProzess.getMethodFromName(pfg.getFolder());
                if (foldername != null) {
                    Path folder = Paths.get(myProzess.getMethodFromName(pfg.getFolder()));
                    if (folder != null && StorageProvider.getInstance().isFileExists(folder) && !StorageProvider.getInstance().list(folder.toString()).isEmpty()) {
                        VirtualFileGroup v = createFilegroup(vp, pfg);
                        mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
                    }
                }
            } else {
                VirtualFileGroup v = createFilegroup(vp, pfg);
                mm.getDigitalDocument().getFileSet().addVirtualFileGroup(v);
            }
        }
    }
    if (useOriginalFiles) {
        // check if media folder contains images
        List<Path> filesInFolder = StorageProvider.getInstance().listFiles(myProzess.getImagesTifDirectory(false));
        if (!filesInFolder.isEmpty()) {
            // compare image names with files in mets file
            List<DocStruct> pages = dd.getPhysicalDocStruct().getAllChildren();
            if (pages != null && pages.size() > 0) {
                for (DocStruct page : pages) {
                    Path completeNameInMets = Paths.get(page.getImageName());
                    String filenameInMets = completeNameInMets.getFileName().toString();
                    int dotIndex = filenameInMets.lastIndexOf('.');
                    if (dotIndex != -1) {
                        filenameInMets = filenameInMets.substring(0, dotIndex);
                    }
                    for (Path imageNameInFolder : filesInFolder) {
                        String imageName = imageNameInFolder.getFileName().toString();
                        dotIndex = imageName.lastIndexOf('.');
                        if (dotIndex != -1) {
                            imageName = imageName.substring(0, dotIndex);
                        }
                        if (filenameInMets.toLowerCase().equals(imageName.toLowerCase())) {
                            // found matching filename
                            page.setImageName(imageNameInFolder.toString());
                            break;
                        }
                    }
                }
            // replace filename in mets file
            }
        }
    }
    // Replace rights and digiprov entries.
    mm.setRightsOwner(vp.replace(myProzess.getProjekt().getMetsRightsOwner()));
    mm.setRightsOwnerLogo(vp.replace(myProzess.getProjekt().getMetsRightsOwnerLogo()));
    mm.setRightsOwnerSiteURL(vp.replace(myProzess.getProjekt().getMetsRightsOwnerSite()));
    mm.setRightsOwnerContact(vp.replace(myProzess.getProjekt().getMetsRightsOwnerMail()));
    mm.setDigiprovPresentation(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentation()));
    mm.setDigiprovReference(vp.replace(myProzess.getProjekt().getMetsDigiprovReference()));
    mm.setDigiprovPresentationAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovPresentationAnchor()));
    mm.setDigiprovReferenceAnchor(vp.replace(myProzess.getProjekt().getMetsDigiprovReferenceAnchor()));
    mm.setMetsRightsLicense(vp.replace(myProzess.getProjekt().getMetsRightsLicense()));
    mm.setMetsRightsSponsor(vp.replace(myProzess.getProjekt().getMetsRightsSponsor()));
    mm.setMetsRightsSponsorLogo(vp.replace(myProzess.getProjekt().getMetsRightsSponsorLogo()));
    mm.setMetsRightsSponsorSiteURL(vp.replace(myProzess.getProjekt().getMetsRightsSponsorSiteURL()));
    mm.setPurlUrl(vp.replace(myProzess.getProjekt().getMetsPurl()));
    mm.setContentIDs(vp.replace(myProzess.getProjekt().getMetsContentIDs()));
    String pointer = myProzess.getProjekt().getMetsPointerPath();
    pointer = vp.replace(pointer);
    mm.setMptrUrl(pointer);
    String anchor = myProzess.getProjekt().getMetsPointerPathAnchor();
    pointer = vp.replace(anchor);
    mm.setMptrAnchorUrl(pointer);
    mm.setGoobiID(String.valueOf(myProzess.getId()));
    mm.setIIIFUrl(vp.replace(myProzess.getProjekt().getMetsIIIFUrl()));
    mm.setSruUrl(vp.replace(myProzess.getProjekt().getMetsSruUrl()));
    // if (!ConfigMain.getParameter("ImagePrefix", "\\d{8}").equals("\\d{8}")) {
    List<String> images = new ArrayList<>();
    if (config.isExportValidateImages()) {
        try {
            images = new MetadatenImagesHelper(this.myPrefs, dd).getDataFiles(myProzess, imageFolderPath);
            int sizeOfPagination = dd.getPhysicalDocStruct().getAllChildren().size();
            if (images != null) {
                int sizeOfImages = images.size();
                if (sizeOfPagination == sizeOfImages) {
                    dd.overrideContentFiles(images);
                } else {
                    String[] param = { String.valueOf(sizeOfPagination), String.valueOf(sizeOfImages) };
                    Helper.setFehlerMeldung(Helper.getTranslation("imagePaginationError", param));
                    return null;
                }
            }
        } catch (IndexOutOfBoundsException e) {
            log.error(e);
            return null;
        } catch (InvalidImagesException e) {
            log.error(e);
            return null;
        }
    } else {
        // create pagination out of virtual file names
        dd.addAllContentFiles();
    }
    return mm;
}
Also used : ContentFile(ugh.dl.ContentFile) ProjectFileGroup(org.goobi.beans.ProjectFileGroup) SwapException(de.sub.goobi.helper.exceptions.SwapException) Element(org.w3c.dom.Element) Metadata(com.drew.metadata.Metadata) ArrayList(java.util.ArrayList) VariableReplacer(de.sub.goobi.helper.VariableReplacer) Prefs(ugh.dl.Prefs) DAOException(de.sub.goobi.helper.exceptions.DAOException) MetadatenImagesHelper(de.sub.goobi.metadaten.MetadatenImagesHelper) VirtualFileGroup(ugh.dl.VirtualFileGroup) DocStruct(ugh.dl.DocStruct) Path(java.nio.file.Path) MetadataType(ugh.dl.MetadataType) UGHException(ugh.exceptions.UGHException) IOException(java.io.IOException) DigitalDocument(ugh.dl.DigitalDocument) InvalidImagesException(de.sub.goobi.helper.exceptions.InvalidImagesException) MetadataTypeNotAllowedException(ugh.exceptions.MetadataTypeNotAllowedException) Md(ugh.dl.Md) PreferencesException(ugh.exceptions.PreferencesException) ExportFileformat(ugh.dl.ExportFileformat)

Example 5 with DigitalDocument

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

the class ProzesskopieForm method createNewFileformat.

/* =============================================================== */
private void createNewFileformat() throws TypeNotAllowedForParentException, TypeNotAllowedAsChildException {
    Prefs myPrefs = this.prozessKopie.getRegelsatz().getPreferences();
    try {
        DigitalDocument dd = new DigitalDocument();
        Fileformat ff = new XStream(myPrefs);
        ff.setDigitalDocument(dd);
        /* BoundBook hinzufügen */
        DocStructType dst = myPrefs.getDocStrctTypeByName("BoundBook");
        DocStruct dsBoundBook = dd.createDocStruct(dst);
        dd.setPhysicalDocStruct(dsBoundBook);
        ConfigOpacDoctype configOpacDoctype = co.getDoctypeByName(this.docType);
        /* Monographie */
        if (!configOpacDoctype.isPeriodical() && !configOpacDoctype.isMultiVolume()) {
            DocStructType dsty = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetType());
            DocStruct ds = dd.createDocStruct(dsty);
            dd.setLogicalDocStruct(ds);
            this.myRdf = ff;
        } else /* periodica */
        if (configOpacDoctype.isPeriodical() || configOpacDoctype.isMultiVolume()) {
            DocStructType anchor = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetType());
            DocStruct ds = dd.createDocStruct(anchor);
            dd.setLogicalDocStruct(ds);
            DocStructType dstyvolume = myPrefs.getDocStrctTypeByName(configOpacDoctype.getRulesetChildType());
            DocStruct dsvolume = dd.createDocStruct(dstyvolume);
            ds.addChild(dsvolume);
            this.myRdf = ff;
        }
    // } catch (TypeNotAllowedForParentException e) {
    // log.error(e);
    // } catch (TypeNotAllowedAsChildException e) {
    // log.error(e);
    } catch (PreferencesException e) {
        log.error(e);
    }
}
Also used : XStream(ugh.fileformats.mets.XStream) DocStructType(ugh.dl.DocStructType) Fileformat(ugh.dl.Fileformat) Prefs(ugh.dl.Prefs) DigitalDocument(ugh.dl.DigitalDocument) PreferencesException(ugh.exceptions.PreferencesException) DocStruct(ugh.dl.DocStruct) ConfigOpacDoctype(de.unigoettingen.sub.search.opac.ConfigOpacDoctype)

Aggregations

DigitalDocument (ugh.dl.DigitalDocument)12 DocStruct (ugh.dl.DocStruct)8 IOException (java.io.IOException)7 Fileformat (ugh.dl.Fileformat)7 PreferencesException (ugh.exceptions.PreferencesException)7 DAOException (de.sub.goobi.helper.exceptions.DAOException)6 Prefs (ugh.dl.Prefs)6 SwapException (de.sub.goobi.helper.exceptions.SwapException)4 UghHelperException (de.sub.goobi.helper.exceptions.UghHelperException)4 Metadata (ugh.dl.Metadata)4 ExportFileException (de.sub.goobi.helper.exceptions.ExportFileException)3 Date (java.util.Date)3 DocStructType (ugh.dl.DocStructType)3 MetadataType (ugh.dl.MetadataType)3 DocStructHasNoTypeException (ugh.exceptions.DocStructHasNoTypeException)3 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)3 UGHException (ugh.exceptions.UGHException)3 VariableReplacer (de.sub.goobi.helper.VariableReplacer)2 InvalidImagesException (de.sub.goobi.helper.exceptions.InvalidImagesException)2 FileNotFoundException (java.io.FileNotFoundException)2