Skip to content

Commit bdfcdea

Browse files
committed
Final attempt:
1) First try to find the activity by type name 2) Even if a descriptor is found by its type name, there might be multiple versions of a workflow-as-activity, hence; if the workflowDefinitionVersionId is specified, then this can override the initially found activity descriptor by type name. 3) Lastly, only when no activity descriptor is found by type name AND the activity JSON contains the property "workflowDeftinitionId", then we can search by workflowDefinitionId
1 parent 5f2d4ad commit bdfcdea

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

src/modules/Elsa.Workflows.Core/Serialization/Converters/ActivityJsonConverter.cs

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -81,34 +81,41 @@ private string GetActivityDetails(JsonElement activityRoot, out int activityType
8181
activityDescriptor = null;
8282
activityTypeVersion = 0;
8383

84-
// First try and find the activity by its workflow definition version id. This is a special case when working with the WorkflowDefinitionActivity.
85-
if (activityRoot.TryGetProperty("workflowDefinitionVersionId", out var workflowDefinitionVersionIdElement))
86-
{
87-
activityDescriptor = FindActivityDescriptorByCustomProperty("WorkflowDefinitionVersionId", workflowDefinitionVersionIdElement);
88-
activityTypeVersion = activityDescriptor?.Version ?? 0;
89-
}
90-
// Or, when working with the WorkflowDefinitionActivity, we should try and find the activity by its workflow definition id.
91-
else if (activityRoot.TryGetProperty("workflowDefinitionId", out var workflowDefinitionIdElement)
92-
&& workflowDefinitionIdElement.ValueKind == JsonValueKind.String)
93-
{
94-
activityDescriptor = FindActivityDescriptorByCustomProperty("WorkflowDefinitionId", workflowDefinitionIdElement);
95-
activityTypeVersion = activityDescriptor?.Version ?? 0;
96-
}
97-
84+
// First we check whether the activity type name is a 'well-known' activity; not a workflow-as-activity
85+
9886
// If the activity type version is specified, use that to find the activity descriptor.
99-
if (activityDescriptor == null && activityRoot.TryGetProperty("version", out var activityVersionElement))
87+
if (activityRoot.TryGetProperty("version", out var activityVersionElement))
10088
{
10189
activityTypeVersion = activityVersionElement.GetInt32();
10290
activityDescriptor = activityRegistry.Find(activityTypeName, activityTypeVersion);
10391
}
10492

105-
// If the activity type version is not specified, use the latest version of the activity descriptor.
106-
else if (activityDescriptor == null)
93+
// If a version is not specified, or activity with specified version is not found: use the latest version of the activity descriptor.
94+
if (activityDescriptor == null)
10795
{
10896
activityDescriptor = activityRegistry.Find(activityTypeName);
10997
activityTypeVersion = activityDescriptor?.Version ?? 0;
11098
}
11199

100+
// This is a special case when working with the WorkflowDefinitionActivity: workflowDefinitionVersionId should be used to find the workflow-as-activity.
101+
if (activityRoot.TryGetProperty("workflowDefinitionVersionId", out var workflowDefinitionVersionIdElement))
102+
{
103+
var activityDescriptorOverride = FindActivityDescriptorByCustomProperty("WorkflowDefinitionVersionId", workflowDefinitionVersionIdElement);
104+
if (activityDescriptorOverride is not null)
105+
{
106+
activityDescriptor = FindActivityDescriptorByCustomProperty("WorkflowDefinitionVersionId", workflowDefinitionVersionIdElement);
107+
activityTypeVersion = activityDescriptor?.Version ?? 0;
108+
}
109+
}
110+
// This is also a special case when working with the WorkflowDefinitionActivity: if no 'well-known' activity could be found, it might be a workflow-as-activity with a workflowDefinitionId
111+
else if (activityDescriptor is null
112+
&& activityRoot.TryGetProperty("workflowDefinitionId", out var workflowDefinitionIdElement)
113+
&& workflowDefinitionIdElement.ValueKind == JsonValueKind.String)
114+
{
115+
activityDescriptor = FindActivityDescriptorByCustomProperty("WorkflowDefinitionId", workflowDefinitionIdElement);
116+
activityTypeVersion = activityDescriptor?.Version ?? 0;
117+
}
118+
112119
return activityTypeName;
113120
}
114121

0 commit comments

Comments
 (0)