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