Search in sources :

Example 1 with ProjectFileGroup

use of org.goobi.beans.ProjectFileGroup in project goobi-workflow by intranda.

the class ProjectBean method filegroupAdd.

public String filegroupAdd() {
    this.myFilegroup = new ProjectFileGroup();
    this.myFilegroup.setProject(this.myProjekt);
    this.newFileGroups.add(this.myFilegroup.getId());
    return "";
}
Also used : ProjectFileGroup(org.goobi.beans.ProjectFileGroup)

Example 2 with ProjectFileGroup

use of org.goobi.beans.ProjectFileGroup in project goobi-workflow by intranda.

the class ProjectMysqlHelper method getFilegroupsForProjectId.

public static List<ProjectFileGroup> getFilegroupsForProjectId(int projectId) throws SQLException {
    Connection connection = null;
    StringBuilder sql = new StringBuilder();
    sql.append("SELECT * FROM projectfilegroups WHERE ProjekteID = ? ");
    try {
        connection = MySQLHelper.getInstance().getConnection();
        Object[] param = { projectId };
        if (log.isTraceEnabled()) {
            log.trace(sql.toString() + ", " + Arrays.toString(param));
        }
        List<ProjectFileGroup> answer = new QueryRunner().query(connection, sql.toString(), resultSetToProjectFilegroupListHandler, param);
        return answer;
    } finally {
        if (connection != null) {
            MySQLHelper.closeConnection(connection);
        }
    }
}
Also used : ProjectFileGroup(org.goobi.beans.ProjectFileGroup) Connection(java.sql.Connection) QueryRunner(org.apache.commons.dbutils.QueryRunner)

Example 3 with ProjectFileGroup

use of org.goobi.beans.ProjectFileGroup 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 4 with ProjectFileGroup

use of org.goobi.beans.ProjectFileGroup in project goobi-workflow by intranda.

the class MockProcess method setUpProject.

private static void setUpProject(Process testProcess) throws IOException {
    Project project = new Project();
    project.setTitel("project");
    project.setId(666);
    testProcess.setProjekt(project);
    project.setFileFormatInternal("Mets");
    project.setFileFormatDmsExport("Mets");
    Path exportFolder = Files.createTempDirectory("hotfolder");
    Files.createDirectories(exportFolder);
    project.setDmsImportImagesPath(exportFolder.toString() + FileSystems.getDefault().getSeparator());
    project.setDmsImportErrorPath(exportFolder.toString() + FileSystems.getDefault().getSeparator());
    project.setDmsImportSuccessPath(exportFolder.toString() + FileSystems.getDefault().getSeparator());
    project.setDmsImportRootPath(exportFolder.toString() + FileSystems.getDefault().getSeparator());
    project.setUseDmsImport(true);
    project.setDmsImportCreateProcessFolder(true);
    ProjectFileGroup presentation = new ProjectFileGroup();
    presentation.setMimetype("image/jp2");
    presentation.setName("PRESENTATION");
    presentation.setPath("/opt/digiverso/viewer/media/1/");
    presentation.setSuffix("jp2");
    presentation.setFolder("");
    presentation.setId(1);
    presentation.setProject(project);
    ProjectFileGroup alto = new ProjectFileGroup();
    alto.setFolder("getOcrAltoDirectory");
    alto.setMimetype("text/xml");
    alto.setName("ALTO");
    alto.setPath("/opt/digiverso/viewer/alto/1/");
    alto.setSuffix("xml");
    alto.setProject(project);
    List<ProjectFileGroup> list = new ArrayList<>();
    list.add(presentation);
    list.add(alto);
    project.setFilegroups(list);
}
Also used : Path(java.nio.file.Path) Project(org.goobi.beans.Project) ProjectFileGroup(org.goobi.beans.ProjectFileGroup) ArrayList(java.util.ArrayList)

Example 5 with ProjectFileGroup

use of org.goobi.beans.ProjectFileGroup in project goobi-workflow by intranda.

the class ProjectBean method deleteFileGroups.

/**
 * this method deletes filegroups by their id's in the list
 *
 * @param List <Integer> fileGroups
 */
private void deleteFileGroups(List<Integer> fileGroups) {
    for (Integer id : fileGroups) {
        for (ProjectFileGroup f : this.myProjekt.getFilegroups()) {
            if (f.getId() == id) {
                this.myProjekt.getFilegroups().remove(f);
                ProjectManager.deleteProjectFileGroup(f);
                break;
            }
        }
    }
}
Also used : ProjectFileGroup(org.goobi.beans.ProjectFileGroup)

Aggregations

ProjectFileGroup (org.goobi.beans.ProjectFileGroup)8 Path (java.nio.file.Path)3 DAOException (de.sub.goobi.helper.exceptions.DAOException)2 SwapException (de.sub.goobi.helper.exceptions.SwapException)2 IOException (java.io.IOException)2 Connection (java.sql.Connection)2 ArrayList (java.util.ArrayList)2 QueryRunner (org.apache.commons.dbutils.QueryRunner)2 MetadataTypeNotAllowedException (ugh.exceptions.MetadataTypeNotAllowedException)2 PreferencesException (ugh.exceptions.PreferencesException)2 Metadata (com.drew.metadata.Metadata)1 VariableReplacer (de.sub.goobi.helper.VariableReplacer)1 ExportFileException (de.sub.goobi.helper.exceptions.ExportFileException)1 InvalidImagesException (de.sub.goobi.helper.exceptions.InvalidImagesException)1 UghHelperException (de.sub.goobi.helper.exceptions.UghHelperException)1 MetadatenImagesHelper (de.sub.goobi.metadaten.MetadatenImagesHelper)1 AccessDeniedException (java.nio.file.AccessDeniedException)1 Institution (org.goobi.beans.Institution)1 InstitutionConfigurationObject (org.goobi.beans.InstitutionConfigurationObject)1 Project (org.goobi.beans.Project)1