use of org.mycore.common.content.MCRBaseContent 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.MCRBaseContent in project mycore by MyCoRe-Org.
the class MCRSolrIndexHandlerFactory method getIndexHandler.
public MCRSolrIndexHandler getIndexHandler(MCRBase... derOrObjs) {
if (derOrObjs.length == 1) {
MCRBaseContent content = new MCRBaseContent(derOrObjs[0]);
return getIndexHandler(content, derOrObjs[0].getId());
}
HashMap<MCRObjectID, MCRContent> contentMap = new HashMap<>();
for (MCRBase derOrObj : derOrObjs) {
MCRBaseContent content = new MCRBaseContent(derOrObj);
contentMap.put(derOrObj.getId(), content);
}
return getIndexHandler(contentMap);
}
use of org.mycore.common.content.MCRBaseContent in project mycore by MyCoRe-Org.
the class MCRDOIRegistrationService method transformToDatacite.
protected Document transformToDatacite(MCRDigitalObjectIdentifier doi, MCRBase mcrBase) throws MCRPersistentIdentifierException {
MCRObjectID id = mcrBase.getId();
MCRBaseContent content = new MCRBaseContent(mcrBase);
try {
MCRContent transform = MCRContentTransformerFactory.getTransformer(this.transformer).transform(content);
Document dataciteDocument = transform.asXML();
insertDOI(dataciteDocument, doi);
Schema dataciteSchema = loadDataciteSchema();
try {
dataciteSchema.newValidator().validate(new JDOMSource(dataciteDocument));
} catch (SAXException e) {
String translatedInformation = MCRTranslation.translate(TRANSLATE_PREFIX + ERR_CODE_1_2);
throw new MCRPersistentIdentifierException("The document " + id + " does not generate well formed Datacite!", translatedInformation, ERR_CODE_1_2, e);
}
return dataciteDocument;
} catch (IOException | JDOMException | SAXException e) {
throw new MCRPersistentIdentifierException("Could not transform the content of " + id + " with the transformer " + transformer, e);
}
}
use of org.mycore.common.content.MCRBaseContent in project mycore by MyCoRe-Org.
the class MCRXMLMetadataEventHandler method handleStoreEvent.
private void handleStoreEvent(MCREvent evt, MCRBase obj) {
String eventType = evt.getEventType();
MCRObjectID id = obj.getId();
try {
switch(eventType) {
case MCREvent.REPAIR_EVENT:
case MCREvent.UPDATE_EVENT:
case MCREvent.CREATE_EVENT:
MCRBaseContent content = new MCRBaseContent(obj);
Date modified = obj.getService().getDate(MCRObjectService.DATE_TYPE_MODIFYDATE);
switch(eventType) {
case MCREvent.REPAIR_EVENT:
MCRContent retrieveContent = metaDataManager.retrieveContent(id);
if (isUptodate(retrieveContent, content)) {
return;
}
case MCREvent.UPDATE_EVENT:
metaDataManager.update(id, content, modified);
break;
case MCREvent.CREATE_EVENT:
metaDataManager.create(id, content, modified);
break;
}
evt.put("content", content);
break;
case MCREvent.DELETE_EVENT:
metaDataManager.delete(id);
break;
default:
throw new IllegalArgumentException("Invalid event type " + eventType + " for object " + id);
}
} catch (IOException e) {
throw new MCRPersistenceException("Error while handling '" + eventType + "' event of '" + id + "'", e);
}
}
Aggregations