Skip to content

Commit

Permalink
delete taskName change endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkoSekulic committed Feb 5, 2024
1 parent 1bd7b07 commit db7fc44
Show file tree
Hide file tree
Showing 5 changed files with 1 addition and 95 deletions.
25 changes: 0 additions & 25 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -128,30 +128,5 @@ await _processModelingService.SaveProcessDefinitionFromTemplateAsync(editingCont
Stream processDefinitionStream = _processModelingService.GetProcessDefinitionStream(editingContext);
return new FileStreamResult(processDefinitionStream, MediaTypeNames.Text.Plain);
}

[HttpPut("tasks/{taskId}/{taskName}")]
public async Task<ActionResult> UpdateProcessTaskName(string org, string repo, string taskId, string taskName,
CancellationToken cancellationToken)
{
Guard.AssertArgumentNotNull(taskId, nameof(taskId));
Guard.AssertArgumentNotNull(taskName, nameof(taskName));
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);
try
{
Stream updatedProcessDefinitionStream =
await _processModelingService.UpdateProcessTaskNameAsync(editingContext, taskId, taskName,
cancellationToken);
return new FileStreamResult(updatedProcessDefinitionStream, MediaTypeNames.Text.Plain);
}
catch (InvalidOperationException)
{
return BadRequest("Could not deserialize process definition.");
}
catch (ArgumentException)
{
return BadRequest("Could not find task with given id.");
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,37 +56,6 @@ public Stream GetProcessDefinitionStream(AltinnRepoEditingContext altinnRepoEdit
return altinnAppGitRepository.GetProcessDefinitionFile();
}

public async Task<Stream> UpdateProcessTaskNameAsync(AltinnRepoEditingContext altinnRepoEditingContext, string taskId, string taskName, CancellationToken cancellationToken = default)
{
cancellationToken.ThrowIfCancellationRequested();
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(altinnRepoEditingContext.Org, altinnRepoEditingContext.Repo, altinnRepoEditingContext.Developer);
XmlSerializer serializer = new(typeof(Definitions));
Definitions? definitions;
using (Stream processDefinitionStream = GetProcessDefinitionStream(altinnRepoEditingContext))
{
definitions = (Definitions?)serializer.Deserialize(processDefinitionStream);
}

if (definitions == null)
{
throw new InvalidOperationException("Could not deserialize process definition.");
}

ProcessTask? processTask = (definitions.Process.Tasks?.FirstOrDefault(t => t.Id == taskId)) ?? throw new ArgumentException($"Could not find task with id {taskId}.");
processTask.Name = taskName;

Stream processStream = new MemoryStream();
serializer.Serialize(processStream, definitions);

// Reset stream position to beginning after serialization
processStream.Seek(0, SeekOrigin.Begin);
await altinnAppGitRepository.SaveProcessDefinitionFileAsync(processStream, cancellationToken);

// Reset stream position to beginning after saving
processStream.Seek(0, SeekOrigin.Begin);
return processStream;
}

private IEnumerable<string> EnumerateTemplateResources(SemanticVersion version)
{
return typeof(ProcessModelingService).Assembly.GetManifestResourceNames()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,5 @@ public interface IProcessModelingService
/// <param name="altinnRepoEditingContext">An <see cref="AltinnRepoEditingContext"/>.</param>
/// <returns>A <see cref="Stream"/> of a process definition file.</returns>
Stream GetProcessDefinitionStream(AltinnRepoEditingContext altinnRepoEditingContext);

/// <summary>
/// Updates the name of a task in the process definition file.
/// </summary>
/// <param name="altinnRepoEditingContext">n <see cref="AltinnRepoEditingContext"/>.</param>
/// <param name="taskId">The ID of the task to update</param>
/// <param name="taskName">The name to set for the task</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is cancelled.</param>
/// <returns></returns>
Task<Stream> UpdateProcessTaskNameAsync(AltinnRepoEditingContext altinnRepoEditingContext, string taskId, string taskName, CancellationToken cancellationToken = default);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public async Task UpsertProcessDefinition_ShouldReturnOk(string org, string app,

string url = VersionPrefix(org, targetRepository);

var form = new MultipartFormDataContent();
using var form = new MultipartFormDataContent();
string metadataString = JsonSerializer.Serialize(metadata,
new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase });
form.Add(new StreamContent(fileStream), "content", "process.bpmn");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,34 +37,6 @@ public void GetProcessDefinitionTemplates_GivenVersion_ReturnsListOfTemplates(st
}
}

[Theory]
[InlineData("ttd", "app-with-process", "testUser", "Task_1", "NewTaskName")]
public async void UpdateProcessTaskNameAsync_GivenTaskIdAndTaskName_UpdatesTaskName(string org, string repo, string developer, string taskId, string newTaskName)
{
// Arrange
string targetRepository = TestDataHelper.GenerateTestRepoName();
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, targetRepository, developer);
await TestDataHelper.CopyRepositoryForTest(org, repo, developer, targetRepository);

try
{
var altinnGitRepositoryFactory = new AltinnGitRepositoryFactory(TestDataHelper.GetTestDataRepositoriesRootDirectory());
IProcessModelingService processModelingService = new ProcessModelingService(altinnGitRepositoryFactory);

// Act
using Stream result = await processModelingService.UpdateProcessTaskNameAsync(editingContext, taskId, newTaskName);
XmlSerializer serializer = new(typeof(Definitions));
Definitions definitions = (Definitions)serializer.Deserialize(result);

// Assert
definitions.Process.Tasks.First(t => t.Id == taskId).Name.Should().Be(newTaskName);
}
finally
{
TestDataHelper.DeleteAppRepository(org, targetRepository, developer);
}
}

public static IEnumerable<object[]> TemplatesTestData => new List<object[]>
{
new object[]
Expand Down

0 comments on commit db7fc44

Please sign in to comment.