Search in sources :

Example 6 with MCRMetsSection

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)));
}
Also used : MCRMetsLink(org.mycore.mets.model.simple.MCRMetsLink) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Example 7 with MCRMetsSection

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);
}
Also used : MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Example 8 with MCRMetsSection

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);
    });
}
Also used : MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) MCRException(org.mycore.common.MCRException) GsonBuilder(com.google.gson.GsonBuilder) MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) Map(java.util.Map) MCRMetsAltoLink(org.mycore.mets.model.simple.MCRMetsAltoLink) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel) Hashtable(java.util.Hashtable) MCRMetsLink(org.mycore.mets.model.simple.MCRMetsLink) MCRMetsAltoLink(org.mycore.mets.model.simple.MCRMetsAltoLink) MCRException(org.mycore.common.MCRException)

Example 9 with MCRMetsSection

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();
}
Also used : PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) StructLink(org.mycore.mets.model.struct.StructLink) LOCTYPE(org.mycore.mets.model.struct.LOCTYPE) Area(org.mycore.mets.model.struct.Area) MCRException(org.mycore.common.MCRException) Document(org.jdom2.Document) FileGrp(org.mycore.mets.model.files.FileGrp) Map(java.util.Map) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) File(org.mycore.mets.model.files.File) Hashtable(java.util.Hashtable) PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) Mets(org.mycore.mets.model.Mets) UUID(java.util.UUID) Seq(org.mycore.mets.model.struct.Seq) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv) SmLink(org.mycore.mets.model.struct.SmLink) List(java.util.List) Fptr(org.mycore.mets.model.struct.Fptr) LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) FLocat(org.mycore.mets.model.files.FLocat) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel) SmLink(org.mycore.mets.model.struct.SmLink) Mets(org.mycore.mets.model.Mets) Hashtable(java.util.Hashtable) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) StructLink(org.mycore.mets.model.struct.StructLink) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Example 10 with MCRMetsSection

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);
    }
}
Also used : LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) Area(org.mycore.mets.model.struct.Area) MCRException(org.mycore.common.MCRException) Fptr(org.mycore.mets.model.struct.Fptr) Seq(org.mycore.mets.model.struct.Seq) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Aggregations

MCRMetsSection (org.mycore.mets.model.simple.MCRMetsSection)11 MCRMetsPage (org.mycore.mets.model.simple.MCRMetsPage)6 MCRMetsSimpleModel (org.mycore.mets.model.simple.MCRMetsSimpleModel)6 Hashtable (java.util.Hashtable)5 MCRException (org.mycore.common.MCRException)5 MCRMetsLink (org.mycore.mets.model.simple.MCRMetsLink)5 List (java.util.List)4 Map (java.util.Map)4 MCRMetsFile (org.mycore.mets.model.simple.MCRMetsFile)4 MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)4 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)4 Mets (org.mycore.mets.model.Mets)3 MCRMetsAltoLink (org.mycore.mets.model.simple.MCRMetsAltoLink)3 LogicalStructMap (org.mycore.mets.model.struct.LogicalStructMap)3 GsonBuilder (com.google.gson.GsonBuilder)2 Collectors.toList (java.util.stream.Collectors.toList)2 Document (org.jdom2.Document)2 FileGrp (org.mycore.mets.model.files.FileGrp)2 Area (org.mycore.mets.model.struct.Area)2 Fptr (org.mycore.mets.model.struct.Fptr)2