org.kie.kogito.eventdriven.decision.EventDrivenDecisionController Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kogito-addons-events-decisions
Show all versions of kogito-addons-events-decisions
Trigger evaluation of decision models via events
/*
* Copyright 2021 Red Hat, Inc. and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.kie.kogito.eventdriven.decision;
import java.net.URI;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import org.kie.dmn.api.core.DMNContext;
import org.kie.dmn.api.core.DMNResult;
import org.kie.kogito.config.ConfigBean;
import org.kie.kogito.decision.DecisionExecutionIdUtils;
import org.kie.kogito.decision.DecisionModel;
import org.kie.kogito.decision.DecisionModels;
import org.kie.kogito.dmn.rest.DMNJSONUtils;
import org.kie.kogito.dmn.rest.KogitoDMNResult;
import org.kie.kogito.event.DataEvent;
import org.kie.kogito.event.DataEventFactory;
import org.kie.kogito.event.EventEmitter;
import org.kie.kogito.event.EventReceiver;
import org.kie.kogito.event.cloudevents.extension.KogitoExtension;
import org.kie.kogito.event.cloudevents.utils.CloudEventUtils;
import org.kie.kogito.internal.utils.ConversionUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.cloudevents.core.provider.ExtensionProvider;
/**
* This class must always have exact FQCN as org.kie.kogito.eventdriven.decision.EventDrivenDecisionController
* for code generation plugins to correctly detect if this addon is enabled.
*/
public class EventDrivenDecisionController {
public static final String REQUEST_EVENT_TYPE = "DecisionRequest";
public static final String RESPONSE_EVENT_TYPE = "DecisionResponse";
public static final String RESPONSE_FULL_EVENT_TYPE = "DecisionResponseFull";
private static final Logger LOG = LoggerFactory.getLogger(EventDrivenDecisionController.class);
private DecisionModels decisionModels;
private ConfigBean config;
private EventEmitter eventEmitter;
private EventReceiver eventReceiver;
protected EventDrivenDecisionController() {
}
protected EventDrivenDecisionController(DecisionModels decisionModels, ConfigBean config, EventEmitter eventEmitter, EventReceiver eventReceiver) {
init(decisionModels, config, eventEmitter, eventReceiver);
}
protected void init(DecisionModels decisionModels, ConfigBean config, EventEmitter eventEmitter, EventReceiver eventReceiver) {
this.decisionModels = decisionModels;
this.config = config;
this.eventEmitter = eventEmitter;
this.eventReceiver = eventReceiver;
}
protected void subscribe() {
eventReceiver.subscribe(this::handleRequest, Map.class);
}
private CompletionStage handleRequest(DataEvent
© 2015 - 2025 Weber Informatics LLC | Privacy Policy