Search in sources :

Example 1 with MCRMetsFileUse

use of org.mycore.mets.model.simple.MCRMetsFileUse in project mycore by MyCoRe-Org.

the class MCRXMLSimpleModelConverter method addFilesFromGroup.

private static void addFilesFromGroup(Map<String, MCRMetsFile> idPageMap, FileGrp fileGroup) {
    String fileGroupUse = fileGroup.getUse();
    fileGroup.getFileList().forEach(file -> {
        MCRMetsFileUse use = Enum.valueOf(MCRMetsFileUse.class, fileGroupUse);
        idPageMap.put(file.getId(), new MCRMetsFile(file.getId(), file.getFLocat().getHref(), file.getMimeType(), use));
    });
}
Also used : MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse)

Example 2 with MCRMetsFileUse

use of org.mycore.mets.model.simple.MCRMetsFileUse in project mycore by MyCoRe-Org.

the class MCRMETSDefaultGenerator method createStructure.

private void createStructure(MCRPath dir, FileSec fileSec, PhysicalDiv physicalDiv, LogicalDiv logicalDiv, StructLink structLink, Map.Entry<MCRPath, BasicFileAttributes> file) throws IOException {
    String baseID = MCRMetsSave.getFileBase(file.getKey());
    final String physicalID = "phys_" + baseID;
    final String href;
    String path = file.getKey().getOwnerRelativePath().substring(1);
    try {
        href = MCRXMLFunctions.encodeURIPath(path, true);
    } catch (URISyntaxException uriSyntaxException) {
        LOGGER.error("invalid href {}", path, uriSyntaxException);
        return;
    }
    int beginIndex = href.lastIndexOf("/") == -1 ? 0 : href.lastIndexOf("/") + 1;
    int endIndex = (href.lastIndexOf(".") == -1 || href.lastIndexOf(".") <= beginIndex) ? href.length() : href.lastIndexOf(".");
    String fileName = href.substring(beginIndex, endIndex);
    LOGGER.debug("Created fileName: {}", fileName);
    if (!(hrefIdMap.containsKey(fileName) || hrefIdMap.containsValue(baseID) && isInExcludedRootFolder(dir))) {
        hrefIdMap.put(fileName, baseID);
    }
    // files
    MCRMetsFileUse fileUse = MCRMetsFileUse.get(href);
    String fileID = MCRMetsFileUse.getIdPrefix(href) + "_" + baseID;
    sortFileToGrp(fileSec, file, fileID, href, fileUse);
    // physical
    buildPhysDivs(dir, physicalDiv, fileID, physicalID, fileName);
    // struct link
    if (!isInExcludedRootFolder(dir)) {
        SmLink smLink = new SmLink(logicalDiv.getId(), physicalID);
        structLink.addSmLink(smLink);
    }
}
Also used : SmLink(org.mycore.mets.model.struct.SmLink) URISyntaxException(java.net.URISyntaxException) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse)

Example 3 with MCRMetsFileUse

use of org.mycore.mets.model.simple.MCRMetsFileUse 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 4 with MCRMetsFileUse

use of org.mycore.mets.model.simple.MCRMetsFileUse 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 5 with MCRMetsFileUse

use of org.mycore.mets.model.simple.MCRMetsFileUse in project mycore by MyCoRe-Org.

the class MCRSimpleModelXMLConverter method buildPhysicalPages.

private static void buildPhysicalPages(MCRMetsSimpleModel msm, Mets mets, Map<MCRMetsPage, String> pageIdMap, Map<String, String> idToNewIDMap) {
    List<MCRMetsPage> pageList = msm.getMetsPageList();
    PhysicalStructMap structMap = (PhysicalStructMap) mets.getStructMap(PhysicalStructMap.TYPE);
    structMap.setDivContainer(new PhysicalDiv(PHYSICAL_ID_PREFIX + UUID.randomUUID(), PhysicalDiv.TYPE_PHYS_SEQ));
    for (MCRMetsPage page : pageList) {
        String id = page.getId();
        PhysicalSubDiv physicalSubDiv = new PhysicalSubDiv(id, DEFAULT_PHYSICAL_TYPE);
        String orderLabel = page.getOrderLabel();
        if (orderLabel != null) {
            physicalSubDiv.setOrderLabel(orderLabel);
        }
        String contentIds = page.getContentIds();
        if (contentIds != null) {
            physicalSubDiv.setContentids(contentIds);
        }
        structMap.getDivContainer().add(physicalSubDiv);
        pageIdMap.put(page, id);
        page.getFileList().forEach((simpleFile) -> {
            String href = simpleFile.getHref();
            String fileID = simpleFile.getId();
            String mimeType = simpleFile.getMimeType();
            MCRMetsFileUse use = simpleFile.getUse();
            idToNewIDMap.put(simpleFile.getId(), fileID);
            File file = new File(fileID, mimeType);
            FLocat fLocat = new FLocat(LOCTYPE.URL, href);
            file.setFLocat(fLocat);
            FileGrp fileGrp = getFileGroup(mets, use);
            fileGrp.addFile(file);
            physicalSubDiv.add(new Fptr(fileID));
        });
    }
}
Also used : PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) FileGrp(org.mycore.mets.model.files.FileGrp) Fptr(org.mycore.mets.model.struct.Fptr) FLocat(org.mycore.mets.model.files.FLocat) File(org.mycore.mets.model.files.File) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv)

Aggregations

MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)5 FileGrp (org.mycore.mets.model.files.FileGrp)3 FileSec (org.mycore.mets.model.files.FileSec)2 PhysicalDiv (org.mycore.mets.model.struct.PhysicalDiv)2 PhysicalStructMap (org.mycore.mets.model.struct.PhysicalStructMap)2 URISyntaxException (java.net.URISyntaxException)1 MCRPath (org.mycore.datamodel.niofs.MCRPath)1 FLocat (org.mycore.mets.model.files.FLocat)1 File (org.mycore.mets.model.files.File)1 AmdSec (org.mycore.mets.model.sections.AmdSec)1 DmdSec (org.mycore.mets.model.sections.DmdSec)1 MCRMetsFile (org.mycore.mets.model.simple.MCRMetsFile)1 MCRMetsPage (org.mycore.mets.model.simple.MCRMetsPage)1 Fptr (org.mycore.mets.model.struct.Fptr)1 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)1 LogicalStructMap (org.mycore.mets.model.struct.LogicalStructMap)1 PhysicalSubDiv (org.mycore.mets.model.struct.PhysicalSubDiv)1 SmLink (org.mycore.mets.model.struct.SmLink)1 StructLink (org.mycore.mets.model.struct.StructLink)1