Skip to content

Commit

Permalink
backend-layoutset-tasktype-endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondyr committed Nov 27, 2024
1 parent 4a7d1e2 commit 1ba29e7
Show file tree
Hide file tree
Showing 7 changed files with 105 additions and 0 deletions.
11 changes: 11 additions & 0 deletions backend/src/Designer/Controllers/AppDevelopmentController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,17 @@ public async Task<IActionResult> GetLayoutSets(string org, string app, Cancellat
return Ok(layoutSets);
}

[HttpGet("layout-sets/extended")]
[UseSystemTextJson]
public async Task<LayoutSetsModel> GetLayoutSetsExtended(string org, string app, CancellationToken cancellationToken)
{
string developer = AuthenticationHelper.GetDeveloperUserName(HttpContext);
var editingContext = AltinnRepoEditingContext.FromOrgRepoDeveloper(org, app, developer);

LayoutSetsModel layoutSetsModel = await _appDevelopmentService.GetLayoutSetsExtended(editingContext, cancellationToken);
return layoutSetsModel;
}

/// <summary>
/// Add a new layout set
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Text.Json.Serialization;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Serialization;
using Altinn.App.Core.Internal.Process.Elements;
using Altinn.Studio.Designer.Configuration;
using Altinn.Studio.Designer.Exceptions.AppDevelopment;
using Altinn.Studio.Designer.Helpers;
Expand Down Expand Up @@ -804,6 +806,13 @@ public Stream GetProcessDefinitionFile()
return OpenStreamByRelativePath(ProcessDefinitionFilePath);
}

public Definitions GetDefinitions()
{
Stream processDefinitionStream = GetProcessDefinitionFile();
XmlSerializer serializer = new(typeof(Definitions));
return (Definitions)serializer.Deserialize(processDefinitionStream);
}

/// <summary>
/// Checks if image already exists in wwwroot
/// </summary>
Expand Down
16 changes: 16 additions & 0 deletions backend/src/Designer/Models/Dto/LayoutSetModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class LayoutSetModel
{
[JsonPropertyName("id")]
public string id { get; set; }
[JsonPropertyName("dataType")]
public string dataType { get; set; }
[JsonPropertyName("type")]
public string type { get; set; }
[JsonPropertyName("task")]
public TaskModel task { get; set; }
}

10 changes: 10 additions & 0 deletions backend/src/Designer/Models/Dto/LayoutSets.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Collections.Generic;
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class LayoutSetsModel
{
[JsonPropertyName("sets")]
public List<LayoutSetModel> sets { get; set; } = [];
}
12 changes: 12 additions & 0 deletions backend/src/Designer/Models/Dto/TaskModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Text.Json.Serialization;

namespace Altinn.Studio.Designer.Models.Dto;

public class TaskModel
{
[JsonPropertyName("id")]
public string id { get; set; }
[JsonPropertyName("type")]
public string type { get; set; }
}

Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,14 @@
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using Altinn.App.Core.Internal.Process.Elements;
using Altinn.App.Core.Models;
using Altinn.Studio.DataModeling.Metamodel;
using Altinn.Studio.Designer.Exceptions.AppDevelopment;
using Altinn.Studio.Designer.Helpers;
using Altinn.Studio.Designer.Infrastructure.GitRepository;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using Altinn.Studio.Designer.Services.Interfaces;
using Microsoft.AspNetCore.Http;
using NuGet.Versioning;
Expand Down Expand Up @@ -265,6 +267,43 @@ public async Task<LayoutSets> GetLayoutSets(AltinnRepoEditingContext altinnRepoE
"No layout set found for this app.");
}

private static string TaskTypeFromDefinitions(Definitions definitions, string taskId)
{
return definitions.Process.Tasks.FirstOrDefault(task => task.Id == taskId)?.ExtensionElements?.TaskExtension?.TaskType ?? string.Empty;
}

public async Task<LayoutSetsModel> GetLayoutSetsExtended(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();
AltinnAppGitRepository altinnAppGitRepository = _altinnGitRepositoryFactory.GetAltinnAppGitRepository(altinnRepoEditingContext.Org, altinnRepoEditingContext.Repo, altinnRepoEditingContext.Developer);

LayoutSets layoutSetsFile = await altinnAppGitRepository.GetLayoutSetsFile(cancellationToken);
Definitions definitions = altinnAppGitRepository.GetDefinitions();

LayoutSetsModel layoutSetsModel = new();
layoutSetsFile.Sets.ForEach(set =>
{
LayoutSetModel layoutSetModel = new()
{
id = set.Id,
dataType = set.DataType,
type = set.Type,
};
string taskId = set.Tasks?[0];
if (taskId != null)
{
string taskType = TaskTypeFromDefinitions(definitions, taskId);
layoutSetModel.task = new TaskModel
{
id = taskId,
type = taskType
};
}
layoutSetsModel.sets.Add(layoutSetModel);
});
return layoutSetsModel;
}

/// <inheritdoc />
public async Task<LayoutSetConfig> GetLayoutSetConfig(AltinnRepoEditingContext altinnRepoEditingContext, string layoutSetId,
CancellationToken cancellationToken = default)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Threading.Tasks;
using Altinn.Studio.DataModeling.Metamodel;
using Altinn.Studio.Designer.Models;
using Altinn.Studio.Designer.Models.Dto;
using JetBrains.Annotations;

namespace Altinn.Studio.Designer.Services.Interfaces
Expand Down Expand Up @@ -106,6 +107,13 @@ public Task<ModelMetadata> GetModelMetadata(
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is canceled.</param>
public Task<LayoutSets> GetLayoutSets(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken = default);

/// <summary>
/// Extended version of layout sets with the intention of adding information not included in the raw layout-sets.json file.
/// </summary>
/// <param name="altinnRepoEditingContext">An <see cref="AltinnRepoEditingContext"/>.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> that observes if operation is canceled.</param>
public Task<LayoutSetsModel> GetLayoutSetsExtended(AltinnRepoEditingContext altinnRepoEditingContext, CancellationToken cancellationToken = default);

/// <summary>
/// Gets a layoutSet config.
/// </summary>
Expand Down

0 comments on commit 1ba29e7

Please sign in to comment.