Skip to content

Commit

Permalink
Merge pull request #803 from Project-MONAI/AC-2216
Browse files Browse the repository at this point in the history
AC-2216 take2 workflow name
  • Loading branch information
woodheadio authored May 15, 2023
2 parents 2a0c339 + 0259b2a commit 4e15f84
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/WorkflowManager/Common/Interfaces/IWorkflowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public interface IWorkflowService : IPaginatedApi<WorkflowRevision>
/// </summary>
/// <param name="workflow">Workflow to Update.</param>
/// <param name="id">Id of the workflow to Update.</param>
Task<string?> UpdateAsync(Workflow workflow, string id);
Task<string?> UpdateAsync(Workflow workflow, string id, bool isUpdateToWorkflowName = false);

/// <summary>
/// Soft deletes a given workflow and all revisions
Expand Down
15 changes: 14 additions & 1 deletion src/WorkflowManager/Common/Services/WorkflowService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,17 @@ public async Task<string> CreateAsync(Workflow workflow)
{
Guard.Against.Null(workflow);

foreach (var task in workflow.Tasks)
{
task.Args["workflow_name"] = workflow.Name;
}

var id = await _workflowRepository.CreateAsync(workflow);
_logger.WorkflowCreated(id, workflow.Name);
return id;
}

public async Task<string?> UpdateAsync(Workflow workflow, string id)
public async Task<string?> UpdateAsync(Workflow workflow, string id, bool isUpdateToWorkflowName = false)
{
Guard.Against.Null(workflow);
Guard.Against.NullOrWhiteSpace(id);
Expand All @@ -71,6 +76,14 @@ public async Task<string> CreateAsync(Workflow workflow)
return null;
}

if (isUpdateToWorkflowName)
{
foreach (var task in workflow.Tasks)
{
task.Args["workflow_name"] = workflow.Name;
}
}

var result = await _workflowRepository.UpdateAsync(workflow, existingWorkflow);
_logger.WorkflowUpdated(id, workflow.Name);
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@ public async Task<IActionResult> UpdateAsync([FromBody] WorkflowUpdateRequest re

try
{
var workflowId = await _workflowService.UpdateAsync(workflow, id);
var workflowId = await _workflowService.UpdateAsync(workflow, id, workflow.Name != originalName);

if (workflowId == null)
{
Expand Down
14 changes: 13 additions & 1 deletion tests/UnitTests/Common.Tests/Services/WorkflowServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,18 @@ public async Task WorkflowService_CreateAsync_With_Empty()
await Assert.ThrowsAsync<ArgumentNullException>(() => WorkflowService.CreateAsync(null));
}

[Fact]
public async Task WorkflowService_CreateAsync_With_ValidReturn()
{
var expectedResult = "1";
_workflowRepository.Setup(w => w.CreateAsync(It.IsAny<Workflow>())).ReturnsAsync(expectedResult);
var tasks = new TaskObject[] { new TaskObject() };
var result = await WorkflowService.CreateAsync(new Workflow() { Name = "workflow1", Tasks = tasks });

Assert.Equal(expectedResult, result);
}


[Fact]
public async Task WorkflowService_WorkflowExists_ReturnsWorkflowId()
{
Expand Down Expand Up @@ -102,7 +114,7 @@ public async Task WorkflowService_WorkflowExists_ReturnsWorkflowId()
_workflowRepository.Setup(w => w.GetByWorkflowIdAsync(workflowRevision.WorkflowId)).ReturnsAsync(workflowRevision);
_workflowRepository.Setup(w => w.UpdateAsync(It.IsAny<Workflow>(), workflowRevision)).ReturnsAsync(workflowRevision.WorkflowId);

var result = await WorkflowService.UpdateAsync(new Workflow(), workflowRevision.WorkflowId);
var result = await WorkflowService.UpdateAsync(new Workflow(), workflowRevision.WorkflowId, true);

Assert.Equal(workflowRevision.WorkflowId, result);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -899,7 +899,7 @@ public async Task UpdateAsync_WorkflowsExist_ReturnsWorkflowId()
request.Workflow = newWorkflow;
request.OriginalWorkflowName = newWorkflow.Name + "1";

_workflowService.Setup(w => w.UpdateAsync(newWorkflow, workflowRevision.WorkflowId)).ReturnsAsync(workflowRevision.WorkflowId);
_workflowService.Setup(w => w.UpdateAsync(newWorkflow, workflowRevision.WorkflowId, It.IsAny<bool>())).ReturnsAsync(workflowRevision.WorkflowId);

var result = await WorkflowsController.UpdateAsync(request, workflowRevision.WorkflowId);

Expand Down

0 comments on commit 4e15f84

Please sign in to comment.