Skip to content
Snippets Groups Projects

Release: Sprint/2022 18 :robot:

Merged Petar Hristov requested to merge dev into main
8 files
+ 341
36
Compare changes
  • Side-by-side
  • Inline
Files
8
using KPIGenerator.Utils;
using Newtonsoft.Json;
using VDS.RDF.Query;
using static KPIGenerator.Utils.CommandLineOptions;
namespace KPIGenerator.Reportings.ApplicationProfile;
@@ -12,10 +14,67 @@ public class ApplicationProfileReporting : Reporting<ApplicationProfileReporting
public override IEnumerable<ReportingFileObject> GenerateReporting()
{
/*
* 1. Collect the reporting for the whole database -- General/{ReportingReportingFileName}
* --> See envisioned folder structure.
*/
throw new NotImplementedException();
var reportingFiles = new List<ReportingFileObject>();
var returnObjects = GetApplicationProfiles();
// General File
reportingFiles.Add(new ReportingFileObject
{
Path = GetReportingPathGeneral(ReportingFileName),
Content = ConvertStringContentsToStream(JsonConvert.SerializeObject(returnObjects, Formatting.Indented))
});
return reportingFiles;
}
private List<ReturnObject> GetApplicationProfiles()
{
var _applicationProfile = "applicationProfile";
var _title = "title";
var _publisher = "publisher";
var _rights = "rights";
var _license = "license";
var returnObjects = new List<ReturnObject>();
var queryString = new SparqlParameterizedString
{
CommandText = $@"PREFIX dcterms: <http://purl.org/dc/terms/>
SELECT DISTINCT * WHERE {{
?{_applicationProfile} a <http://www.w3.org/ns/shacl#NodeShape> .
OPTIONAL {{ ?{_applicationProfile} dcterms:{_title} ?{_title}. }}
OPTIONAL {{ ?{_applicationProfile} dcterms:{_publisher} ?{_publisher} . }}
OPTIONAL {{ ?{_applicationProfile} dcterms:{_rights} ?{_rights} . }}
OPTIONAL {{ ?{_applicationProfile} dcterms:{_license} ?{_license} . }}
}}"
};
using var result = RdfStoreConnector.QueryEndpoint.QueryWithResultSet(queryString.ToString());
var grouped = result.GroupBy(ap => new
{
Uri = ap.Value(_applicationProfile).ToString(),
Publisher = ap.HasValue(_publisher) && ap.Value(_publisher) is not null ? ap.Value(_publisher).ToString() : null,
Rights = ap.HasValue(_rights) && ap.Value(_rights) is not null ? ap.Value(_rights).ToString() : null,
License = ap.HasValue(_license) && ap.Value(_license) is not null ? ap.Value(_license).ToString() : null
},
t => t.HasValue(_title) && t.Value(_title) is not null ? t.Value(_title).ToString() : null);
foreach (var ap in grouped)
{
returnObjects.Add(new ReturnObject
{
Uri = ap.Key.Uri,
Publisher = ap.Key.Publisher,
Rights = ap.Key.Rights,
License = ap.Key.License,
Titles = ap.Select(t =>
{
if (t is not null)
{
return t[..t.IndexOf('@')];
}
return t;
}).ToList()
});
}
return returnObjects;
}
}
Loading