Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🌳 Stub endpoints for backend client 🌳 #63

Merged
merged 7 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ client/Boundaries/Boundaries/bin
client/Boundaries/Boundaries/obj
client/Boundaries/TestBoundaries/obj
client/Boundaries/TestBoundaries/bin
client/Boundaries/Backend/bin
client/Boundaries/Backend/obj
output.svg
local
chex.egg-info
Expand All @@ -36,4 +38,4 @@ __pycache__
/SymbolLibrary/SymolLibrary.Tests/obj/
/SymbolLibrary/SymolLibrary.Tests/bin/
/SymbolLibrary/SymbolLibrary.sln.DotSettings.user
/SymbolLibrary/src/Data/Symbols.xlsm
/SymbolLibrary/src/Data/Symbols.xlsm
12 changes: 12 additions & 0 deletions SymbolLibrary/src/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"profiles": {
"SymbolLibrary": {
"commandName": "Project",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "https://localhost:54024;http://localhost:54025"
}
}
}
14 changes: 14 additions & 0 deletions client/Boundaries/Backend/Backend.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.11" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
</ItemGroup>

</Project>
6 changes: 6 additions & 0 deletions client/Boundaries/Backend/Backend.csproj.user
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<ActiveDebugProfile>https</ActiveDebugProfile>
</PropertyGroup>
</Project>
12 changes: 12 additions & 0 deletions client/Boundaries/Backend/Model/CommissioningPackage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace Backend.Model;

public class CommissioningPackage
{
public required string Id { get; set; }
public required string Name { get; set; }
public required string Colour { get; set; }
public List<Node>? CalculatedInternal { get; set; }
public List<Node>? SelectedInternal { get; set; }
public List<Node>? Boundary { get; set; }

}
7 changes: 7 additions & 0 deletions client/Boundaries/Backend/Model/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace Backend.Model;


public class Node
{
public required string Id { get; set; }
}
74 changes: 74 additions & 0 deletions client/Boundaries/Backend/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
using Backend.Model;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

var app = builder.Build();

if (app.Environment.IsDevelopment())
{
app.UseSwagger();
app.UseSwaggerUI();
}

app.UseHttpsRedirection();


//Add node as boundary
app.MapPost("/commissioning-package/{packageId}/boundary/{nodeId}", (string packageId, string nodeId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Add node as internal
app.MapPost("/commissioning-package/{packageId}/internal/{nodeId}", (string packageId, string nodeId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Remove node as boundary
app.MapDelete("/commissioning-package/{packageId}/boundary/{nodeId}", (string packageId, string nodeId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Remove node as internal
app.MapDelete("/commissioning-package/{packageId}/internal/{nodeId}", (string packageId, string nodeId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Get adjacent nodes
app.MapGet("/nodes/{nodeId}/adjacent", (string nodeId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Add commissioning package
app.MapPost("/commissioning-package", (CommissioningPackage commissioningPackage) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Update commissioning package - updating information like name, color and id while persisting the calculated internal nodes, and boundaries.
app.MapPut("/commissioning-package", (CommissioningPackage commissioningPackage) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Delete commissioning package
app.MapDelete("/commissioning-package/{commissioningPackageId}", (string commissioningPackageId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});

//Get commissioning package
app.MapGet("/commissioning-package/{commissioningPackageId}", (string commissioningPackageId) =>
{
throw new NotImplementedException("TODO: Not implemented...");
});


app.Run();
41 changes: 41 additions & 0 deletions client/Boundaries/Backend/Properties/launchSettings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"$schema": "http://json.schemastore.org/launchsettings.json",
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:4141",
"sslPort": 44387
}
},
"profiles": {
"http": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"https": {
"commandName": "Project",
"dotnetRunMessages": true,
"launchBrowser": true,
"launchUrl": "swagger",
"applicationUrl": "https://localhost:7046;http://localhost:5184",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"launchUrl": "swagger",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
}
}
}
21 changes: 18 additions & 3 deletions client/Boundaries/Boundaries.sln
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@

Microsoft Visual Studio Solution File, Format Version 12.00
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Boundaries", "Boundaries\Boundaries.csproj", "{B7723633-9BCD-44C6-BC90-1E3F5C6C8101}"
# Visual Studio Version 17
VisualStudioVersion = 17.11.35431.28
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Boundaries", "Boundaries\Boundaries.csproj", "{B7723633-9BCD-44C6-BC90-1E3F5C6C8101}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestBoundaries", "TestBoundaries\TestBoundaries.csproj", "{6389698E-C0E2-4262-AE30-FD2A01654FA5}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TestBoundaries", "TestBoundaries\TestBoundaries.csproj", "{6389698E-C0E2-4262-AE30-FD2A01654FA5}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Dexpi2Svg", "Dexpi2Svg\Dexpi2Svg.csproj", "{18B982C7-6B76-46E5-A662-4F6C56A3744E}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Dexpi2Svg", "Dexpi2Svg\Dexpi2Svg.csproj", "{18B982C7-6B76-46E5-A662-4F6C56A3744E}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Backend", "Backend\Backend.csproj", "{49E561FC-F64F-4877-8F24-B8D593568DA9}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Expand All @@ -24,5 +29,15 @@ Global
{18B982C7-6B76-46E5-A662-4F6C56A3744E}.Debug|Any CPU.Build.0 = Debug|Any CPU
{18B982C7-6B76-46E5-A662-4F6C56A3744E}.Release|Any CPU.ActiveCfg = Release|Any CPU
{18B982C7-6B76-46E5-A662-4F6C56A3744E}.Release|Any CPU.Build.0 = Release|Any CPU
{49E561FC-F64F-4877-8F24-B8D593568DA9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{49E561FC-F64F-4877-8F24-B8D593568DA9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{49E561FC-F64F-4877-8F24-B8D593568DA9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{49E561FC-F64F-4877-8F24-B8D593568DA9}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {86B458A0-804E-48CF-9B47-8E0DBDF1F23D}
EndGlobalSection
EndGlobal
8 changes: 4 additions & 4 deletions client/Boundaries/Boundaries/DatalogCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ namespace Boundaries;
public class DatalogCreator
{
public IriReference BoundaryGraph = new IriReference($"https://data.equinor.com/boundaries/{Guid.NewGuid()}");

public string CreateCommissioningSparqlQuery()
{
return $"select ?s(GROUP_CONCAT(?label; SEPARATOR=',') AS ?labels) where {{?s a <{BoundaryGraph}>; rdfs:label ?label. OPTIONAL{{?s <http://sandbox.dexpi.org/rdl/TagNameAssignmentClass> ?tag.}} }} GROUP BY (?s)";
}

public string CreateBoundaryDatalogRule(string internalComponentLabel, IriReference[] borderComponentIris)
{
var filters = borderComponentIris
Expand All @@ -29,8 +29,8 @@ public string CreateBoundaryDatalogRule(string internalComponentLabel, IriRefere
dexpi:PipingOrEquipment [?node].
""";
}


public string CreateConnectedSparqlQuery()
{
return $"select * where {{?s a <{BoundaryGraph}>; rdfs:label ?tag.}}";
Expand Down
15 changes: 8 additions & 7 deletions client/Boundaries/Boundaries/DexpiApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,40 @@

namespace Boundaries;

public static class DexpiApi{
public static class DexpiApi
{
public static async Task<string> GetCommissioningPackage(string internalComponentLabel, IriReference[] borderComponentIris, string dexpiFilePath)
{
var datalogCreator = new DatalogCreator();
var datalog = datalogCreator.CreateBoundaryDatalogRule(internalComponentLabel, borderComponentIris);
var conn = RdfoxApi.GetDefaultConnectionSettings();
await RdfoxApi.LoadDatalog(conn, datalog);

var data = File.ReadAllText(dexpiFilePath);
await RdfoxApi.LoadData(conn, data);

var queryString = datalogCreator.CreateCommissioningSparqlQuery();
var result = await RdfoxApi.QuerySparql(conn, queryString);

await RdfoxApi.DeleteData(conn, data);
await RdfoxApi.DeleteDatalog(conn, datalog);
return result;
}


public static async Task<string> GetConnectedEquipment(string internalComponentLabel, string dexpiFilePath)
{
var datalogCreator = new DatalogCreator();
var datalog = datalogCreator.CreateConnectedDatalogRule(internalComponentLabel);
var conn = RdfoxApi.GetDefaultConnectionSettings();
await RdfoxApi.LoadDatalog(conn, datalog);

var data = File.ReadAllText(dexpiFilePath);
await RdfoxApi.LoadData(conn, data);

var queryString = datalogCreator.CreateConnectedSparqlQuery();
var result = await RdfoxApi.QuerySparql(conn, queryString);

await RdfoxApi.DeleteData(conn, data);
await RdfoxApi.DeleteDatalog(conn, datalog);
return result;
Expand Down
Loading
Loading