Skip to content

Instantly share code, notes, and snippets.

@berndruecker
Last active October 19, 2022 18:22
Show Gist options
  • Save berndruecker/1cdbf8db238dff704264aa7e25f75ae3 to your computer and use it in GitHub Desktop.
Save berndruecker/1cdbf8db238dff704264aa7e25f75ae3 to your computer and use it in GitHub Desktop.
@Scheduled(fixedDelay = 5000)
public void scheduleImport() throws OperateException {
List<ProcessDefinition> processDefinitions = camundaOperateClient
.searchProcessDefinitions();
for (ProcessDefinition processDefinition: processDefinitions) {
if (!registry.processDefinitionChecked(processDefinition.getKey())) {
processBpmnXml(
processDefinition,
camundaOperateClient.getProcessDefinitionXml(processDefinition.getKey()));
registry.markProcessDefinitionChecked(processDefinition.getKey());
}
}
}
private void processBpmnXml(ProcessDefinition processDefinition, String resource) {
final BpmnModelInstance bpmnModelInstance = Bpmn.readModelFromStream(
new ByteArrayInputStream(resource.getBytes()));
bpmnModelInstance.getDefinitions()
.getChildElementsByType(Process.class)
.stream().flatMap(
process -> process.getChildElementsByType(StartEvent.class).stream()
)
.map(startEvent -> startEvent.getSingleExtensionElement(ZeebeProperties.class))
.filter(Objects::nonNull)
.forEach(zeebeProperties -> processZeebeProperties(processDefinition, zeebeProperties));
// TODO: Also process intermediate catching message events and Receive Tasks
}
private void processZeebeProperties(ProcessDefinition processDefinition, ZeebeProperties zeebeProperties) {
InboundConnectorProperties properties = new InboundConnectorProperties(
processDefinition.getBpmnProcessId(),
processDefinition.getVersion().intValue(),
processDefinition.getKey(),
zeebeProperties.getProperties().stream()
.collect(Collectors.toMap(ZeebeProperty::getName, ZeebeProperty::getValue)));
if (InboundConnectorProperties.TYPE_WEBHOOK.equals(properties.getType())) {
registry.registerWebhookConnector(properties);
}
// ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment