All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.netgrif.application.engine.workflow.service.TaskEventHandler Maven / Gradle / Ivy

Go to download

System provides workflow management functions including user, role and data management.

There is a newer version: 6.4.0
Show newest version
package com.netgrif.application.engine.workflow.service;

import com.netgrif.application.engine.elastic.service.interfaces.IElasticTaskMappingService;
import com.netgrif.application.engine.elastic.service.interfaces.IElasticTaskService;
import com.netgrif.application.engine.workflow.domain.Task;
import org.bson.Document;
import org.bson.types.ObjectId;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.mapping.event.AbstractMongoEventListener;
import org.springframework.data.mongodb.core.mapping.event.AfterDeleteEvent;
import org.springframework.data.mongodb.core.mapping.event.AfterSaveEvent;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class TaskEventHandler extends AbstractMongoEventListener {

    private static final Logger log = LoggerFactory.getLogger(TaskEventHandler.class);

    @Autowired
    private IElasticTaskService service;

    @Autowired
    private IElasticTaskMappingService taskMappingService;

    @Async
    @Override
    public void onAfterSave(AfterSaveEvent event) {
        service.index(this.taskMappingService.transform(event.getSource()));
    }

    @Override
    public void onAfterDelete(AfterDeleteEvent event) {
        Document document = event.getDocument();
        if (document == null) {
            log.warn("Trying to delete null document!");
            return;
        }

        ObjectId objectId = document.getObjectId("_id");
        if (objectId != null) {
            service.remove(objectId.toString());
            return;
        }

        String processId = document.getString("processId");
        if (processId != null) {
            service.removeByPetriNetId(processId);
            return;
        }

        throw new IllegalStateException("Task has been deleted neither by ID nor by process ID!");
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy