Search in sources :

Example 1 with DocStructType

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

use of ugh.dl.DocStructType 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 3 with DocStructType

use of ugh.dl.DocStructType 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 4 with DocStructType

use of ugh.dl.DocStructType 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 5 with DocStructType

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

DocStructType (ugh.dl.DocStructType)12 DocStruct (ugh.dl.DocStruct)10 Metadata (ugh.dl.Metadata)9 MetadataType (ugh.dl.MetadataType)6 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)5 ArrayList (java.util.ArrayList)4 Corporate (ugh.dl.Corporate)4 DigitalDocument (ugh.dl.DigitalDocument)4 DocStructHasNoTypeException (ugh.exceptions.DocStructHasNoTypeException)4 TypeNotAllowedForParentException (ugh.exceptions.TypeNotAllowedForParentException)4 DAOException (de.sub.goobi.helper.exceptions.DAOException)3 IOException (java.io.IOException)3 Person (ugh.dl.Person)3 Prefs (ugh.dl.Prefs)3 Reference (ugh.dl.Reference)3 PreferencesException (ugh.exceptions.PreferencesException)3 UghHelper (de.sub.goobi.helper.UghHelper)2 InvalidImagesException (de.sub.goobi.helper.exceptions.InvalidImagesException)2 SwapException (de.sub.goobi.helper.exceptions.SwapException)2 UghHelperException (de.sub.goobi.helper.exceptions.UghHelperException)2