Search in sources :

Example 1 with MCRMetsPage

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;
}
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 2 with MCRMetsPage

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;
}
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)

Example 3 with MCRMetsPage

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

Example 4 with MCRMetsPage

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

Example 5 with MCRMetsPage

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));
        });
    }
}
Also used : PhysicalStructMap(org.mycore.mets.model.struct.PhysicalStructMap) MCRMetsPage(org.mycore.mets.model.simple.MCRMetsPage) FileGrp(org.mycore.mets.model.files.FileGrp) Fptr(org.mycore.mets.model.struct.Fptr) FLocat(org.mycore.mets.model.files.FLocat) File(org.mycore.mets.model.files.File) PhysicalDiv(org.mycore.mets.model.struct.PhysicalDiv) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) PhysicalSubDiv(org.mycore.mets.model.struct.PhysicalSubDiv)

Aggregations

MCRMetsPage (org.mycore.mets.model.simple.MCRMetsPage)7 MCRMetsSection (org.mycore.mets.model.simple.MCRMetsSection)5 Hashtable (java.util.Hashtable)4 MCRMetsFile (org.mycore.mets.model.simple.MCRMetsFile)4 MCRMetsFileUse (org.mycore.mets.model.simple.MCRMetsFileUse)4 MCRMetsSimpleModel (org.mycore.mets.model.simple.MCRMetsSimpleModel)4 List (java.util.List)3 Map (java.util.Map)3 MCRException (org.mycore.common.MCRException)3 Mets (org.mycore.mets.model.Mets)3 FileGrp (org.mycore.mets.model.files.FileGrp)3 MCRMetsLink (org.mycore.mets.model.simple.MCRMetsLink)3 PhysicalStructMap (org.mycore.mets.model.struct.PhysicalStructMap)3 PhysicalSubDiv (org.mycore.mets.model.struct.PhysicalSubDiv)3 Document (org.jdom2.Document)2 FLocat (org.mycore.mets.model.files.FLocat)2 File (org.mycore.mets.model.files.File)2 MCRMetsAltoLink (org.mycore.mets.model.simple.MCRMetsAltoLink)2 Fptr (org.mycore.mets.model.struct.Fptr)2 LogicalDiv (org.mycore.mets.model.struct.LogicalDiv)2