Search in sources :

Example 6 with MCREvent

use of org.mycore.common.events.MCREvent in project mycore by MyCoRe-Org.

the class MCRPersistentIdentifierEventHandler method handleObjectRepaired.

@Override
protected void handleObjectRepaired(MCREvent evt, MCRObject obj) {
    /* Add PIs to DB if they are not there */
    MCRPersistentIdentifierManager.getInstance().getRegistered(obj).forEach(pi -> MCRPersistentIdentifierManager.getInstance().delete(pi.getMycoreID(), pi.getAdditional(), pi.getType(), pi.getService()));
    Gson gson = new Gson();
    obj.getService().getFlags(MCRPIRegistrationService.PI_FLAG).stream().map(piFlag -> gson.fromJson(piFlag, MCRPI.class)).filter(entry -> !MCRPersistentIdentifierManager.getInstance().exist(entry)).forEach(entry -> {
        // TODO: disabled for MCR-1393
        // entry.setMcrRevision(MCRCoreVersion.getRevision());
        entry.setMcrVersion(MCRCoreVersion.getVersion());
        entry.setMycoreID(obj.getId().toString());
        LOGGER.info("Add PI : {} with service {} to database!", entry.getIdentifier(), entry.getService());
        MCRHIBConnection.instance().getSession().save(entry);
    });
    handleObjectUpdated(evt, obj);
}
Also used : MCRPersistentIdentifierException(org.mycore.pi.exceptions.MCRPersistentIdentifierException) MCRHIBConnection(org.mycore.backend.hibernate.MCRHIBConnection) MCREvent(org.mycore.common.events.MCREvent) MCRException(org.mycore.common.MCRException) MCREventHandlerBase(org.mycore.common.events.MCREventHandlerBase) MCRPI(org.mycore.pi.backend.MCRPI) MCRCoreVersion(org.mycore.common.MCRCoreVersion) List(java.util.List) Logger(org.apache.logging.log4j.Logger) Gson(com.google.gson.Gson) MCRObject(org.mycore.datamodel.metadata.MCRObject) BiConsumer(java.util.function.BiConsumer) LogManager(org.apache.logging.log4j.LogManager) Gson(com.google.gson.Gson) MCRPI(org.mycore.pi.backend.MCRPI)

Example 7 with MCREvent

use of org.mycore.common.events.MCREvent in project mycore by MyCoRe-Org.

the class MCRFile method delete.

/**
 * Deletes this file and its content stored in the system. Note that after
 * calling this method, the file object is deleted and invalid and can not
 * be used any more.
 */
@Override
public void delete() throws MCRPersistenceException {
    ensureNotDeleted();
    if (storageID.length() != 0) {
        BasicFileAttributes attrs;
        try {
            attrs = getBasicFileAttributes();
        } catch (IOException e) {
            attrs = MCRFileAttributes.file(getID(), getSize(), getMD5(), FileTime.from(getLastModified().toInstant()));
        }
        getContentStore().deleteContent(storageID);
        // Call event handlers to update indexed content
        MCREvent event = new MCREvent(MCREvent.PATH_TYPE, MCREvent.DELETE_EVENT);
        // to support old events
        event.put(MCRFileEventHandlerBase.FILE_TYPE, this);
        event.put(MCREvent.PATH_KEY, toPath());
        event.put(MCREvent.FILEATTR_KEY, attrs);
        MCREventManager.instance().handleEvent(event);
        if (hasParent()) {
            getParent().sizeOfChildChanged(-size);
        }
    }
    super.delete();
    contentTypeID = null;
    md5 = null;
    storageID = null;
    storeID = null;
    avExtender = null;
}
Also used : MCREvent(org.mycore.common.events.MCREvent) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) BasicFileAttributes(java.nio.file.attribute.BasicFileAttributes)

Example 8 with MCREvent

use of org.mycore.common.events.MCREvent in project mycore by MyCoRe-Org.

the class MCRFilesystemNode method fireUpdateEvent.

protected void fireUpdateEvent() {
    MCREvent event = new MCREvent(MCREvent.PATH_TYPE, MCREvent.UPDATE_EVENT);
    // to support old events
    event.put(MCRFileEventHandlerBase.FILE_TYPE, this);
    event.put(MCREvent.PATH_KEY, toPath());
    try {
        event.put(MCREvent.FILEATTR_KEY, getBasicFileAttributes());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    MCREventManager.instance().handleEvent(event);
}
Also used : MCREvent(org.mycore.common.events.MCREvent) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException)

Example 9 with MCREvent

use of org.mycore.common.events.MCREvent in project mycore by MyCoRe-Org.

the class MCRMODSLinksEventHandler method handleObjectUpdated.

/* (non-Javadoc)
     * @see org.mycore.common.events.MCREventHandlerBase#handleObjectUpdated(org.mycore.common.events.MCREvent, org.mycore.datamodel.metadata.MCRObject)
     */
@Override
protected void handleObjectUpdated(final MCREvent evt, final MCRObject obj) {
    if (!MCRMODSWrapper.isSupported(obj)) {
        return;
    }
    handleObjectCreated(evt, obj);
    // may have to reindex children, if they inherit any information
    for (MCRMetaLinkID childLinkID : obj.getStructure().getChildren()) {
        MCRObjectID childID = childLinkID.getXLinkHrefID();
        if (MCRMetadataManager.exists(childID)) {
            MCREvent childEvent = new MCREvent(childID.getTypeId(), MCREvent.INDEX_EVENT);
            childEvent.put("object", MCRMetadataManager.retrieve(childID));
            MCREventManager.instance().handleEvent(childEvent);
        }
    }
}
Also used : MCREvent(org.mycore.common.events.MCREvent) MCRMetaLinkID(org.mycore.datamodel.metadata.MCRMetaLinkID) MCRObjectID(org.mycore.datamodel.metadata.MCRObjectID)

Aggregations

MCREvent (org.mycore.common.events.MCREvent)9 IOException (java.io.IOException)3 BasicFileAttributes (java.nio.file.attribute.BasicFileAttributes)3 UncheckedIOException (java.io.UncheckedIOException)2 MCRPath (org.mycore.datamodel.niofs.MCRPath)2 Gson (com.google.gson.Gson)1 HashSet (java.util.HashSet)1 List (java.util.List)1 BiConsumer (java.util.function.BiConsumer)1 LogManager (org.apache.logging.log4j.LogManager)1 Logger (org.apache.logging.log4j.Logger)1 MCRHIBConnection (org.mycore.backend.hibernate.MCRHIBConnection)1 MCRCoreVersion (org.mycore.common.MCRCoreVersion)1 MCRException (org.mycore.common.MCRException)1 MCREventHandlerBase (org.mycore.common.events.MCREventHandlerBase)1 MCRCategLinkReference (org.mycore.datamodel.classifications2.MCRCategLinkReference)1 MCRMetaLinkID (org.mycore.datamodel.metadata.MCRMetaLinkID)1 MCRObject (org.mycore.datamodel.metadata.MCRObject)1 MCRObjectID (org.mycore.datamodel.metadata.MCRObjectID)1 MCRIFSFileSystem (org.mycore.datamodel.niofs.ifs1.MCRIFSFileSystem)1