Skip to content

Commit

Permalink
12735 update endpoint that sets datatype for process task to accept a…
Browse files Browse the repository at this point in the history
…rray of data types (#12865)

* Change data type in body to be list

* Add tests

* Fix PR comments
  • Loading branch information
standeren authored Jun 18, 2024
1 parent e938d0d commit 396c405
Show file tree
Hide file tree
Showing 49 changed files with 486 additions and 341 deletions.
13 changes: 6 additions & 7 deletions backend/src/Designer/Controllers/ProcessModelingController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -106,19 +106,18 @@ await _mediator.Publish(new ProcessTaskIdChangedEvent
return Accepted();
}

[HttpPut("data-type")]
public async Task<IActionResult> ProcessDataTypeChangedNotify(string org, string repo, [FromBody] DataTypeChange dataTypeChange, CancellationToken cancellationToken)
[HttpPut("data-types")]
public async Task<IActionResult> ProcessDataTypesChangedNotify(string org, string repo, [FromBody] DataTypesChange dataTypesChange, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, repo, developer);

if (dataTypeChange is not null)
if (dataTypesChange is not null)
{

await _mediator.Publish(new ProcessDataTypeChangedEvent
await _mediator.Publish(new ProcessDataTypesChangedEvent
{
NewDataType = dataTypeChange.NewDataType,
ConnectedTaskId = dataTypeChange.ConnectedTaskId,
NewDataTypes = dataTypesChange.NewDataTypes,
ConnectedTaskId = dataTypesChange.ConnectedTaskId,
EditingContext = editingContext
}, cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Platform.Storage.Interface.Models;
Expand All @@ -8,19 +9,19 @@

namespace Altinn.Studio.Designer.EventHandlers.ProcessDataTypeChanged;

public class ProcessDataTypeChangedApplicationMetadataHandler : INotificationHandler<ProcessDataTypeChangedEvent>
public class ProcessDataTypesChangedApplicationMetadataHandler : INotificationHandler<ProcessDataTypesChangedEvent>
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor;

public ProcessDataTypeChangedApplicationMetadataHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory,
public ProcessDataTypesChangedApplicationMetadataHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory,
IFileSyncHandlerExecutor fileSyncHandlerExecutor)
{
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
_fileSyncHandlerExecutor = fileSyncHandlerExecutor;
}

public async Task Handle(ProcessDataTypeChangedEvent notification, CancellationToken cancellationToken)
public async Task Handle(ProcessDataTypesChangedEvent notification, CancellationToken cancellationToken)
{
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(
notification.EditingContext,
Expand All @@ -34,7 +35,7 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(

var applicationMetadata = await repository.GetApplicationMetadata(cancellationToken);

if (notification.ConnectedTaskId != Constants.General.CustomReceiptId && TryChangeDataType(applicationMetadata, notification.NewDataType, notification.ConnectedTaskId))
if (notification.ConnectedTaskId != Constants.General.CustomReceiptId && TryChangeDataTypes(applicationMetadata, notification.NewDataTypes, notification.ConnectedTaskId))
{
await repository.SaveApplicationMetadata(applicationMetadata);
}
Expand All @@ -46,18 +47,18 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(
/// If there are changes, the application metadata is updated and the method returns true.
/// Otherwise, the method returns false.
/// </summary>
private static bool TryChangeDataType(Application applicationMetadata, string newDataType, string connectedTaskId)
private static bool TryChangeDataTypes(Application applicationMetadata, List<string> newDataTypes, string connectedTaskId)
{
bool hasChanges = false;


var dataTypeToDisconnect = applicationMetadata.DataTypes.Find(dataType => dataType.TaskId == connectedTaskId);
if (dataTypeToDisconnect is not null)
var dataTypesToDisconnect = applicationMetadata.DataTypes.FindAll(dataType => dataType.TaskId == connectedTaskId);
foreach (var dataTypeToDisconnect in dataTypesToDisconnect)
{
dataTypeToDisconnect.TaskId = null;
hasChanges = true;
}
if (!string.IsNullOrEmpty(newDataType))
foreach (string newDataType in newDataTypes)
{
var dataTypeToUpdate = applicationMetadata.DataTypes.Find(dataType => dataType.Id == newDataType);
// Only update taskId on appMetaData dataType if the new connected dataType for the layout set exists in appMetaData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using Altinn.Studio.Designer.Events;
Expand All @@ -8,19 +9,19 @@

namespace Altinn.Studio.Designer.EventHandlers.ProcessDataTypeChanged;

public class ProcessDataTypeChangedLayoutSetsHandler : INotificationHandler<ProcessDataTypeChangedEvent>
public class ProcessDataTypesChangedLayoutSetsHandler : INotificationHandler<ProcessDataTypesChangedEvent>
{
private readonly IAltinnGitRepositoryFactory _altinnGitRepositoryFactory;
private readonly IFileSyncHandlerExecutor _fileSyncHandlerExecutor;

public ProcessDataTypeChangedLayoutSetsHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory,
public ProcessDataTypesChangedLayoutSetsHandler(IAltinnGitRepositoryFactory altinnGitRepositoryFactory,
IFileSyncHandlerExecutor fileSyncHandlerExecutor)
{
_altinnGitRepositoryFactory = altinnGitRepositoryFactory;
_fileSyncHandlerExecutor = fileSyncHandlerExecutor;
}

public async Task Handle(ProcessDataTypeChangedEvent notification, CancellationToken cancellationToken)
public async Task Handle(ProcessDataTypesChangedEvent notification, CancellationToken cancellationToken)
{
await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(
notification.EditingContext,
Expand All @@ -39,20 +40,20 @@ await _fileSyncHandlerExecutor.ExecuteWithExceptionHandling(
}

var layoutSets = await repository.GetLayoutSetsFile(cancellationToken);
if (TryChangeDataType(layoutSets, notification.NewDataType, notification.ConnectedTaskId))
if (TryChangeDataTypes(layoutSets, notification.NewDataTypes, notification.ConnectedTaskId))
{
await repository.SaveLayoutSets(layoutSets);
}
});
}

private static bool TryChangeDataType(LayoutSets layoutSets, string newDataType, string connectedTaskId)
private static bool TryChangeDataTypes(LayoutSets layoutSets, List<string> newDataTypes, string connectedTaskId)
{
bool hasChanges = false;
var layoutSet = layoutSets.Sets?.Find(layoutSet => layoutSet.Tasks[0] == connectedTaskId);
if (layoutSet is not null)
if (layoutSet is not null && !newDataTypes.Contains(layoutSet.DataType))
{
layoutSet.DataType = newDataType;
layoutSet.DataType = newDataTypes[0];
hasChanges = true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Collections.Generic;
using Altinn.Studio.Designer.Models;
using MediatR;

namespace Altinn.Studio.Designer.Events;

public class ProcessDataTypeChangedEvent : INotification
public class ProcessDataTypesChangedEvent : INotification
{
public string NewDataType { get; set; }
public List<string> NewDataTypes { get; set; }
public string ConnectedTaskId { get; set; }
public AltinnRepoEditingContext EditingContext { get; set; }
}
6 changes: 4 additions & 2 deletions backend/src/Designer/Models/Dto/DataTypeChange.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Collections.Generic;

namespace Altinn.Studio.Designer.Models.Dto;

public class DataTypeChange
public class DataTypesChange
{
public string NewDataType { get; set; }
public List<string> NewDataTypes { get; set; }
public string ConnectedTaskId { get; set; }
}

This file was deleted.

Loading

0 comments on commit 396c405

Please sign in to comment.