Search in sources :

Example 1 with PhysicalSubDiv

use of org.mycore.mets.model.struct.PhysicalSubDiv in project mycore by MyCoRe-Org.

the class MCRMetsMods2IIIFConverter method getIIIFIdentifier.

protected String getIIIFIdentifier(PhysicalSubDiv subDiv) {
    File file = subDiv.getChildren().stream().map(fptr -> imageGrp.getFileById(fptr.getFileId())).filter(Objects::nonNull).findAny().get();
    String cleanHref = file.getFLocat().getHref();
    cleanHref = cleanHref.substring(cleanHref.indexOf(this.identifier), cleanHref.length());
    return cleanHref;
}
Also used : PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFImageUtil(org.mycore.iiif.image.MCRIIIFImageUtil) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRConstants(org.mycore.common.MCRConstants) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) HashMap(java.util.HashMap) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) FileGrp(org.mycore.mets.model.files.FileGrp) Map(java.util.Map) MCRDCMIType(org.mycore.iiif.presentation.model.attributes.MCRDCMIType) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) File(org.mycore.mets.model.files.File) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) MCRIIIFViewingHint(org.mycore.iiif.presentation.model.attributes.MCRIIIFViewingHint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) Mets(org.mycore.mets.model.Mets) Collectors(java.util.stream.Collectors) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MDTYPE(org.mycore.mets.model.struct.MDTYPE) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) DmdSec(org.mycore.mets.model.sections.DmdSec) MdWrap(org.mycore.mets.model.struct.MdWrap) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) Objects(java.util.Objects) File(org.mycore.mets.model.files.File)

Example 2 with PhysicalSubDiv

use of org.mycore.mets.model.struct.PhysicalSubDiv in project mycore by MyCoRe-Org.

the class MCRMetsMods2IIIFConverter method convert.

public MCRIIIFManifest convert() {
    MCRIIIFManifest manifest = new MCRIIIFManifest();
    // root chapter ^= manifest metadata
    LogicalStructMap logicalStructMap = (LogicalStructMap) mets.getStructMap("LOGICAL");
    LogicalDiv divContainer = logicalStructMap.getDivContainer();
    List<MCRIIIFMetadata> metadata = extractMedataFromLogicalDiv(mets, divContainer);
    manifest.metadata = metadata;
    manifest.setId(this.identifier);
    PhysicalStructMap physicalStructMap = (PhysicalStructMap) mets.getStructMap("PHYSICAL");
    PhysicalDiv physicalDivContainer = physicalStructMap.getDivContainer();
    String id = physicalDivContainer.getId();
    MCRIIIFSequence sequence = new MCRIIIFSequence(id);
    List<PhysicalSubDiv> children = physicalDivContainer.getChildren();
    MCRIIIFImageImpl imageImpl = MCRIIIFImageImpl.getInstance(getImageImplName());
    MCRIIIFImageProfile profile = imageImpl.getProfile();
    profile.setId(MCRIIIFImageUtil.getProfileLink(imageImpl));
    sequence.canvases = children.stream().map(physicalSubDiv -> {
        String order = physicalSubDiv.asElement().getAttributeValue("ORDER");
        String orderLabel = physicalSubDiv.getOrderLabel();
        String contentids = physicalSubDiv.getContentids();
        String label = Stream.of(order, orderLabel, contentids).filter(o -> o != null && !o.isEmpty()).collect(Collectors.joining(" - "));
        String identifier = this.physicalIdentifierMap.get(physicalSubDiv);
        try {
            MCRIIIFImageInformation information = imageImpl.getInformation(identifier);
            MCRIIIFCanvas canvas = new MCRIIIFCanvas(identifier, label, information.width, information.height);
            MCRIIIFAnnotation annotation = new MCRIIIFAnnotation(identifier, canvas);
            canvas.images.add(annotation);
            MCRIIIFResource resource = new MCRIIIFResource(information.getId(), MCRDCMIType.Image);
            resource.setWidth(information.width);
            resource.setHeight(information.height);
            MCRIIIFService service = new MCRIIIFService(information.getId(), profile.getContext());
            service.profile = MCRIIIFImageProfile.IIIF_PROFILE_2_0;
            resource.setService(service);
            annotation.setResource(resource);
            return canvas;
        } catch (MCRIIIFImageNotFoundException | MCRIIIFImageProvidingException e) {
            throw new MCRException("Error while providing ImageInfo for " + identifier, e);
        } catch (MCRAccessException e) {
            LOGGER.warn("User has no access to {}", identifier);
            return null;
        }
    }).filter(Objects::nonNull).collect(Collectors.toList());
    manifest.sequences.add(sequence);
    List<MCRIIIFRange> complete = new ArrayList<>();
    processDivContainer(complete, divContainer);
    manifest.structures.addAll(complete);
    manifest.setLabel(metadata.stream().filter(m -> m.getLabel().equals("title")).findFirst().get().getStringValue().get());
    return manifest;
}
Also used : PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFImageUtil(org.mycore.iiif.image.MCRIIIFImageUtil) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRConstants(org.mycore.common.MCRConstants) MCRIIIFImageProvidingException(org.mycore.iiif.image.impl.MCRIIIFImageProvidingException) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) HashMap(java.util.HashMap) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) MCRException(org.mycore.common.MCRException) ArrayList(java.util.ArrayList) Document(org.jdom2.Document) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) FileGrp(org.mycore.mets.model.files.FileGrp) Map(java.util.Map) MCRDCMIType(org.mycore.iiif.presentation.model.attributes.MCRDCMIType) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) File(org.mycore.mets.model.files.File) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) MCRIIIFViewingHint(org.mycore.iiif.presentation.model.attributes.MCRIIIFViewingHint) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) Mets(org.mycore.mets.model.Mets) Collectors(java.util.stream.Collectors) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MDTYPE(org.mycore.mets.model.struct.MDTYPE) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) Objects(java.util.Objects) List(java.util.List) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) MCRIIIFImageNotFoundException(org.mycore.iiif.image.impl.MCRIIIFImageNotFoundException) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) DmdSec(org.mycore.mets.model.sections.DmdSec) MdWrap(org.mycore.mets.model.struct.MdWrap) Collections(java.util.Collections) LogManager(org.apache.logging.log4j.LogManager) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) ArrayList(java.util.ArrayList) MCRIIIFSequence(org.mycore.iiif.presentation.model.basic.MCRIIIFSequence) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) MCRIIIFRange(org.mycore.iiif.presentation.model.basic.MCRIIIFRange) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRIIIFCanvas(org.mycore.iiif.presentation.model.basic.MCRIIIFCanvas) MCRIIIFMetadata(org.mycore.iiif.presentation.model.attributes.MCRIIIFMetadata) MCRIIIFService(org.mycore.iiif.presentation.model.attributes.MCRIIIFService) MCRIIIFImageImpl(org.mycore.iiif.image.impl.MCRIIIFImageImpl) MCRException(org.mycore.common.MCRException) MCRIIIFManifest(org.mycore.iiif.presentation.model.basic.MCRIIIFManifest) MCRIIIFImageInformation(org.mycore.iiif.image.model.MCRIIIFImageInformation) MCRIIIFResource(org.mycore.iiif.presentation.model.attributes.MCRIIIFResource) MCRAccessException(org.mycore.access.MCRAccessException) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRIIIFImageProfile(org.mycore.iiif.image.model.MCRIIIFImageProfile) MCRIIIFAnnotation(org.mycore.iiif.presentation.model.additional.MCRIIIFAnnotation) Objects(java.util.Objects)

Example 3 with PhysicalSubDiv

use of org.mycore.mets.model.struct.PhysicalSubDiv in project mycore by MyCoRe-Org.

the class MCRMETSDefaultGenerator method buildPhysDivs.

private void buildPhysDivs(MCRPath dir, PhysicalDiv physicalDiv, String fileID, final String physicalID, String fileName) {
    if (!fileName.isEmpty() && hrefIdMap.containsKey(fileName) && isInExcludedRootFolder(dir)) {
        for (PhysicalSubDiv physSubDiv : physicalDiv.getChildren()) {
            if (physSubDiv.getId().contains(hrefIdMap.get(fileName))) {
                physSubDiv.add(new Fptr(fileID));
            }
        }
    } else {
        PhysicalSubDiv pyhsicalPage = new PhysicalSubDiv(physicalID, "page");
        Fptr fptr = new Fptr(fileID);
        pyhsicalPage.add(fptr);
        physicalDiv.add(pyhsicalPage);
    }
}
Also used : Fptr(org.mycore.mets.model.struct.Fptr) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv)

Example 4 with PhysicalSubDiv

use of org.mycore.mets.model.struct.PhysicalSubDiv in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method createStructLink.

/**
 * Creates the mets:structLink part of the mets.xml
 *
 * @return a newly generated StructLink.
 */
protected StructLink createStructLink() {
    StructLink structLink = new StructLink();
    String currentLogicalDivId = logicalStructMap.getDivContainer().getId();
    PhysicalDiv physicalDiv = this.physicalStructMap.getDivContainer();
    List<PhysicalSubDiv> subDivList = physicalDiv.getChildren();
    for (PhysicalSubDiv physLink : subDivList) {
        if (structLinkMap.containsKey(physLink.getId())) {
            ArrayList<String> logicalIdList = new ArrayList<>(structLinkMap.get(physLink.getId()));
            Collections.sort(logicalIdList);
            for (String logicalId : logicalIdList) {
                currentLogicalDivId = logicalId;
                structLink.addSmLink(new SmLink(currentLogicalDivId, physLink.getId()));
            }
        } else {
            structLink.addSmLink(new SmLink(currentLogicalDivId, physLink.getId()));
        }
    }
    return structLink;
}
Also used : SmLink(org.mycore.mets.model.struct.SmLink) StructLink(org.mycore.mets.model.struct.StructLink) ArrayList(java.util.ArrayList) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv)

Example 5 with PhysicalSubDiv

use of org.mycore.mets.model.struct.PhysicalSubDiv in project mycore by MyCoRe-Org.

the class MCRMETSHierarchyGenerator method createPhysicalStruct.

/**
 * This method creates the physical structure map.
 *
 * @return generated pyhiscal struct map secion.
 */
protected PhysicalStructMap createPhysicalStruct() {
    PhysicalStructMap pstr = new PhysicalStructMap();
    PhysicalDiv physicalDiv = new PhysicalDiv("phys_" + this.mcrDer.getId(), PhysicalDiv.TYPE_PHYS_SEQ);
    pstr.setDivContainer(physicalDiv);
    // run through file references
    for (FileRef ref : this.files) {
        String physId = ref.toPhysId();
        PhysicalSubDiv page = physicalDiv.get(physId);
        if (page == null) {
            page = new PhysicalSubDiv(physId, PhysicalSubDiv.TYPE_PAGE);
            getOrderLabel(ref.toId()).ifPresent(page::setOrderLabel);
            physicalDiv.add(page);
        }
        page.add(new Fptr(ref.toId()));
    }
    return pstr;
}
Also used : PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) Fptr(org.mycore.mets.model.struct.Fptr) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv)

Aggregations

PhysicalSubDiv (org.mycore.mets.model.struct.PhysicalSubDiv)13 FileGrp (org.mycore.mets.model.files.FileGrp)9 PhysicalDiv (org.mycore.mets.model.struct.PhysicalDiv)9 PhysicalStructMap (org.mycore.mets.model.struct.PhysicalStructMap)9 ArrayList (java.util.ArrayList)8 File (org.mycore.mets.model.files.File)8 Mets (org.mycore.mets.model.Mets)7 Fptr (org.mycore.mets.model.struct.Fptr)7 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)6 LogicalStructMap (org.mycore.mets.model.struct.LogicalStructMap)6 HashMap (java.util.HashMap)5 List (java.util.List)5 Map (java.util.Map)5 Document (org.jdom2.Document)5 Collections (java.util.Collections)4 Objects (java.util.Objects)4 Collectors (java.util.stream.Collectors)4 IOException (java.io.IOException)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)3 URISyntaxException (java.net.URISyntaxException)3