Search in sources :

Example 6 with FileGrp

use of org.mycore.mets.model.files.FileGrp in project mycore by MyCoRe-Org.

the class MCRMETSDefaultGenerator method createMets.

private Mets createMets() throws IOException {
    Mets mets = new Mets();
    String owner = getOwner();
    // add dmdsec
    DmdSec dmdSec = new DmdSec("dmd_" + owner);
    // add amdsec
    AmdSec amdSec = new AmdSec("amd_" + owner);
    // file sec
    FileSec fileSec = new FileSec();
    for (MCRMetsFileUse fileUse : MCRMetsFileUse.values()) {
        FileGrp fileGrp = new FileGrp(fileUse.toString());
        fileSec.addFileGrp(fileGrp);
    }
    // physical structure
    PhysicalStructMap physicalStructMap = new PhysicalStructMap();
    PhysicalDiv physicalDiv = new PhysicalDiv("phys_" + owner, "physSequence");
    physicalStructMap.setDivContainer(physicalDiv);
    // logical structure
    MCRILogicalStructMapTypeProvider typeProvider = getTypeProvider();
    LogicalStructMap logicalStructMap = new LogicalStructMap();
    LogicalDiv logicalDiv = new LogicalDiv("log_" + owner, typeProvider.getType(MCRObjectID.getInstance(owner)), owner, amdSec.getId(), dmdSec.getId());
    logicalDiv.setDmdId(dmdSec.getId());
    logicalStructMap.setDivContainer(logicalDiv);
    // struct Link
    StructLink structLink = new StructLink();
    // create internal structure
    structureMets(getDerivatePath(), getIgnorePaths(), fileSec, physicalDiv, logicalDiv, structLink, 0);
    hrefIdMap.clear();
    // add to mets
    mets.addDmdSec(dmdSec);
    mets.addAmdSec(amdSec);
    mets.setFileSec(fileSec);
    mets.addStructMap(physicalStructMap);
    mets.addStructMap(logicalStructMap);
    mets.setStructLink(structLink);
    return mets;
}
Also used : AmdSec(org.mycore.mets.model.sections.AmdSec) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) FileGrp(org.mycore.mets.model.files.FileGrp) StructLink(org.mycore.mets.model.struct.StructLink) DmdSec(org.mycore.mets.model.sections.DmdSec) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) FileSec(org.mycore.mets.model.files.FileSec)

Example 7 with FileGrp

use of org.mycore.mets.model.files.FileGrp in project mycore by MyCoRe-Org.

the class MCRMETSDefaultGenerator method sortFileToGrp.

private void sortFileToGrp(FileSec fileSec, Map.Entry<MCRPath, BasicFileAttributes> file, String fileID, final String href, MCRMetsFileUse fileUse) throws IOException {
    // file
    File metsFile = new File(fileID, MCRContentTypes.probeContentType(file.getKey()));
    FLocat fLocat = new FLocat(LOCTYPE.URL, href);
    metsFile.setFLocat(fLocat);
    for (FileGrp fileGrp : fileSec.getFileGroups()) {
        if (fileGrp.getUse().equalsIgnoreCase(fileUse.toString())) {
            fileGrp.addFile(metsFile);
        }
    }
}
Also used : FileGrp(org.mycore.mets.model.files.FileGrp) FLocat(org.mycore.mets.model.files.FLocat) File(org.mycore.mets.model.files.File)

Example 8 with FileGrp

use of org.mycore.mets.model.files.FileGrp in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method getFileId.

/**
 * Runs through all USE="MASTER" files and tries to find the corresponding
 * mets:file @ID.
 *
 * @param uriEncodedLinkedFile the file to find
 * @return the fileSec @ID
 */
private Optional<String> getFileId(String uriEncodedLinkedFile) {
    FileGrp masterGroup = this.fileSection.getFileGroup(FileGrp.USE_MASTER);
    return masterGroup.getFileList().stream().filter(file -> {
        String href = file.getFLocat().getHref();
        boolean equals = href.equals(uriEncodedLinkedFile);
        boolean equalsWithoutSlash = uriEncodedLinkedFile.startsWith("/") && href.equals(uriEncodedLinkedFile.substring(1));
        return equals || equalsWithoutSlash;
    }).map(File::getId).findFirst();
}
Also used : FileGrp(org.mycore.mets.model.files.FileGrp)

Example 9 with FileGrp

use of org.mycore.mets.model.files.FileGrp in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method createFileSection.

/**
 * Creates the file section.
 *
 * @return generated file secion.
 */
protected FileSec createFileSection() throws IOException {
    FileSec fileSec = new FileSec();
    List<MCRPath> filePaths = MCRMetsSave.listFiles(getDerivatePath(), getIgnorePaths());
    List<FileGrp> fileGrps = MCRMetsSave.buildFileGroups(filePaths);
    fileGrps.forEach(fileSec::addFileGrp);
    for (MCRPath file : filePaths) {
        String contentType = MCRContentTypes.probeContentType(file);
        FileRef ref = new FileRef(file, contentType);
        this.files.add(ref);
    }
    for (FileRef ref : this.files) {
        MCRMetsFileUse use = MCRMetsFileUse.get(ref.path);
        FileGrp fileGrp = fileGrps.stream().filter(grp -> grp.getUse().equals(use.toString())).findFirst().orElse(null);
        if (fileGrp == null) {
            LOGGER.warn("Unable to add file '" + ref.toId() + "' because cannot find corresponding group " + " with @USE='" + use.toString() + "'. Ignore file and continue.");
            continue;
        }
        addFile(ref.toId(), fileGrp, ref.getPath(), ref.getContentType());
    }
    return fileSec;
}
Also used : FileSec(org.mycore.mets.model.files.FileSec) FileGrp(org.mycore.mets.model.files.FileGrp) MCRPath(org.mycore.datamodel.niofs.MCRPath) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse)

Example 10 with FileGrp

use of org.mycore.mets.model.files.FileGrp in project mycore by MyCoRe-Org.

the class MCRMetsSave method getFileGroup.

private static Element getFileGroup(Document mets, String fileGrpUSE) {
    // alter the mets document
    XPathExpression<Element> xpath;
    String fileGroupXPathString = String.format(Locale.ROOT, "mets:mets/mets:fileSec/mets:fileGrp[@USE='%s']", fileGrpUSE);
    xpath = XPathFactory.instance().compile(fileGroupXPathString, Filters.element(), null, MCRConstants.METS_NAMESPACE);
    Element element = xpath.evaluateFirst(mets);
    if (element == null) {
        // section does not exist
        Element fileGroupElement = new FileGrp(fileGrpUSE).asElement();
        String fileSectionPath = "mets:mets/mets:fileSec";
        xpath = XPathFactory.instance().compile(fileSectionPath, Filters.element(), null, MCRConstants.METS_NAMESPACE);
        Element fileSectionElement = xpath.evaluateFirst(mets);
        if (fileSectionElement == null) {
            throw new MCRPersistenceException("There is no fileSection in mets.xml!");
        }
        fileSectionElement.addContent(fileGroupElement);
        element = fileGroupElement;
    }
    return element;
}
Also used : Element(org.jdom2.Element) FileGrp(org.mycore.mets.model.files.FileGrp) MCRPersistenceException(org.mycore.common.MCRPersistenceException)

Aggregations

FileGrp (org.mycore.mets.model.files.FileGrp)13 File (org.mycore.mets.model.files.File)7 PhysicalDiv (org.mycore.mets.model.struct.PhysicalDiv)6 PhysicalStructMap (org.mycore.mets.model.struct.PhysicalStructMap)6 PhysicalSubDiv (org.mycore.mets.model.struct.PhysicalSubDiv)6 MCRPersistenceException (org.mycore.common.MCRPersistenceException)5 FLocat (org.mycore.mets.model.files.FLocat)5 Fptr (org.mycore.mets.model.struct.Fptr)5 IOException (java.io.IOException)4 URISyntaxException (java.net.URISyntaxException)4 ArrayList (java.util.ArrayList)4 MCRPath (org.mycore.datamodel.niofs.MCRPath)4 MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)4 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)4 LogicalStructMap (org.mycore.mets.model.struct.LogicalStructMap)4 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 HashMap (java.util.HashMap)3 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2