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