Search in sources :

Example 1 with MCRMetsSection

use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.

the class MCRJSONSimpleModelConverterTest method testToSimpleModel.

@Test
public void testToSimpleModel() throws Exception {
    MCRMetsSimpleModel metsSimpleModel = MCRJSONSimpleModelConverter.toSimpleModel(json);
    MCRMetsSimpleModel compareSimpleModel = MCRMetsTestUtil.buildMetsSimpleModel();
    MCRMetsSection s1RootSection = metsSimpleModel.getRootSection();
    MCRMetsSection s2RootSection = compareSimpleModel.getRootSection();
    Assert.assertEquals("labels of root must be the same", s1RootSection.getLabel(), s2RootSection.getLabel());
    Assert.assertEquals("types of root must be the same", s1RootSection.getType(), s2RootSection.getType());
    Assert.assertEquals("page count must be the same", metsSimpleModel.getMetsPageList().size(), compareSimpleModel.getMetsPageList().size());
    List<MCRMetsLink> s1SectionPageLinkList = metsSimpleModel.getSectionPageLinkList();
    List<MCRMetsLink> s2SectionPageLinkList = compareSimpleModel.getSectionPageLinkList();
    for (int n = 0; n < 3; n++) {
        Assert.assertEquals("from of " + n + " link must be the same", s1SectionPageLinkList.get(n).getFrom().getLabel(), s2SectionPageLinkList.get(n).getFrom().getLabel());
        Assert.assertEquals("to of " + n + " link must be the same", s1SectionPageLinkList.get(n).getTo().getOrderLabel(), s2SectionPageLinkList.get(n).getTo().getOrderLabel());
    }
}
Also used : MCRMetsLink(org.mycore.mets.model.simple.MCRMetsLink) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection) Test(org.junit.Test)

Example 2 with MCRMetsSection

use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.

the class MCRMetsTestUtil method builSimpleModelSections.

private static void builSimpleModelSections(MCRMetsSimpleModel metsSimpleModel) {
    MCRMetsSection rootSection = new MCRMetsSection("root", "testRootType", "testRootLabel", null);
    metsSimpleModel.setRootSection(rootSection);
    MCRMetsSection subSection1 = new MCRMetsSection("sub1", "subSection", "subSection1Label", rootSection);
    MCRMetsSection subSection2 = new MCRMetsSection("sub2", "subSection", "subSection2Label", rootSection);
    rootSection.addSection(subSection1);
    rootSection.addSection(subSection2);
}
Also used : MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Example 3 with MCRMetsSection

use of org.mycore.mets.model.simple.MCRMetsSection 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;
}
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) GsonBuilder(com.google.gson.GsonBuilder) MCRMetsLink(org.mycore.mets.model.simple.MCRMetsLink) Hashtable(java.util.Hashtable) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel)

Example 4 with MCRMetsSection

use of org.mycore.mets.model.simple.MCRMetsSection in project mycore by MyCoRe-Org.

the class MCRSimpleModelXMLConverter method buildLogicalPages.

private static void buildLogicalPages(MCRMetsSimpleModel msm, Mets mets, Map<MCRMetsSection, String> sectionIdMap, Map<String, String> idToNewIDMap) {
    LogicalStructMap logicalStructMap = (LogicalStructMap) mets.getStructMap(LogicalStructMap.TYPE);
    MCRMetsSection rootSection = msm.getRootSection();
    String type = rootSection.getType();
    String label = rootSection.getLabel();
    String id = rootSection.getId();
    LogicalDiv logicalDiv = new LogicalDiv(id, type, label);
    sectionIdMap.put(rootSection, id);
    for (MCRMetsSection metsSection : rootSection.getMetsSectionList()) {
        buildLogicalSubDiv(metsSection, logicalDiv, sectionIdMap, idToNewIDMap);
    }
    logicalStructMap.setDivContainer(logicalDiv);
}
Also used : LogicalStructMap(org.mycore.mets.model.struct.LogicalStructMap) LogicalDiv(org.mycore.mets.model.struct.LogicalDiv) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection)

Example 5 with MCRMetsSection

use of org.mycore.mets.model.simple.MCRMetsSection 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;
}
Also used : Mets(org.mycore.mets.model.Mets) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel) Hashtable(java.util.Hashtable) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) 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