Skip to content

Commit d323371

Browse files
committed
Use SAS DTO for analysis and workspace
1 parent 61f7060 commit d323371

7 files changed

Lines changed: 115 additions & 22 deletions

File tree

api/Controllers/AnalysisController.cs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,27 +11,29 @@ namespace api.Controllers;
1111
public class AnalysisController(
1212
ILogger<AnalysisController> logger,
1313
IAnalysisService analysisService,
14-
IAnalysisTriggerService analysisTriggerService
14+
IAnalysisTriggerService analysisTriggerService,
15+
IBlobStorageService blobStorageService
1516
) : ControllerBase
1617
{
1718
[HttpGet]
1819
[Authorize(Roles = Role.Any)]
19-
[ProducesResponseType(typeof(PagedResponse<Analysis>), StatusCodes.Status200OK)]
20+
[ProducesResponseType(typeof(PagedResponse<AnalysisDto>), StatusCodes.Status200OK)]
2021
[ProducesResponseType(StatusCodes.Status400BadRequest)]
2122
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
2223
[ProducesResponseType(StatusCodes.Status403Forbidden)]
2324
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
24-
public async Task<ActionResult<PagedResponse<Analysis>>> GetAll(
25+
public async Task<ActionResult<PagedResponse<AnalysisDto>>> GetAll(
2526
[FromQuery] AnalysisParameters parameters
2627
)
2728
{
2829
try
2930
{
3031
var page = await analysisService.GetAnalyses(parameters);
32+
var pageDtos = page.Select((p) => new AnalysisDto(p, blobStorageService)).ToList();
3133
return Ok(
32-
new PagedResponse<Analysis>
34+
new PagedResponse<AnalysisDto>
3335
{
34-
Items = page,
36+
Items = pageDtos,
3537
PageNumber = page.CurrentPage,
3638
PageSize = page.PageSize,
3739
TotalCount = page.TotalCount,
@@ -54,7 +56,7 @@ [FromQuery] AnalysisParameters parameters
5456
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
5557
[ProducesResponseType(StatusCodes.Status403Forbidden)]
5658
[ProducesResponseType(StatusCodes.Status500InternalServerError)]
57-
public async Task<ActionResult<Analysis>> GetById([FromRoute] Guid id)
59+
public async Task<ActionResult<AnalysisDto>> GetById([FromRoute] Guid id)
5860
{
5961
try
6062
{
@@ -63,7 +65,8 @@ public async Task<ActionResult<Analysis>> GetById([FromRoute] Guid id)
6365
{
6466
return NotFound($"Could not find analysis with id {id}");
6567
}
66-
return Ok(analysis);
68+
var analysisDto = new AnalysisDto(analysis, blobStorageService);
69+
return Ok(analysisDto);
6770
}
6871
catch (Exception e)
6972
{

api/Controllers/Models/AnalysisDto.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ public AnalysisDto(Analysis analysis, IBlobStorageService blobService)
1111
this.Id = analysis.Id;
1212
this.Name = analysis.Name;
1313
this.CreatedAt = analysis.CreatedAt;
14+
this.Runs = analysis.Runs;
15+
this.AnalysisGroup = analysis.AnalysisGroup;
16+
this.AnalysisGroupId = analysis.AnalysisGroupId;
17+
this.InspectionRecords = analysis.InspectionRecords;
1418

1519
var workflows = analysis.Runs.SelectMany(r => r.Workflows);
1620

@@ -42,4 +46,12 @@ public AnalysisDto(Analysis analysis, IBlobStorageService blobService)
4246
public Uri? AnonymizedSAS { get; set; }
4347

4448
public Uri? VisualizedSAS { get; set; }
49+
50+
public Guid? AnalysisGroupId { get; set; }
51+
52+
public AnalysisGroup? AnalysisGroup { get; set; }
53+
54+
public List<InspectionRecord> InspectionRecords { get; set; }
55+
56+
public List<AnalysisRun> Runs { get; set; } = [];
4557
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
using api.Database.Models;
2+
using api.Services;
3+
4+
namespace api.Controllers.Models;
5+
6+
public class WorkflowDto(Workflow workflow, IBlobStorageService blobService)
7+
{
8+
public Guid Id { get; set; } = workflow.Id;
9+
10+
public int StepNumber { get; set; } = workflow.StepNumber;
11+
12+
public string WorkflowType { get; set; } = workflow.WorkflowType;
13+
14+
public List<Uri> InputBlobSAS { get; set; } =
15+
workflow
16+
.InputBlobStorageLocations.Select(
17+
(i) => blobService.CreateUserDelegationSASUri(i).Result
18+
)
19+
.ToList();
20+
21+
public WorkflowStatus Status { get; set; } = workflow.Status;
22+
23+
public Uri? OutputBlobSAS { get; set; } =
24+
workflow.OutputBlobStorageLocation != null
25+
? blobService.CreateUserDelegationSASUri(workflow.OutputBlobStorageLocation).Result
26+
: null;
27+
28+
public string? ResultJson { get; set; } = workflow.ResultJson;
29+
30+
public DateTime? StartedAt { get; set; } = workflow.StartedAt;
31+
32+
public DateTime? CompletedAt { get; set; } = workflow.CompletedAt;
33+
34+
public string? ErrorMessage { get; set; } = workflow.ErrorMessage;
35+
}

api/Controllers/WorkflowController.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,23 +8,27 @@ namespace api.Controllers;
88

99
[ApiController]
1010
[Route("workflow")]
11-
public class WorkflowController(ILogger<WorkflowController> logger, IWorkflowService service)
12-
: ControllerBase
11+
public class WorkflowController(
12+
ILogger<WorkflowController> logger,
13+
IWorkflowService service,
14+
IBlobStorageService blobService
15+
) : ControllerBase
1316
{
1417
[HttpGet]
1518
[Authorize(Roles = Role.Any)]
1619
[ProducesResponseType(typeof(PagedResponse<Workflow>), StatusCodes.Status200OK)]
17-
public async Task<ActionResult<PagedResponse<Workflow>>> GetAll(
20+
public async Task<ActionResult<PagedResponse<WorkflowDto>>> GetAll(
1821
[FromQuery] WorkflowParameters parameters
1922
)
2023
{
2124
try
2225
{
2326
var page = await service.GetWorkflows(parameters);
27+
var pageDtos = page.Select((p) => new WorkflowDto(p, blobService)).ToList();
2428
return Ok(
25-
new PagedResponse<Workflow>
29+
new PagedResponse<WorkflowDto>
2630
{
27-
Items = page,
31+
Items = pageDtos,
2832
PageNumber = page.CurrentPage,
2933
PageSize = page.PageSize,
3034
TotalCount = page.TotalCount,
@@ -44,14 +48,15 @@ [FromQuery] WorkflowParameters parameters
4448
[Route("id/{id:guid}")]
4549
[ProducesResponseType(typeof(Workflow), StatusCodes.Status200OK)]
4650
[ProducesResponseType(StatusCodes.Status404NotFound)]
47-
public async Task<ActionResult<Workflow>> GetById([FromRoute] Guid id)
51+
public async Task<ActionResult<WorkflowDto>> GetById([FromRoute] Guid id)
4852
{
4953
var workflow = await service.ReadById(id);
5054
if (workflow is null)
5155
{
5256
return NotFound($"Could not find workflow with id {id}");
5357
}
54-
return Ok(workflow);
58+
var workflowDto = new WorkflowDto(workflow, blobService);
59+
return Ok(workflowDto);
5560
}
5661

5762
[HttpPost]

frontend/src/api/client.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ export interface InspectionRecord {
112112
analyses?: Analysis[];
113113
}
114114

115-
export interface Workflow {
115+
export interface WorkflowWithoutSAS {
116116
id: string;
117117
analysisRunId: string;
118118
stepNumber: number;
@@ -127,21 +127,38 @@ export interface Workflow {
127127
analysisRun?: AnalysisRun;
128128
}
129129

130+
export interface Workflow {
131+
id: string;
132+
analysisRunId: string;
133+
stepNumber: number;
134+
workflowType: string;
135+
inputBlobSAS: string[];
136+
status: WorkflowStatus;
137+
outputBlobSAS?: string | null;
138+
resultJson?: string | null;
139+
startedAt?: string | null;
140+
completedAt?: string | null;
141+
errorMessage?: string | null;
142+
analysisRun?: AnalysisRun;
143+
}
144+
130145
export interface AnalysisRun {
131146
id: string;
132147
analysisId: string;
133148
runNumber: number;
134149
status: AnalysisRunStatus;
135150
startedAt?: string | null;
136151
completedAt?: string | null;
137-
workflows?: Workflow[];
152+
workflows?: WorkflowWithoutSAS[];
138153
analysis?: Analysis;
139154
}
140155

141156
export interface Analysis {
142157
id: string;
143158
name: string;
144159
createdAt: string;
160+
anonymizedSAS: string;
161+
visualizedSAS: string;
145162
analysisGroupId?: string | null;
146163
analysisGroup?: AnalysisGroup | null;
147164
inspectionRecords?: InspectionRecord[];

frontend/src/pages/analyses/detail.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ export default function AnalysisDetailPage() {
7272
<Table.Cell>ID</Table.Cell>
7373
<Table.Cell>{analysis.id}</Table.Cell>
7474
</Table.Row>
75+
<Table.Row>
76+
<Table.Cell>Anonymized data</Table.Cell>
77+
<Table.Cell>
78+
<Typography link href={analysis.anonymizedSAS}>
79+
Link
80+
</Typography></Table.Cell>
81+
</Table.Row>
82+
<Table.Row>
83+
<Table.Cell>Visualized data</Table.Cell>
84+
<Table.Cell>
85+
{
86+
analysis.visualizedSAS ? (
87+
<Typography link href={analysis.visualizedSAS}>
88+
Link
89+
</Typography>) : "-"
90+
}
91+
</Table.Cell>
92+
</Table.Row>
7593
<Table.Row>
7694
<Table.Cell>Created</Table.Cell>
7795
<Table.Cell>{new Date(analysis.createdAt).toLocaleString()}</Table.Cell>

frontend/src/pages/workflows/detail.tsx

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ import { useNavigate, useParams } from "react-router";
33
import { Button, Icon, Table, Typography } from "@equinor/eds-core-react";
44
import { arrow_back } from "@equinor/eds-icons";
55
import { getWorkflow, retryWorkflow, type Workflow } from "../../api/client";
6-
import BlobLocation from "../../components/BlobLocation";
76
import StatusChip from "../../components/StatusChip";
87

98
Icon.add({ arrow_back });
@@ -110,15 +109,17 @@ export default function WorkflowDetailPage() {
110109
<Typography variant="h5" style={{ marginBottom: "0.5rem" }}>
111110
Inputs
112111
</Typography>
113-
{workflow.inputBlobStorageLocations.length === 0 ? (
112+
{workflow.inputBlobSAS.length === 0 ? (
114113
<Typography variant="body_short" style={{ marginBottom: "1.5rem" }}>
115114
None.
116115
</Typography>
117116
) : (
118117
<ul style={{ marginBottom: "1.5rem" }}>
119-
{workflow.inputBlobStorageLocations.map((loc, i) => (
118+
{workflow.inputBlobSAS.map((loc, i) => (
120119
<li key={i}>
121-
<BlobLocation loc={loc} />
120+
<Typography link href={loc}>
121+
Link
122+
</Typography>
122123
</li>
123124
))}
124125
</ul>
@@ -128,8 +129,10 @@ export default function WorkflowDetailPage() {
128129
Output
129130
</Typography>
130131
<div style={{ marginBottom: "1.5rem" }}>
131-
{workflow.outputBlobStorageLocation ? (
132-
<BlobLocation loc={workflow.outputBlobStorageLocation} />
132+
{workflow.outputBlobSAS ? (
133+
<Typography link href={workflow.outputBlobSAS}>
134+
Link
135+
</Typography>
133136
) : (
134137
<Typography variant="body_short">None.</Typography>
135138
)}

0 commit comments

Comments
 (0)