Skip to content

Commit

Permalink
Fix default-adapter handling
Browse files Browse the repository at this point in the history
  • Loading branch information
stephanpelikan committed Mar 18, 2024
1 parent 6719e82 commit 7e8fcfc
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class AdapterAwareProcessService<DE> implements ProcessService<DE> {

private final Map<String, ProcessServiceImplementation<DE>> processServicesByAdapter;

private final List<String> wiredAdapterIds = new LinkedList<>();
private final Set<String> wiredAdapterIds = new HashSet<>();

private String workflowModuleId;

Expand Down Expand Up @@ -177,7 +177,7 @@ public void wire(
wiredAdapterIds.add(adapterId);
if (wiredAdapterIds.size() == processServicesByAdapter.size()) { // all adapters wired for this service
properties.validatePropertiesFor(
wiredAdapterIds,
new LinkedList<>(wiredAdapterIds),
workflowModuleId,
bpmnProcessId);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ public void validateConfiguration() {
.stream()
.map(AdapterConfigurationBase::getAdapterId)
.toList();
if (properties.getDefaultAdapter().isEmpty()
&& (adapterIds.size() == 1)) {
properties.setDefaultAdapter(adapterIds);
}

properties.validateProperties(adapterIds, workflowModuleIds);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -185,48 +185,42 @@ public void validatePropertiesFor(
final String workflowModuleId,
final String bpmnProcessId) {

// default-adapter
if (adapterIds.size() == 1) {
setDefaultAdapter(adapterIds);
} else {
final var defaultAdapters = getDefaultAdapterFor(workflowModuleId, bpmnProcessId);
if (defaultAdapters.isEmpty()) {
throw new RuntimeException(
"More than one VanillaBP adapter was found in classpath, but no default adapter is configured at\n "
+ PREFIX
+ ".workflow-modules."
+ workflowModuleId
+ ".workflows."
+ bpmnProcessId
+ ".default-adapter or \n "
+ PREFIX
+ ".workflow-modules."
+ workflowModuleId
+ ".default-adapter or \n "
+ PREFIX
+ ".default-adapter\nAvailable adapters are '"
+ String.join("', '", adapterIds)
+ "'.");
}

final var listOfAdapters = String.join("', '", adapterIds);
final var missingAdapters = defaultAdapters
.stream()
.filter(defaultAdapter -> !adapterIds.contains(defaultAdapter))
.collect(Collectors.joining("', '"));
if (!missingAdapters.isEmpty()) {
throw new RuntimeException(
"Property 'default-adapter' of workflow-module '"
+ workflowModuleId
+ "' and bpmn-process-id '"
+ bpmnProcessId
+ "' contains adapters not available in classpath:\n' "
+ missingAdapters
+ "'!\nAvailable adapters are: '"
+ listOfAdapters
+ "'.");
}
final var defaultAdapters = getDefaultAdapterFor(workflowModuleId, bpmnProcessId);
if (defaultAdapters.isEmpty()) {
throw new RuntimeException(
"More than one VanillaBP adapter was found in classpath, but no default adapter is configured at\n "
+ PREFIX
+ ".workflow-modules."
+ workflowModuleId
+ ".workflows."
+ bpmnProcessId
+ ".default-adapter or \n "
+ PREFIX
+ ".workflow-modules."
+ workflowModuleId
+ ".default-adapter or \n "
+ PREFIX
+ ".default-adapter\nAvailable adapters are '"
+ String.join("', '", adapterIds)
+ "'.");
}

final var listOfAdapters = String.join("', '", adapterIds);
final var missingAdapters = defaultAdapters
.stream()
.filter(defaultAdapter -> !adapterIds.contains(defaultAdapter))
.collect(Collectors.joining("', '"));
if (!missingAdapters.isEmpty()) {
throw new RuntimeException(
"Property 'default-adapter' of workflow-module '"
+ workflowModuleId
+ "' and bpmn-process-id '"
+ bpmnProcessId
+ "' contains adapters not available in classpath:\n' "
+ missingAdapters
+ "'!\nAvailable adapters are: '"
+ listOfAdapters
+ "'.");
}

}
Expand Down

0 comments on commit 7e8fcfc

Please sign in to comment.