Skip to content

Commit e4e8c42

Browse files
ivicacclaude
andcommitted
2447 Add null-safe ParametersFactory.create and simplify callers
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent fd1c436 commit e4e8c42

4 files changed

Lines changed: 48 additions & 69 deletions

File tree

server/libs/platform/platform-component/platform-component-api/src/main/java/com/bytechef/platform/component/definition/ParametersFactory.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ public static Parameters create(ComponentConnection componentConnection) {
3030
}
3131

3232
public static Parameters create(Map<String, ?> map) {
33+
if (map == null) {
34+
map = Map.of();
35+
}
36+
3337
try {
3438
return new ParametersImpl(map);
3539
} catch (Exception exception) {

server/libs/platform/platform-component/platform-component-service/src/main/java/com/bytechef/platform/component/service/ActionDefinitionServiceImpl.java

Lines changed: 29 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -277,8 +277,7 @@ public String executeWorkflowNodeDescription(
277277
componentName, componentVersion, actionName, null, null, null, null, null, null, null, null, true);
278278

279279
try {
280-
return workflowNodeDescriptionFunction.apply(
281-
ParametersFactory.create(inputParameters), actionContext);
280+
return workflowNodeDescriptionFunction.apply(ParametersFactory.create(inputParameters), actionContext);
282281
} catch (Exception e) {
283282
throw new ConfigurationException(
284283
e, inputParameters, ActionDefinitionErrorType.EXECUTE_WORKFLOW_NODE_DESCRIPTION);
@@ -317,9 +316,7 @@ private static ConvertResult convert(
317316
@Nullable ComponentConnection componentConnection) {
318317

319318
return new ConvertResult(
320-
ParametersFactory.create(inputParameters),
321-
ParametersFactory.create(
322-
componentConnection == null ? Map.of() : componentConnection.parameters()),
319+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
323320
getLookupDependsOnPathsMap(lookupDependsOnPaths));
324321
}
325322

@@ -358,13 +355,11 @@ private List<Property> doExecuteDynamicProperties(
358355

359356
try {
360357
BaseOutputDefinition.OutputResponse outputResponse = outputFunction.apply(
361-
ParametersFactory.create(inputParameters), connections,
362-
ParametersFactory.create(extensions), context);
358+
ParametersFactory.create(inputParameters), connections, ParametersFactory.create(extensions), context);
363359

364360
return toOutputResponse(outputResponse);
365361
} catch (Exception e) {
366-
throw new ConfigurationException(
367-
e, inputParameters, ActionDefinitionErrorType.EXECUTE_OUTPUT);
362+
throw new ConfigurationException(e, inputParameters, ActionDefinitionErrorType.EXECUTE_OUTPUT);
368363
}
369364
}
370365

@@ -374,8 +369,8 @@ private Object executeMultipleConnectionsPerform(
374369

375370
try {
376371
return performFunction.apply(
377-
ParametersFactory.create(inputParameters), componentConnections,
378-
ParametersFactory.create(extensions), context);
372+
ParametersFactory.create(inputParameters), componentConnections, ParametersFactory.create(extensions),
373+
context);
379374
} catch (Exception e) {
380375
throw new ExecutionException(e, inputParameters, ActionDefinitionErrorType.EXECUTE_PERFORM);
381376
}
@@ -387,8 +382,8 @@ private Object executeMultipleConnectionsStreamPerform(
387382

388383
try {
389384
return performFunction.apply(
390-
ParametersFactory.create(inputParameters), componentConnections,
391-
ParametersFactory.create(extensions), context);
385+
ParametersFactory.create(inputParameters), componentConnections, ParametersFactory.create(extensions),
386+
context);
392387
} catch (Exception e) {
393388
throw new ExecutionException(e, inputParameters, ActionDefinitionErrorType.EXECUTE_PERFORM);
394389
}
@@ -400,8 +395,8 @@ private Object executeMultipleConnectionsSseStreamResponsePerform(
400395

401396
try {
402397
return performFunction.apply(
403-
ParametersFactory.create(inputParameters), componentConnections,
404-
ParametersFactory.create(extensions), context);
398+
ParametersFactory.create(inputParameters), componentConnections, ParametersFactory.create(extensions),
399+
context);
405400
} catch (Exception e) {
406401
throw new ExecutionException(e, inputParameters, ActionDefinitionErrorType.EXECUTE_PERFORM);
407402
}
@@ -441,9 +436,7 @@ private List<Option> doExecuteOptions(
441436

442437
try {
443438
BaseOutputDefinition.OutputResponse outputResponse = outputFunction.apply(
444-
ParametersFactory.create(inputParameters),
445-
ParametersFactory.create(
446-
componentConnection == null ? Map.of() : componentConnection.getConnectionParameters()),
439+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
447440
context);
448441

449442
return toOutputResponse(outputResponse);
@@ -471,32 +464,31 @@ private Object executeResumePerform(
471464
actionDefinition.getBeforeTimeoutResume();
472465

473466
if (beforeTimeoutResumeOptional.isPresent()) {
474-
Optional<Map<String, ?>> additionalParameters = beforeTimeoutResumeOptional.get()
475-
.apply(
476-
ParametersFactory.create(inputParameters), ParametersFactory.create(continueParameters),
477-
context);
467+
BeforeTimeoutResumeFunction beforeTimeoutResumeFunction = beforeTimeoutResumeOptional.get();
468+
469+
Optional<Map<String, ?>> additionalParameters = beforeTimeoutResumeFunction.apply(
470+
ParametersFactory.create(inputParameters), ParametersFactory.create(continueParameters),
471+
context);
478472

479473
additionalParameters.ifPresent(mergedInputParameters::putAll);
480474
}
481475
} else {
482476
Optional<BeforeResumeFunction> beforeResumeOptional = actionDefinition.getBeforeResume();
483477

484478
if (beforeResumeOptional.isPresent()) {
485-
Optional<Map<String, ?>> additionalParameters = beforeResumeOptional.get()
486-
.apply(
487-
null, ParametersFactory.create(mergedInputParameters),
488-
ParametersFactory.create(continueParameters), context);
479+
BeforeResumeFunction beforeResumeFunction = beforeResumeOptional.get();
480+
481+
Optional<Map<String, ?>> additionalParameters = beforeResumeFunction.apply(
482+
null, ParametersFactory.create(mergedInputParameters),
483+
ParametersFactory.create(continueParameters), context);
489484

490485
additionalParameters.ifPresent(mergedInputParameters::putAll);
491486
}
492487
}
493488

494489
return resumePerformFunction.apply(
495-
ParametersFactory.create(mergedInputParameters),
496-
componentConnection == null
497-
? null : ParametersFactory.create(componentConnection.getConnectionParameters()),
498-
ParametersFactory.create(continueParameters),
499-
ParametersFactory.create(resumeData == null ? Map.of() : resumeData),
490+
ParametersFactory.create(mergedInputParameters), ParametersFactory.create(componentConnection),
491+
ParametersFactory.create(continueParameters), ParametersFactory.create(resumeData),
500492
context);
501493
} catch (Exception exception) {
502494
if (exception instanceof ProviderException) {
@@ -522,11 +514,11 @@ private Object checkSuspend(
522514

523515
if (beforeSuspendOptional.isPresent()) {
524516
try {
525-
beforeSuspendOptional.get()
526-
.apply(
527-
resumeUrl, suspend.expiresAt(),
528-
ParametersFactory.create(suspend.continueParameters()),
529-
actionContext);
517+
BeforeSuspendConsumer beforeSuspendConsumer = beforeSuspendOptional.get();
518+
519+
beforeSuspendConsumer.apply(
520+
resumeUrl, suspend.expiresAt(), ParametersFactory.create(suspend.continueParameters()),
521+
actionContext);
530522
} catch (Exception exception) {
531523
throw new ExecutionException(
532524
exception, Map.of(), ActionDefinitionErrorType.EXECUTE_PERFORM);
@@ -554,9 +546,7 @@ private Object executeSingleConnectionPerform(
554546

555547
try {
556548
return performFunction.apply(
557-
ParametersFactory.create(inputParameters),
558-
componentConnection == null
559-
? null : ParametersFactory.create(componentConnection.getConnectionParameters()),
549+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
560550
context);
561551
} catch (Exception e) {
562552
if (e instanceof ProviderException) {

server/libs/platform/platform-component/platform-component-service/src/main/java/com/bytechef/platform/component/service/ClusterElementDefinitionServiceImpl.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -150,8 +150,7 @@ public List<Option> executeOptions(
150150
componentName, componentVersion, clusterElementName, componentConnection, true);
151151

152152
Parameters inputParams = ParametersFactory.create(inputParameters);
153-
Parameters connectionParams = ParametersFactory.create(
154-
componentConnection == null ? Map.of() : componentConnection.parameters());
153+
Parameters connectionParams = ParametersFactory.create(componentConnection);
155154

156155
try {
157156
BaseOutputDefinition.OutputResponse outputResponse = outputFunction.apply(
@@ -350,8 +349,7 @@ private static ConvertResult convert(
350349
@Nullable ComponentConnection componentConnection) {
351350

352351
return new ConvertResult(
353-
ParametersFactory.create(inputParameters),
354-
ParametersFactory.create(componentConnection == null ? Map.of() : componentConnection.parameters()),
352+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
355353
getLookupDependsOnPathsMap(lookupDependsOnPaths));
356354
}
357355

@@ -441,8 +439,7 @@ private Object doExecuteTool(
441439
componentName, componentVersion, clusterElementName);
442440

443441
Parameters inputParameters = ParametersFactory.create(inputParameterMap);
444-
Parameters connectionParameters = ParametersFactory.create(
445-
componentConnection == null ? Map.of() : componentConnection.getParameters());
442+
Parameters connectionParameters = ParametersFactory.create(componentConnection);
446443

447444
try {
448445
if (clusterElement instanceof ToolCallbackProviderFunction toolCallbackProviderFunction) {

server/libs/platform/platform-component/platform-component-service/src/main/java/com/bytechef/platform/component/service/TriggerDefinitionServiceImpl.java

Lines changed: 12 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
import java.util.Collections;
7575
import java.util.List;
7676
import java.util.Map;
77+
import java.util.Objects;
7778
import java.util.Optional;
7879
import org.jspecify.annotations.Nullable;
7980
import org.springframework.context.ApplicationEventPublisher;
@@ -173,9 +174,7 @@ public void executeListenerEnable(
173174

174175
try {
175176
listenerEnableConsumer.accept(
176-
ParametersFactory.create(inputParameters),
177-
ParametersFactory
178-
.create(componentConnection == null ? Map.of() : componentConnection.parameters()),
177+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
179178
workflowExecutionId,
180179
output -> eventPublisher.publishEvent(
181180
new TriggerListenerEvent(
@@ -412,9 +411,7 @@ private List<Option> doExecuteOptions(
412411
.map(outputFunction -> {
413412
try {
414413
BaseOutputDefinition.OutputResponse outputResponse = outputFunction.apply(
415-
ParametersFactory.create(inputParameters),
416-
ParametersFactory.create(
417-
componentConnection == null ? Map.of() : componentConnection.getConnectionParameters()),
414+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
418415
context);
419416

420417
if (outputResponse == null) {
@@ -442,9 +439,7 @@ private static TriggerOutput executePollingTrigger(
442439

443440
PollOutput pollOutput;
444441

445-
Parameters connectionParameters =
446-
ParametersFactory.create(
447-
componentConnection == null ? Map.of() : componentConnection.getConnectionParameters());
442+
Parameters connectionParameters = ParametersFactory.create(componentConnection);
448443

449444
try {
450445
pollOutput = pollFunction.apply(
@@ -496,7 +491,8 @@ private TriggerOutput doExecuteTrigger(
496491

497492
if (TriggerType.DYNAMIC_WEBHOOK == triggerType || TriggerType.STATIC_WEBHOOK == triggerType) {
498493
WebhookValidateResponse response = executeWebhookValidate(
499-
triggerDefinition, ParametersFactory.create(inputParameters), webhookRequest, context);
494+
triggerDefinition, ParametersFactory.create(inputParameters), Objects.requireNonNull(webhookRequest),
495+
context);
500496

501497
if (response.status() != HttpStatus.OK.getValue()) {
502498
throw new IllegalStateException("Invalid trigger signature.");
@@ -537,9 +533,7 @@ private void doExecuteWebhookDisable(
537533

538534
try {
539535
webhookDisableConsumer.accept(
540-
ParametersFactory.create(inputParameters),
541-
ParametersFactory
542-
.create(componentConnection == null ? Map.of() : componentConnection.parameters()),
536+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
543537
ParametersFactory.create(outputParameters), workflowExecutionId, context);
544538
} catch (Exception e) {
545539
if (e instanceof ProviderException pe) {
@@ -565,9 +559,7 @@ private void doExecuteWebhookDisable(
565559

566560
try {
567561
return webhookEnableFunction.apply(
568-
ParametersFactory.create(inputParameters),
569-
ParametersFactory.create(
570-
componentConnection == null ? Map.of() : componentConnection.parameters()),
562+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
571563
webhookUrl, workflowExecutionId, context);
572564
} catch (Exception e) {
573565
if (e instanceof ProviderException pe) {
@@ -624,11 +616,9 @@ private static TriggerOutput executeWebhookTrigger(
624616

625617
try {
626618
webhookOutput = webhookRequestFunction.apply(
627-
ParametersFactory.create(inputParameters),
628-
ParametersFactory
629-
.create(componentConnection == null ? Map.of() : componentConnection.parameters()),
630-
new HttpHeadersImpl(webhookRequest.headers()),
631-
new HttpParametersImpl(webhookRequest.parameters()), webhookRequest.body(), webhookRequest.method(),
619+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
620+
new HttpHeadersImpl(webhookRequest.headers()), new HttpParametersImpl(webhookRequest.parameters()),
621+
webhookRequest.body(), webhookRequest.method(),
632622
ParametersFactory.create(webhookEnabledOutputParameters), triggerContext);
633623
} catch (Exception e) {
634624
if (e instanceof ProviderException pe) {
@@ -768,9 +758,7 @@ private static WrapResult wrap(
768758
@Nullable ComponentConnection componentConnection) {
769759

770760
return new WrapResult(
771-
ParametersFactory.create(inputParameters),
772-
ParametersFactory.create(
773-
componentConnection == null ? Map.of() : componentConnection.parameters()),
761+
ParametersFactory.create(inputParameters), ParametersFactory.create(componentConnection),
774762
getLookupDependsOnPathsMap(lookupDependsOnPaths));
775763
}
776764

0 commit comments

Comments
 (0)