Search in sources :

Example 1 with FileSec

use of org.mycore.mets.model.files.FileSec 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 2 with FileSec

use of org.mycore.mets.model.files.FileSec 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)

Aggregations

FileGrp (org.mycore.mets.model.files.FileGrp)2 FileSec (org.mycore.mets.model.files.FileSec)2 MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)2 MCRPath (org.mycore.datamodel.niofs.MCRPath)1 AmdSec (org.mycore.mets.model.sections.AmdSec)1 DmdSec (org.mycore.mets.model.sections.DmdSec)1 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)1 LogicalStructMap (org.mycore.mets.model.struct.LogicalStructMap)1 PhysicalDiv (org.mycore.mets.model.struct.PhysicalDiv)1 PhysicalStructMap (org.mycore.mets.model.struct.PhysicalStructMap)1 StructLink (org.mycore.mets.model.struct.StructLink)1