Search in sources :

Example 1 with MCRBaseContent

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);
        }
    });
}
Also used : MCRBaseContent(org.mycore.common.content.MCRBaseContent) MCRContent(org.mycore.common.content.MCRContent)

Example 2 with MCRBaseContent

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);
}
Also used : HashMap(java.util.HashMap) MCRBaseContent(org.mycore.common.content.MCRBaseContent) MCRBase(org.mycore.datamodel.metadata.MCRBase) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) MCRContent(org.mycore.common.content.MCRContent)

Example 3 with MCRBaseContent

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);
    }
}
Also used : Schema(javax.xml.validation.Schema) MCRBaseContent(org.mycore.common.content.MCRBaseContent) JDOMSource(org.jdom2.transform.JDOMSource) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) Document(org.jdom2.Document) MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) JDOMException(org.jdom2.JDOMException) MCRContent(org.mycore.common.content.MCRContent) SAXException(org.xml.sax.SAXException)

Example 4 with MCRBaseContent

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);
    }
}
Also used : MCRBaseContent(org.mycore.common.content.MCRBaseContent) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID) IOException(java.io.IOException) MCRContent(org.mycore.common.content.MCRContent) MCRPersistenceException(org.mycore.common.MCRPersistenceException) Date(java.util.Date)

Aggregations

MCRBaseContent (org.mycore.common.content.MCRBaseContent)4 MCRContent (org.mycore.common.content.MCRContent)4 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)3 IOException (java.io.IOException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Schema (javax.xml.validation.Schema)1 Document (org.jdom2.Document)1 JDOMException (org.jdom2.JDOMException)1 JDOMSource (org.jdom2.transform.JDOMSource)1 MCRPersistenceException (org.mycore.common.MCRPersistenceException)1 MCRBase (org.mycore.datamodel.metadata.MCRBase)1 MCRPersistentIdentifierException (org.mycore.pi.exceptions.MCRPersistentIdentifierException)1 SAXException (org.xml.sax.SAXException)1