Search in sources :

Example 6 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method createDocument.

@Test
public void createDocument() throws Exception {
    Document testXmlDoc = new Document(new Element("root"));
    MCRContent testContent = new MCRJDOMContent(testXmlDoc);
    MCRVersionedMetadata versionedMetadata = getVersStore().create(testContent);
    MCRContent contentFromStore = getVersStore().retrieve(versionedMetadata.getID()).getMetadata();
    String contentStrFromStore = contentFromStore.asString();
    MCRContent mcrContent = new MCRJDOMContent(testXmlDoc);
    String expectedContentStr = mcrContent.asString();
    assertNotNull(versionedMetadata);
    assertEquals(expectedContentStr, contentStrFromStore);
    assertTrue(versionedMetadata.getID() > 0);
    assertTrue(versionedMetadata.getRevision() > 0);
    MCRVersionedMetadata vm3 = getVersStore().create(new MCRJDOMContent(testXmlDoc));
    assertTrue(vm3.getID() > versionedMetadata.getID());
    assertTrue(vm3.getRevision() > versionedMetadata.getRevision());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Example 7 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method retrieve.

@Test
public void retrieve() throws Exception {
    Document xml1 = new Document(new Element("root"));
    int id = getVersStore().create(new MCRJDOMContent(xml1)).getID();
    MCRVersionedMetadata sm1 = getVersStore().retrieve(id);
    MCRContent xml2 = sm1.getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Example 8 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRVersioningMetadataStoreTest method createDocumentInt.

@Test
public void createDocumentInt() throws Exception {
    int id = getVersStore().getNextFreeID();
    assertTrue(id > 0);
    Document xml1 = new Document(new Element("root"));
    MCRVersionedMetadata vm1 = getVersStore().create(new MCRJDOMContent(xml1), id);
    MCRContent xml2 = getVersStore().retrieve(id).getMetadata();
    assertNotNull(vm1);
    assertEquals(new MCRJDOMContent(xml1).asString(), xml2.asString());
    getVersStore().create(new MCRJDOMContent(xml1), id + 1);
    MCRContent xml3 = getVersStore().retrieve(id + 1).getMetadata();
    assertEquals(new MCRJDOMContent(xml1).asString(), xml3.asString());
}
Also used : Element(org.jdom2.Element) MCRJDOMContent(org.mycore.common.content.MCRJDOMContent) Document(org.jdom2.Document) MCRContent(org.mycore.common.content.MCRContent) Test(org.junit.Test)

Example 9 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRSolrIndexEventHandler method addObject.

protected synchronized void addObject(MCREvent evt, MCRBase objectOrDerivate) {
    // do not add objects which are marked for import or deletion
    if (MCRMarkManager.instance().isMarked(objectOrDerivate)) {
        return;
    }
    MCRSessionMgr.getCurrentSession().onCommit(() -> {
        long tStart = System.currentTimeMillis();
        try {
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Solr: submitting data of \"{}\" for indexing", objectOrDerivate.getId());
            }
            MCRContent content = (MCRContent) evt.get("content");
            if (content == null) {
                content = new MCRBaseContent(objectOrDerivate);
            }
            MCRSolrIndexHandler indexHandler = MCRSolrIndexHandlerFactory.getInstance().getIndexHandler(content, objectOrDerivate.getId());
            indexHandler.setCommitWithin(1000);
            MCRSolrIndexer.submitIndexHandler(indexHandler, MCRSolrIndexer.HIGH_PRIORITY);
            if (LOGGER.isDebugEnabled()) {
                LOGGER.debug("Solr: submitting data of \"{}\" for indexing done in {}ms ", objectOrDerivate.getId(), System.currentTimeMillis() - tStart);
            }
        } catch (Exception ex) {
            LOGGER.error("Error creating transfer thread for object {}", objectOrDerivate, ex);
        }
    });
}
Also used : MCRBaseContent(org.mycore.common.content.MCRBaseContent) MCRContent(org.mycore.common.content.MCRContent)

Example 10 with MCRContent

use of org.mycore.common.content.MCRContent in project mycore by MyCoRe-Org.

the class MCRSolrIndexer method rebuildMetadataIndex.

/**
 * Rebuilds solr's metadata index.
 *
 * @param list
 *            list of identifiers of the objects to index
 * @param solrClient
 *            solr server to index
 */
public static void rebuildMetadataIndex(List<String> list, SolrClient solrClient) {
    LOGGER.info("Re-building Metadata Index");
    if (list.isEmpty()) {
        LOGGER.info("Sorry, no documents to index");
        return;
    }
    StopWatch swatch = new StopWatch();
    swatch.start();
    int totalCount = list.size();
    LOGGER.info("Sending {} objects to solr for reindexing", totalCount);
    MCRXMLMetadataManager metadataMgr = MCRXMLMetadataManager.instance();
    MCRSolrIndexStatistic statistic = null;
    HashMap<MCRObjectID, MCRContent> contentMap = new HashMap<>((int) (BULK_SIZE * 1.4));
    int i = 0;
    for (String id : list) {
        i++;
        try {
            LOGGER.debug("Preparing \"{}\" for indexing", id);
            MCRObjectID objId = MCRObjectID.getInstance(id);
            MCRContent content = metadataMgr.retrieveContent(objId);
            contentMap.put(objId, content);
            if (i % BULK_SIZE == 0 || totalCount == i) {
                MCRSolrIndexHandler indexHandler = MCRSolrIndexHandlerFactory.getInstance().getIndexHandler(contentMap);
                indexHandler.setCommitWithin(BATCH_AUTO_COMMIT_WITHIN_MS);
                indexHandler.setSolrServer(solrClient);
                statistic = indexHandler.getStatistic();
                submitIndexHandler(indexHandler);
                contentMap = new HashMap<>((int) (BULK_SIZE * 1.4));
            }
        } catch (Exception ex) {
            LOGGER.error("Error creating index thread for object {}", id, ex);
        }
    }
    long durationInMilliSeconds = swatch.getTime();
    if (statistic != null) {
        statistic.addTime(durationInMilliSeconds);
    }
}
Also used : MCRSolrIndexStatistic(org.mycore.solr.index.statistic.MCRSolrIndexStatistic) HashMap(java.util.HashMap) MCRXMLMetadataManager(org.mycore.datamodel.common.MCRXMLMetadataManager) MCRContent(org.mycore.common.content.MCRContent) SolrServerException(org.apache.solr.client.solrj.SolrServerException) IOException(java.io.IOException) StopWatch(org.apache.commons.lang.time.StopWatch) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Aggregations

MCRContent (org.mycore.common.content.MCRContent)63 Document (org.jdom2.Document)21 MCRJDOMContent (org.mycore.common.content.MCRJDOMContent)20 IOException (java.io.IOException)16 Element (org.jdom2.Element)13 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)11 MCRPath (org.mycore.datamodel.niofs.MCRPath)10 Test (org.junit.Test)8 MCRPathContent (org.mycore.common.content.MCRPathContent)7 MCRParameterCollector (org.mycore.common.xsl.MCRParameterCollector)6 File (java.io.File)5 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JDOMException (org.jdom2.JDOMException)5 InputStream (java.io.InputStream)4 HashMap (java.util.HashMap)4 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 MCRException (org.mycore.common.MCRException)4 MCRDerivate (org.mycore.datamodel.metadata.MCRDerivate)4 URL (java.net.URL)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3