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

io.vertx.tp.workflow.uca.camunda.IoEventEnd Maven / Gradle / Ivy

The newest version!
package io.vertx.tp.workflow.uca.camunda;

import io.horizon.eon.VValue;
import io.vertx.core.Future;
import io.vertx.core.json.JsonObject;
import io.vertx.tp.error._409EventEndUniqueException;
import io.vertx.tp.error._501EventEndMissingException;
import io.vertx.tp.workflow.init.WfPin;
import io.vertx.up.eon.KName;
import io.vertx.up.fn.Fn;
import io.vertx.up.unity.Ux;
import io.vertx.up.util.Ut;
import org.camunda.bpm.engine.RepositoryService;
import org.camunda.bpm.model.bpmn.BpmnModelInstance;
import org.camunda.bpm.model.bpmn.instance.EndEvent;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * @author Lang
 */
class IoEventEnd extends AbstractIo {

    // 「IoBpmn」ProcessDefinition -> List
    @Override
    public Future> children(final String definitionId) {
        if (Ut.isNil(definitionId)) {
            return Ux.futureL();
        }
        final RepositoryService service = WfPin.camundaRepository();
        final BpmnModelInstance instance = service.getBpmnModelInstance(definitionId);
        final Collection ends = instance.getModelElementsByType(EndEvent.class);
        if (ends.isEmpty()) {
            return Fn.outWeb(_501EventEndMissingException.class, this.getClass(), definitionId);
        }
        return Ux.future(new ArrayList<>(ends));
    }


    // 「IoBpmn」ProcessDefinition -> EndEvent
    @Override
    public Future child(final String definitionId) {
        return this.children(definitionId).compose(list -> {
            final int size = list.size();
            if (VValue.ONE == size) {
                return Ux.future(list.get(VValue.IDX));
            } else {
                return Fn.outWeb(_409EventEndUniqueException.class, this.getClass(), size, definitionId);
            }
        });
    }

    @Override
    public Future out(final JsonObject workflow, final List ends) {
        if (1 == ends.size()) {
            final EndEvent event = ends.get(VValue.IDX);
            /*
             * task:        id
             * taskName:    name
             */
            workflow.put(KName.Flow.TASK, event.getId());
            workflow.put(KName.Flow.TASK_NAME, event.getName());
        } else {
            final JsonObject taskMap = new JsonObject();
            ends.forEach(start -> taskMap.put(start.getId(), start.getName()));
            /*
             * id1:      name1
             * id2:      name2
             */
            workflow.put(KName.Flow.TASK, taskMap);
        }
        return Ux.future(workflow);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy