use of org.mycore.mets.model.simple.MCRMetsFile in project mycore by MyCoRe-Org.
the class MCRXMLSimpleModelConverterTest method testFromXMLMetsFiles.
@org.junit.Test
public void testFromXMLMetsFiles() throws Exception {
Iterator<MCRMetsFile> hrefIterator = metsSimpleModel.getMetsPageList().stream().map((p) -> {
Optional<MCRMetsFile> first = p.getFileList().stream().findFirst();
return first.get();
}).iterator();
int i = 0;
while (hrefIterator.hasNext()) {
i++;
MCRMetsFile mcrMetsFile = hrefIterator.next();
String expectedFileName = String.format(FILE_NAME_MATCH_PATTERN, i);
String message = String.format("href %s should match %s", mcrMetsFile.getHref(), expectedFileName);
Assert.assertEquals(message, mcrMetsFile.getHref(), expectedFileName);
message = String.format("MimeType %s should match %s", mcrMetsFile.getMimeType(), ALL_FILE_MIMETYPE);
Assert.assertEquals(message, mcrMetsFile.getMimeType(), ALL_FILE_MIMETYPE);
message = String.format("File-Use %s should match %s", mcrMetsFile.getUse(), MASTER);
Assert.assertEquals(message, mcrMetsFile.getUse(), MASTER);
}
}
use of org.mycore.mets.model.simple.MCRMetsFile in project mycore by MyCoRe-Org.
the class MCRJSONSimpleModelConverter method toSimpleModel.
public static MCRMetsSimpleModel toSimpleModel(String model) {
GsonBuilder gsonBuilder = new GsonBuilder();
gsonBuilder.registerTypeAdapter(MCRMetsLink.class, new MCRMetsLinkTypeAdapter());
gsonBuilder.registerTypeAdapter(MCRMetsAltoLink.class, new MCRAltoLinkTypeAdapter());
gsonBuilder.setPrettyPrinting();
MCRMetsSimpleModel metsSimpleModel = gsonBuilder.create().fromJson(model, MCRMetsSimpleModel.class);
Hashtable<String, MCRMetsPage> idPageMap = new Hashtable<>();
metsSimpleModel.getMetsPageList().stream().forEach(page -> idPageMap.put(page.getId(), page));
final Map<String, MCRMetsFile> idMCRMetsFileMap = extractIdFileMap(metsSimpleModel.getMetsPageList());
Hashtable<String, MCRMetsSection> idSectionMap = new Hashtable<>();
processSections(metsSimpleModel.getRootSection(), idSectionMap, idMCRMetsFileMap);
List<MCRMetsLink> sectionPageLinkList = metsSimpleModel.getSectionPageLinkList();
List<MCRMetsLink> metsLinks = sectionPageLinkList.stream().map((link) -> {
if (link instanceof MCRMetsLinkTypeAdapter.MCRMetsLinkPlaceholder) {
MCRMetsLinkTypeAdapter.MCRMetsLinkPlaceholder placeholder = (MCRMetsLinkTypeAdapter.MCRMetsLinkPlaceholder) link;
MCRMetsSection metsSection = idSectionMap.get(placeholder.getFromString());
MCRMetsPage metsPage = idPageMap.get(placeholder.getToString());
return new MCRMetsLink(metsSection, metsPage);
} else {
return link;
}
}).collect(toList());
sectionPageLinkList.clear();
sectionPageLinkList.addAll(metsLinks);
return metsSimpleModel;
}
use of org.mycore.mets.model.simple.MCRMetsFile 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.MCRMetsFile in project mycore by MyCoRe-Org.
the class MCRXMLSimpleModelConverter method fromXML.
/**
* Converts a Document to MetsSimpleModel
*
* @param metsDocument the Document which should be converted
* @return the converted MetsSimpleModel
* @throws Exception if new Mets(metsDocument) throws exception
*/
public static MCRMetsSimpleModel fromXML(Document metsDocument) throws Exception {
Mets mets = new Mets(metsDocument);
MCRMetsSimpleModel msm = new MCRMetsSimpleModel();
Map<String, MCRMetsPage> idPageMap = new Hashtable<>();
Map<String, MCRMetsFile> idFileMap = buildidFileMap(mets);
List<MCRMetsPage> metsPageList = buildPageList(mets, idPageMap, idFileMap);
msm.getMetsPageList().addAll(metsPageList);
Map<String, MCRMetsSection> idSectionMap = new Hashtable<>();
MCRMetsSection rootMetsSection = buidRootSection(mets, idSectionMap, idFileMap);
msm.setRootSection(rootMetsSection);
linkPages(mets, idSectionMap, idPageMap, msm);
return msm;
}
use of org.mycore.mets.model.simple.MCRMetsFile in project mycore by MyCoRe-Org.
the class MCRMetsTestUtil method buildSimpleModelPages.
private static void buildSimpleModelPages(MCRMetsSimpleModel metsSimpleModel) {
MCRMetsPage metsPage1 = new MCRMetsPage("1_P", "1", "URN:special-urn1");
metsPage1.getFileList().add(new MCRMetsFile("1_M", "1.jpg", "image/jpeg", MCRMetsFileUse.MASTER));
metsPage1.getFileList().add(new MCRMetsFile("1_A", "1.xml", "text/xml", MCRMetsFileUse.ALTO));
MCRMetsPage metsPage2 = new MCRMetsPage("2_P", "2", "URN:special-urn2");
metsPage2.getFileList().add(new MCRMetsFile("2_M", "2.jpg", "image/jpeg", MCRMetsFileUse.MASTER));
metsPage2.getFileList().add(new MCRMetsFile("2_A", "2.xml", "text/xml", MCRMetsFileUse.ALTO));
MCRMetsPage metsPage3 = new MCRMetsPage("3_P", "3", "URN:special-urn3");
metsPage3.getFileList().add(new MCRMetsFile("3_M", "3.jpg", "image/jpeg", MCRMetsFileUse.MASTER));
metsPage3.getFileList().add(new MCRMetsFile("3_A", "3.xml", "text/xml", MCRMetsFileUse.ALTO));
metsSimpleModel.getMetsPageList().add(metsPage1);
metsSimpleModel.getMetsPageList().add(metsPage2);
metsSimpleModel.getMetsPageList().add(metsPage3);
}
Aggregations