use of org.mycore.mets.model.simple.MCRMetsPage 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.MCRMetsPage 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.MCRMetsPage in project mycore by MyCoRe-Org.
the class MCRMetsTestUtil method buildSimpleModelLinkList.
private static void buildSimpleModelLinkList(MCRMetsSimpleModel metsSimpleModel) {
List<MCRMetsLink> linkList = metsSimpleModel.sectionPageLinkList;
MCRMetsSection rootSection = metsSimpleModel.getRootSection();
List<MCRMetsPage> pageList = metsSimpleModel.getMetsPageList();
linkList.add(new MCRMetsLink(rootSection, pageList.get(0)));
linkList.add(new MCRMetsLink(rootSection.getMetsSectionList().get(0), pageList.get(1)));
linkList.add(new MCRMetsLink(rootSection.getMetsSectionList().get(1), pageList.get(2)));
}
use of org.mycore.mets.model.simple.MCRMetsPage 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);
}
use of org.mycore.mets.model.simple.MCRMetsPage 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