Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a86c2be
commit 59693ef
Showing
11 changed files
with
1,115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
...example/src/main/java/info/novatec/micronaut/camunda/bpm/example/SampleEventListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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 info.novatec.micronaut.camunda.bpm.example; | ||
|
||
import info.novatec.micronaut.camunda.bpm.feature.eventing.ExecutionEvent; | ||
import info.novatec.micronaut.camunda.bpm.feature.eventing.TaskEvent; | ||
import io.micronaut.runtime.event.annotation.EventListener; | ||
import org.camunda.bpm.engine.impl.history.event.HistoryEvent; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Singleton; | ||
|
||
@Singleton | ||
public class SampleEventListener { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(SampleEventListener.class); | ||
|
||
@EventListener | ||
public void onExecutionEvent(ExecutionEvent event) { | ||
log.info("new ExecutionEvent: EventName={}, CurrentActivityName={}", event.getEventName(), | ||
event.getCurrentActivityName()); | ||
} | ||
|
||
@EventListener | ||
public void onTaskEvent(TaskEvent event) { | ||
log.info("new TaskEvent: EventName={}, Assignee={}", event.getEventName(), event.getAssignee()); | ||
} | ||
|
||
@EventListener | ||
public void onTaskEvent(HistoryEvent event) { | ||
log.info("new HistoryEvent: EventType={}", event.getEventType()); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,7 @@ camunda: | |
enabled: true | ||
filter: | ||
create: "All tasks" | ||
eventing: | ||
task: false | ||
execution: false | ||
history: false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
...ain/java/info/novatec/micronaut/camunda/bpm/feature/eventing/EventingPublisherPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
/* | ||
* Copyright 2021 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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 info.novatec.micronaut.camunda.bpm.feature.eventing; | ||
|
||
import info.novatec.micronaut.camunda.bpm.feature.Configuration; | ||
import io.micronaut.context.annotation.Requires; | ||
import io.micronaut.context.event.ApplicationEventPublisher; | ||
import org.camunda.bpm.engine.ProcessEngine; | ||
import org.camunda.bpm.engine.impl.bpmn.parser.BpmnParseListener; | ||
import org.camunda.bpm.engine.impl.cfg.ProcessEngineConfigurationImpl; | ||
import org.camunda.bpm.engine.impl.cfg.ProcessEnginePlugin; | ||
import org.camunda.bpm.engine.impl.history.handler.HistoryEventHandler; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import javax.inject.Singleton; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Plugin to map Camunda Events to Micronaut {@link io.micronaut.context.event.ApplicationEvent}'s. | ||
* | ||
* @author Silvan Brenner | ||
*/ | ||
// Implementation based on https://github.com/camunda/camunda-bpm-platform/blob/master/spring-boot-starter/starter/src/main/java/org/camunda/bpm/spring/boot/starter/event/EventPublisherPlugin.java | ||
@Singleton | ||
@Requires(condition = EventingPublisherPluginCondition.class) | ||
public class EventingPublisherPlugin implements ProcessEnginePlugin { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(EventingPublisherPlugin.class); | ||
|
||
protected final Configuration configuration; | ||
protected final ApplicationEventPublisher publisher; | ||
protected final BpmnParseListener publishDelegateParseListener; | ||
protected final HistoryEventHandler publishHistoryEventHandler; | ||
|
||
public EventingPublisherPlugin(Configuration configuration, ApplicationEventPublisher publisher, BpmnParseListener publishDelegateParseListener, HistoryEventHandler publishHistoryEventHandler) { | ||
this.configuration = configuration; | ||
this.publisher = publisher; | ||
this.publishDelegateParseListener = publishDelegateParseListener; | ||
this.publishHistoryEventHandler = publishHistoryEventHandler; | ||
} | ||
|
||
@Override | ||
public void preInit(ProcessEngineConfigurationImpl processEngineConfiguration) { | ||
if (configuration.getEventing().isTask() || configuration.getEventing().isExecution()) { | ||
log.info("Initialized Micronaut Event Engine Plugin."); | ||
if (configuration.getEventing().isTask()) { | ||
log.info("Task events will be published as Micronaut Events."); | ||
} else { | ||
log.info("Task eventing is disabled via property."); | ||
} | ||
|
||
if (configuration.getEventing().isExecution()) { | ||
log.info("Execution events will be published as Micronaut Events."); | ||
} else { | ||
log.info("Execution eventing is disabled via property."); | ||
} | ||
if (processEngineConfiguration.getCustomPostBPMNParseListeners() == null) { | ||
processEngineConfiguration.setCustomPostBPMNParseListeners(new ArrayList<>()); | ||
} | ||
processEngineConfiguration.getCustomPostBPMNParseListeners() | ||
.add(publishDelegateParseListener); | ||
} | ||
if (configuration.getEventing().isHistory()) { | ||
log.info("History events will be published as Micronaut events."); | ||
processEngineConfiguration.getCustomHistoryEventHandlers() | ||
.add(publishHistoryEventHandler); | ||
} else { | ||
log.info("History eventing is disabled via property."); | ||
} | ||
} | ||
|
||
@Override | ||
public void postInit(ProcessEngineConfigurationImpl processEngineConfiguration) { | ||
} | ||
|
||
@Override | ||
public void postProcessEngineBuild(ProcessEngine processEngine) { | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...info/novatec/micronaut/camunda/bpm/feature/eventing/EventingPublisherPluginCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2021 original authors | ||
* | ||
* 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 | ||
* | ||
* https://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 info.novatec.micronaut.camunda.bpm.feature.eventing; | ||
|
||
import info.novatec.micronaut.camunda.bpm.feature.Configuration; | ||
import io.micronaut.context.condition.Condition; | ||
import io.micronaut.context.condition.ConditionContext; | ||
|
||
/** | ||
* Condition to find out if the {@link EventingPublisherPlugin} should be enabled or not. | ||
* | ||
* @author Silvan Brenner | ||
*/ | ||
public class EventingPublisherPluginCondition implements Condition { | ||
|
||
@Override | ||
public boolean matches(ConditionContext context) { | ||
Configuration.Eventing eventing = context.getBean(Configuration.class).getEventing(); | ||
return eventing.isExecution() || eventing.isTask() || eventing.isHistory(); | ||
} | ||
} |
Oops, something went wrong.