Search in sources :

Example 6 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRRSSFeedImporter method sendNotificationMail.

private void sendNotificationMail(List<MCRObject> importedObjects) throws Exception {
    Element xml = new Element(STATUS_FLAG).setAttribute("source", this.sourceSystemID);
    for (MCRObject obj : importedObjects) {
        xml.addContent(obj.createXML().detachRootElement());
    }
    HashMap<String, String> parameters = new HashMap<>();
    parameters.put(PROPERTY_MAIL_ADDRESS, MCRConfiguration.instance().getString(PROPERTY_MAIL_ADDRESS));
    MCRMailer.sendMail(new Document(xml), xsl2BuildNotificationMail, parameters);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) HashMap(java.util.HashMap) Element(org.jdom2.Element) Document(org.jdom2.Document)

Example 7 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRRSSFeedImporter method buildMCRObject.

private MCRObject buildMCRObject(Element publicationXML, String projectID) {
    MCRObject obj = new MCRObject(new Document(publicationXML));
    MCRMODSWrapper wrapper = new MCRMODSWrapper(obj);
    wrapper.setServiceFlag("status", STATUS_FLAG);
    MCRObjectID oid = MCRObjectID.getNextFreeId(projectID, "mods");
    obj.setId(oid);
    return obj;
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) MCRMODSWrapper(org.mycore.mods.MCRMODSWrapper) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) Document(org.jdom2.Document)

Example 8 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRMODSLinkedMetadataTest method setUp.

@Before
public void setUp() throws Exception {
    super.setUp();
    seriesID = MCRObjectID.getInstance("junit_mods_00000001");
    bookID = MCRObjectID.getInstance("junit_mods_00000002");
    MCRSessionMgr.getCurrentSession().setUserInformation(MCRSystemUserInformation.getSuperUserInstance());
    MCRObject series = new MCRObject(getResourceAsURL(seriesID + ".xml").toURI());
    MCRObject book = new MCRObject(getResourceAsURL(bookID + ".xml").toURI());
    MCRMetadataManager.create(series);
    MCRMetadataManager.create(book);
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Before(org.junit.Before)

Example 9 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRMODSLinkedMetadataTest method testUpdate.

@Test
public void testUpdate() throws IOException, URISyntaxException, MCRPersistenceException, MCRActiveLinkException, JDOMException, SAXException, MCRAccessException {
    MCRObject seriesNew = new MCRObject(getResourceAsURL(seriesID + "-updated.xml").toURI());
    MCRMetadataManager.update(seriesNew);
    Document bookNew = MCRXMLMetadataManager.instance().retrieveXML(bookID);
    XPathBuilder<Element> builder = new XPathBuilder<>("/mycoreobject/metadata/def.modsContainer/modsContainer/mods:mods/mods:relatedItem/mods:titleInfo/mods:title", Filters.element());
    builder.setNamespace(MCRConstants.MODS_NAMESPACE);
    XPathExpression<Element> seriesTitlePath = builder.compileWith(XPathFactory.instance());
    Element titleElement = seriesTitlePath.evaluateFirst(bookNew);
    Assert.assertNotNull("No title element in related item: " + new XMLOutputter(Format.getPrettyFormat()).outputString(bookNew), titleElement);
    Assert.assertEquals("Title update from series was not promoted to book of series.", "Updated series title", titleElement.getText());
}
Also used : XMLOutputter(org.jdom2.output.XMLOutputter) MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) XPathBuilder(org.jdom2.xpath.XPathBuilder) Document(org.jdom2.Document) Test(org.junit.Test)

Example 10 with MCRObject

use of org.mycore.datamodel.metadata.MCRObject in project mycore by MyCoRe-Org.

the class MCRMODSWrapperTest method testWrapMODSDocument.

/**
 * Test method for {@link org.mycore.mods.MCRMODSWrapper#wrapMODSDocument(org.jdom2.Element, java.lang.String)}.
 */
@Test
public void testWrapMODSDocument() throws SAXParseException, URISyntaxException, JDOMException, IOException {
    Document modsDoc = loadMODSDocument();
    MCRObject mcrObj = MCRMODSWrapper.wrapMODSDocument(modsDoc.getRootElement(), "JUnit");
    assertTrue("Generated MCRObject is not valid.", mcrObj.isValid());
    Document mcrObjXml = mcrObj.createXML();
    // check load from XML throws no exception
    MCRObject mcrObj2 = new MCRObject(mcrObjXml);
    mcrObjXml = mcrObj2.createXML();
    XPathExpression<Element> xpathCheck = XPathFactory.instance().compile("//mods:mods", Filters.element(), null, MCRConstants.MODS_NAMESPACE);
    assertEquals("Did not find mods data", 1, xpathCheck.evaluate(mcrObjXml).size());
}
Also used : MCRObject(org.mycore.datamodel.metadata.MCRObject) Element(org.jdom2.Element) Document(org.jdom2.Document) Test(org.junit.Test)

Aggregations

MCRObject (org.mycore.datamodel.metadata.MCRObject)71 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)33 Document (org.jdom2.Document)18 Element (org.jdom2.Element)17 MCRException (org.mycore.common.MCRException)16 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)14 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)14 MCRCommand (org.mycore.frontend.cli.annotation.MCRCommand)12 IOException (java.io.IOException)11 MCRAccessException (org.mycore.access.MCRAccessException)11 MCRMODSWrapper (org.mycore.mods.MCRMODSWrapper)9 MCRPersistenceException (org.mycore.common.MCRPersistenceException)7 Date (java.util.Date)6 JDOMException (org.jdom2.JDOMException)6 MCRActiveLinkException (org.mycore.datamodel.common.MCRActiveLinkException)6 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)6 SAXException (org.xml.sax.SAXException)6 URI (java.net.URI)5 URISyntaxException (java.net.URISyntaxException)5 ArrayList (java.util.ArrayList)5