Skip to content

Commit

Permalink
add option in get diagram query to instruct the schematic service to …
Browse files Browse the repository at this point in the history
…save the diagram in a geojson file
  • Loading branch information
jesper-dax committed Feb 27, 2021
1 parent 5b394eb commit ffd8afa
Showing 1 changed file with 14 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using OpenFTTH.APIGateway.GraphQL.Schematic.Types;
using OpenFTTH.CQRS;
using OpenFTTH.Schematic.API.Queries;
using OpenFTTH.Schematic.Business.IO;
using System;
using System.Linq;

Expand All @@ -18,7 +19,10 @@ public SchematicQueries(ILogger<SchematicQueries> logger, IQueryDispatcher query

Field<DiagramType>(
"buildDiagram",
arguments: new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "routeNetworkElementId" }),
arguments:
new QueryArguments(new QueryArgument<NonNullGraphType<IdGraphType>> { Name = "routeNetworkElementId" },
new QueryArgument<StringGraphType> { Name = "exportToGeoJsonFilename" }
),
resolve: context =>
{
if (!Guid.TryParse(context.GetArgument<string>("routeNetworkElementId"), out Guid routeNetworkElementId))
Expand All @@ -34,6 +38,15 @@ public SchematicQueries(ILogger<SchematicQueries> logger, IQueryDispatcher query
context.Errors.Add(new ExecutionError(getDiagramQueryResult.Errors.First().Message));
}

// Export to geojson file (for checking in QGIS etc.) if such filename is specified
var jsonFilename = context.GetArgument<string>("exportToGeoJsonFilename");

if (jsonFilename != null)
{
var export = new GeoJsonExporter(getDiagramQueryResult.Value.Diagram);
export.Export(jsonFilename);
}

return getDiagramQueryResult.Value.Diagram;
}
);
Expand Down

0 comments on commit ffd8afa

Please sign in to comment.