Skip to content
Snippets Groups Projects
Commit 80b330eb authored by Petar Hristov's avatar Petar Hristov :speech_balloon: Committed by Sirieam Marie Hunke
Browse files

New: Extended with Application Profile Reporting

parent f2f0c152
No related branches found
No related tags found
2 merge requests!5Release: Sprint/2022 18 :robot:,!4New: Extended with Application Profile Reporting
......@@ -82,6 +82,16 @@ public abstract class Reporting<O> where O : class
// Define commit actions
var actions = new List<CreateCommitRequestAction>();
// Delete files or organizations that are not valid anymore
foreach (var fileInProject in projectTree.Where(file => file.Type.Equals("blob")))
{
if (!files.Any(f => f.Path.Equals(fileInProject.Path)) && !fileInProject.Path.Equals("README.md"))
{
// Add Action
actions.Add(new CreateCommitRequestAction(CreateCommitRequestActionType.Delete, fileInProject.Path));
}
}
// Create a commit per file with its contents
foreach (var file in files)
{
......@@ -100,8 +110,6 @@ public abstract class Reporting<O> where O : class
actionType = CreateCommitRequestActionType.Update;
}
// TODO: Add Mechanism to Delete files or organizations that are not valid anymore
// Add Action
actions.Add(new CreateCommitRequestAction(actionType, file.Path)
{
......
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;
}
}
......@@ -4,7 +4,7 @@ namespace KPIGenerator.Utils;
public static partial class CommandLineOptions
{
[Verb("applprofiles", HelpText = "Generate application profile KPIs")]
[Verb("applicationprofiles", HelpText = "Generate application profile KPIs")]
public class ApplicationProfileReportingOptions : BaseOptions
{
// Add verb specific options here
......
......@@ -5,5 +5,10 @@
/// </summary>
public class ReturnObject
{
public List<string?> Titles { get; set; } = new();
public string Uri { get; set; } = null!;
public string? Publisher { get; set; } = null!;
public string? Rights { get; set; } = null!;
public string? License { get; set; } = null!;
}
......@@ -8,17 +8,11 @@ namespace KPIGenerator.Reportings.User;
/// </summary>
public class ReturnObject
{
[JsonProperty("related_projects")]
public List<RelatedProject> RelatedProjects { get; set; } = new();
[JsonProperty("organizations")]
public List<string> Organizations { get; set; } = new();
[JsonProperty("institutes")]
public List<string> Institutes { get; set; } = new();
[JsonProperty("disciplines")]
public List<DisciplineObject> Disciplines { get; set; } = new();
[JsonProperty("login_providers")]
public List<ExternalAuthenticatorsObject> LoginProviders { get; set; } = new();
[JsonProperty("latest_activity")]
public DateTime? LatestActivity { get; set; } = null;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment