Search in sources :

Example 1 with MCRMetsFile

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

the class MCRXMLSimpleModelConverterTest method testFromXMLMetsFiles.

@org.junit.Test
public void testFromXMLMetsFiles() throws Exception {
    Iterator<MCRMetsFile> hrefIterator = metsSimpleModel.getMetsPageList().stream().map((p) -> {
        Optional<MCRMetsFile> first = p.getFileList().stream().findFirst();
        return first.get();
    }).iterator();
    int i = 0;
    while (hrefIterator.hasNext()) {
        i++;
        MCRMetsFile mcrMetsFile = hrefIterator.next();
        String expectedFileName = String.format(FILE_NAME_MATCH_PATTERN, i);
        String message = String.format("href %s should match %s", mcrMetsFile.getHref(), expectedFileName);
        Assert.assertEquals(message, mcrMetsFile.getHref(), expectedFileName);
        message = String.format("MimeType %s should match %s", mcrMetsFile.getMimeType(), ALL_FILE_MIMETYPE);
        Assert.assertEquals(message, mcrMetsFile.getMimeType(), ALL_FILE_MIMETYPE);
        message = String.format("File-Use %s should match %s", mcrMetsFile.getUse(), MASTER);
        Assert.assertEquals(message, mcrMetsFile.getUse(), MASTER);
    }
}
Also used : Document(org.jdom2.Document) MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Iterator(java.util.Iterator) Optional(java.util.Optional) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse) MCRMetsSection(org.mycore.mets.model.simple.MCRMetsSection) Assert(org.junit.Assert) MCRMetsSimpleModel(org.mycore.mets.model.simple.MCRMetsSimpleModel) LogManager(org.apache.logging.log4j.LogManager) Before(org.junit.Before) Optional(java.util.Optional) MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile)

Example 2 with MCRMetsFile

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

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

the class MCRXMLSimpleModelConverter method addFilesFromGroup.

private static void addFilesFromGroup(Map<String, MCRMetsFile> idPageMap, FileGrp fileGroup) {
    String fileGroupUse = fileGroup.getUse();
    fileGroup.getFileList().forEach(file -> {
        MCRMetsFileUse use = Enum.valueOf(MCRMetsFileUse.class, fileGroupUse);
        idPageMap.put(file.getId(), new MCRMetsFile(file.getId(), file.getFLocat().getHref(), file.getMimeType(), use));
    });
}
Also used : MCRMetsFile(org.mycore.mets.model.simple.MCRMetsFile) MCRMetsFileUse(org.mycore.mets.model.simple.MCRMetsFileUse)

Example 4 with MCRMetsFile

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

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

Aggregations

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