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;
}
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;
}
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);
}
}
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;
}
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;
}
Aggregations