use of org.mycore.mets.model.simple.MCRMetsSection 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.MCRMetsSection in project mycore by MyCoRe-Org.
the class MCRXMLSimpleModelConverterTest method testFromXMLMetsSection.
@org.junit.Test
public void testFromXMLMetsSection() throws Exception {
MCRMetsSection rootSection = metsSimpleModel.getRootSection();
Assert.assertEquals("The rootSection label should be " + ROOT_SECTION_LABEL, rootSection.getLabel(), ROOT_SECTION_LABEL);
Assert.assertEquals("log_ArchNachl_derivate_00000011", rootSection.getId());
List<MCRMetsSection> metsSectionList = rootSection.getMetsSectionList();
String message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "first", ROOT_SECTION_FIRST_CHILD_LABEL, "label");
Assert.assertEquals(message, metsSectionList.get(0).getLabel(), ROOT_SECTION_FIRST_CHILD_LABEL);
message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "first", COVER_FRONT_TYPE, "type");
Assert.assertEquals(message, metsSectionList.get(0).getType(), COVER_FRONT_TYPE);
message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "second", ROOT_SECTION_FIRST_CHILD_LABEL, "label");
Assert.assertEquals(message, metsSectionList.get(1).getLabel(), ROOT_SECTION_SECOND_CHILD_LABEL);
message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "second", CONTAINED_WORK_TYPE, "type");
Assert.assertEquals(message, metsSectionList.get(1).getType(), CONTAINED_WORK_TYPE);
message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "third", ROOT_SECTION_THIRD_CHILD_LABEL, "label");
Assert.assertEquals(message, metsSectionList.get(2).getLabel(), ROOT_SECTION_THIRD_CHILD_LABEL);
message = String.format(SECTION_ASSERT_MESSAGE_PATTERN, "third", CHAPTER_TYPE, "type");
Assert.assertEquals(message, metsSectionList.get(2).getType(), CHAPTER_TYPE);
}
use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.
the class MCRJSONSimpleModelConverter method processSections.
private static void processSections(MCRMetsSection current, Hashtable<String, MCRMetsSection> idSectionTable, Map<String, MCRMetsFile> idFileMap) {
idSectionTable.put(current.getId(), current);
final List<MCRMetsAltoLink> altoLinks = current.getAltoLinks().stream().map(altoLink -> {
if (altoLink instanceof MCRAltoLinkTypeAdapter.MCRAltoLinkPlaceHolder) {
MCRAltoLinkTypeAdapter.MCRAltoLinkPlaceHolder ph = (MCRAltoLinkTypeAdapter.MCRAltoLinkPlaceHolder) altoLink;
if (!idFileMap.containsKey(ph.getFileID())) {
throw new MCRException("Could not parse link from section to alto! (FileID of alto not found in file list)");
}
return new MCRMetsAltoLink(idFileMap.get(ph.getFileID()), ph.getBegin(), ph.getEnd());
}
return altoLink;
}).collect(toList());
current.setAltoLinks(altoLinks);
current.getMetsSectionList().forEach((child) -> {
child.setParent(current);
processSections(child, idSectionTable, idFileMap);
});
}
use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.
the class MCRSimpleModelXMLConverter method toXML.
/**
* Converts MetsSimpleModel to XML
* @param msm the MetsSimpleModel which should be converted
* @return xml
*/
public static Document toXML(MCRMetsSimpleModel msm) {
Mets mets = new Mets();
Hashtable<MCRMetsPage, String> pageIdMap = new Hashtable<>();
Map<String, String> idToNewIDMap = new Hashtable<>();
buildPhysicalPages(msm, mets, pageIdMap, idToNewIDMap);
Hashtable<MCRMetsSection, String> sectionIdMap = new Hashtable<>();
buildLogicalPages(msm, mets, sectionIdMap, idToNewIDMap);
StructLink structLink = mets.getStructLink();
msm.getSectionPageLinkList().stream().map((metsLink) -> {
MCRMetsSection section = metsLink.getFrom();
MCRMetsPage page = metsLink.getTo();
String fromId = sectionIdMap.get(section);
String toId = pageIdMap.get(page);
return new SmLink(fromId, toId);
}).forEach(structLink::addSmLink);
return mets.asDocument();
}
use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.
the class MCRSimpleModelXMLConverter method buildLogicalSubDiv.
private static void buildLogicalSubDiv(MCRMetsSection metsSection, LogicalDiv parent, Map<MCRMetsSection, String> sectionIdMap, Map<String, String> idToNewIDMap) {
String id = metsSection.getId();
LogicalDiv logicalSubDiv = new LogicalDiv(id, metsSection.getType(), metsSection.getLabel());
if (metsSection.getAltoLinks().size() > 0) {
Fptr fptr = new Fptr();
List<Seq> seqList = fptr.getSeqList();
Seq seq = new Seq();
seqList.add(seq);
metsSection.getAltoLinks().forEach(al -> {
Area area = new Area();
seq.getAreaList().add(area);
area.setBetype("IDREF");
area.setBegin(al.getBegin());
area.setEnd(al.getEnd());
String oldID = al.getFile().getId();
if (!idToNewIDMap.containsKey(oldID)) {
throw new MCRException("Could not get new id for: " + oldID);
}
area.setFileId(idToNewIDMap.get(oldID));
});
logicalSubDiv.getFptrList().add(fptr);
}
sectionIdMap.put(metsSection, id);
parent.add(logicalSubDiv);
int count = 1;
for (MCRMetsSection section : metsSection.getMetsSectionList()) {
buildLogicalSubDiv(section, logicalSubDiv, sectionIdMap, idToNewIDMap);
}
}
Aggregations