Search in sources :

Example 1 with MCRMetsLink

use of org.mycore.mets.model.simple.MCRMetsLink 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 MCRMetsLink

use of org.mycore.mets.model.simple.MCRMetsLink 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 3 with MCRMetsLink

use of org.mycore.mets.model.simple.MCRMetsLink 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)

Aggregations

MCRMetsLink (org.mycore.mets.model.simple.MCRMetsLink)3 MCRMetsSection (org.mycore.mets.model.simple.MCRMetsSection)3 MCRMetsPage (org.mycore.mets.model.simple.MCRMetsPage)2 MCRMetsSimpleModel (org.mycore.mets.model.simple.MCRMetsSimpleModel)2 GsonBuilder (com.google.gson.GsonBuilder)1 Hashtable (java.util.Hashtable)1 List (java.util.List)1 Map (java.util.Map)1 Collectors.toList (java.util.stream.Collectors.toList)1 Test (org.junit.Test)1 MCRException (org.mycore.common.MCRException)1 MCRMetsAltoLink (org.mycore.mets.model.simple.MCRMetsAltoLink)1 MCRMetsFile (org.mycore.mets.model.simple.MCRMetsFile)1 MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)1