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

Feature/ab#26819 Unity Reporting Enhancements #1007

Draft
wants to merge 34 commits into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
5f948f3
AB#26819 - still very much in experiment phase
AndreGAot Dec 10, 2024
c6c07a7
Merge remote-tracking branch 'origin/dev' into feature/AB#26819-custo…
AndreGAot Dec 12, 2024
acd7067
AB#26819 POC for submission / custom field reporting
AndreGAot Dec 16, 2024
b2ecabb
AB#26819 undo dev config change
AndreGAot Dec 16, 2024
b0a8768
Merge branch 'dev' into feature/AB#26819-custom-field-reporting
AndreGAot Jan 6, 2025
b436062
AB#26819 refactor and start worksheet reporting classes
AndreGAot Jan 6, 2025
cb22fbe
AB#26819 report generator classes for worksheets
AndreGAot Jan 7, 2025
0884650
AB#26819 refactor reporting classes
AndreGAot Jan 9, 2025
1295b49
AB#26819 start scoresheet reporting additions
AndreGAot Jan 9, 2025
e36a7de
AB#26819 more work on scoresheets and refactor
AndreGAot Jan 10, 2025
2afa09e
AB#26819 fix unit test warnings
AndreGAot Jan 10, 2025
716d4a0
AB#26819 scoresheet views added
AndreGAot Jan 13, 2025
b7b0da8
AB#26819 checkbox group column builder and fix audit json loop
AndreGAot Jan 13, 2025
2941799
AB#26819 checkboxgroup report datagenerator added
AndreGAot Jan 14, 2025
f425eb1
AB#26819 refactor and add datagrid report field generator
AndreGAot Jan 14, 2025
80b493b
AB#26819 refactor and add summaries
AndreGAot Jan 14, 2025
97e9b90
AB#26819 update reporting functions and start services for retrospect…
AndreGAot Jan 15, 2025
d6d5909
AB#26819 add endpoint for retroactive data population and bugfixes
AndreGAot Jan 16, 2025
8b122ab
AB#26819 endpoints for report data population and refactor
AndreGAot Jan 17, 2025
31899b4
Merge remote-tracking branch 'origin/dev' into feature/AB#26819-custo…
AndreGAot Jan 17, 2025
4c41643
AB#26819 fix datagrid first row reportdata
AndreGAot Jan 17, 2025
214a56e
AB#26819 sonarqube warning
AndreGAot Jan 17, 2025
ded1a33
AB#26819 more sonarqube cleanup
AndreGAot Jan 17, 2025
faa6329
AB#26819 fix checkbox group report render
AndreGAot Jan 18, 2025
2d1fcd0
AB#26819 add generic try catch for report data generation service
AndreGAot Jan 20, 2025
cc948ef
AB#26819 update blanket exception handler messaging for report data g…
AndreGAot Jan 20, 2025
360030e
Merge remote-tracking branch 'origin/dev' into feature/AB#26819-custo…
AndreGAot Jan 22, 2025
6520474
Merge remote-tracking branch 'origin/dev' into feature/AB#26819-custo…
AndreGAot Jan 24, 2025
fcce070
AB#26819 cleanup sonarqube warnings
AndreGAot Jan 24, 2025
5520b39
AB#26819 move reportgenerator catch to remoteservice from app service
AndreGAot Jan 25, 2025
0843e6d
Merge remote-tracking branch 'origin/dev' into feature/AB#26819-custo…
AndreGAot Jan 27, 2025
926581c
AB#26819 wrap callouts to the reporting services internally with a fe…
AndreGAot Jan 28, 2025
c74ef9e
AB#26819 fix failing unit tests
AndreGAot Jan 28, 2025
8fe1c8b
AB#26819 SQ cleanup
AndreGAot Jan 28, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;

namespace Unity.Flex.Reporting
{
public interface IScoresheetReportingDataGeneratorAppService : IApplicationService
{
Task Generate(Guid scoresheetInstanceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;
using System.Threading.Tasks;
using Volo.Abp.Application.Services;

namespace Unity.Flex.Reporting
{
public interface IScoresheetReportingFieldsGeneratorAppService : IApplicationService
{
Task Generate(Guid scoresheetId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using System;
using Volo.Abp.Application.Services;

namespace Unity.Flex.Reporting
{
public interface IWorksheetReportingDataGeneratorAppService : IApplicationService
{
Task Generate(Guid worksheetInstanceId);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System.Threading.Tasks;
using System;
using Volo.Abp.Application.Services;

namespace Unity.Flex.Reporting
{
public interface IWorksheetReportingFieldsGeneratorAppService : IApplicationService
{
Task Generate(Guid worksheetId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Text.Json;
using Unity.Flex.Scoresheets.Enums;
using Unity.Flex.Worksheets.Definitions;
using Volo.Abp.Application.Dtos;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@ public class CreateWorksheetInstanceDto
public string SheetCorrelationProvider { get; set; } = string.Empty;
public string CorrelationAnchor { get; set; } = string.Empty;
public string? CurrentValue { get; set; }
public string ReportData { get; set; } = string.Empty;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ public interface ICustomFieldValueAppService : IApplicationService
Task ExplicitAddAsync(CustomFieldValueDto value);

[RemoteService(false)]
Task SyncWorksheetInstanceValueAsync(Guid worksheetInstanceId);
Task SyncWorksheetInstanceValueAsync(Guid worksheetInstanceId);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.ObjectModel;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using Unity.Flex.Domain.Scoresheets;
using Unity.Modules.Shared.Correlation;
Expand All @@ -25,6 +26,9 @@ public class ScoresheetInstance : FullAuditedAggregateRoot<Guid>, IMultiTenant,

public virtual Collection<Answer> Answers { get; private set; } = [];

[Column(TypeName = "jsonb")]
public virtual string ReportData { get; private set; } = "{}";

public ScoresheetInstance(Guid id,
Guid scoresheetId,
Guid correlationId,
Expand All @@ -41,5 +45,11 @@ public ScoresheetInstance UpdateValue()
Value = JsonSerializer.Serialize(this);
return this;
}

public ScoresheetInstance SetReportingData(string reportingData)
{
ReportData = reportingData;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
using System;
using System.Collections.ObjectModel;
using Unity.Flex.Scoresheets;
using System.ComponentModel.DataAnnotations.Schema;
using Unity.Flex.Worksheets.Definitions;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;
using Newtonsoft.Json;
using Volo.Abp;
using System.Linq;
using Unity.Flex.Scoresheets.Enums;

namespace Unity.Flex.Domain.Scoresheets
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,26 @@
using System.Linq;
using Unity.Flex.Domain.Exceptions;
using Unity.Flex.Domain.ScoresheetInstances;
using Unity.Flex.Reporting;
using Volo.Abp;
using Volo.Abp.Domain.Entities.Auditing;
using Volo.Abp.MultiTenancy;

namespace Unity.Flex.Domain.Scoresheets
{
public class Scoresheet : FullAuditedAggregateRoot<Guid>, IMultiTenant
public class Scoresheet : FullAuditedAggregateRoot<Guid>, IMultiTenant, IReportableEntity<Scoresheet>
{
public virtual string Title { get; set; } = string.Empty;
public virtual string Name { get; private set; } = string.Empty;
public virtual uint Version { get; set; } = 1;
public virtual uint Order { get; set; } = 0;
public virtual bool Published { get; set; } = false;
public virtual bool Published { get; set; } = false;
public Guid? TenantId { get; set; }


// For reporting purposes
public virtual string ReportColumns { get; set; } = string.Empty;
public virtual string ReportKeys { get; set; } = string.Empty;
public virtual string ReportViewName { get; set; } = string.Empty;

public virtual Collection<ScoresheetSection> Sections { get; private set; } = [];
public virtual Collection<ScoresheetInstance> Instances { get; private set; } = [];
Expand Down Expand Up @@ -100,5 +105,14 @@ internal Scoresheet CloneSection(ScoresheetSection clonedSection)
Sections.Add(clonedSection);
return this;
}

public Scoresheet SetReportingFields(string keys, string columns, string reportViewName)
{
ReportColumns = columns;
ReportViewName = reportViewName;
ReportKeys = keys;

return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Unity.Flex.Domain.ScoresheetInstances;
using Unity.Flex.Domain.Scoresheets;
using Unity.Flex.Reporting.DataGenerators;
using Unity.Flex.Scoresheets.Enums;
using Unity.Flex.Scoresheets.Events;
using Unity.Flex.Worksheets.Definitions;
using Unity.Modules.Shared.Features;
using Volo.Abp.Domain.Services;
using Volo.Abp.Features;
using Volo.Abp.Validation;

namespace Unity.Flex.Domain.Services
{
public class ScoresheetsManager : DomainService
public class ScoresheetsManager(IScoresheetInstanceRepository scoresheetInstanceRepository,
IScoresheetRepository scoresheetRepository,
IReportingDataGeneratorService<Scoresheet, ScoresheetInstance> reportingDataGeneratorService,
IFeatureChecker featureChecker) : DomainService
{
public static List<string> ValidateScoresheetAnswersAsync(ScoresheetInstance scoresheetInstance, Scoresheet scoresheet)
{
Expand Down Expand Up @@ -37,6 +48,41 @@ private static string BuildMissingAnswerError(Question question)
{
return $"{question.Section?.Order + 1}.{question.Order + 1}: {question.Label} (required)";
}

public async Task PersistScoresheetData(PersistScoresheetSectionInstanceEto eventData)
{
var instance = await scoresheetInstanceRepository.GetByCorrelationAsync(eventData.AssessmentId) ?? throw new AbpValidationException("Missing ScoresheetInstance.");
var scoresheet = await scoresheetRepository.GetAsync(instance.ScoresheetId);

var scoresheetAnswers = eventData.AssessmentAnswers.ToList();

foreach (var item in scoresheetAnswers)
{
var ans = instance.Answers.FirstOrDefault(a => a.QuestionId == item.QuestionId);

if (ans != null)
{
ans.SetValue(ValueConverter.Convert(item.Answer ?? "", (QuestionType)item.QuestionType));
}
else
{
ans = new Answer(Guid.NewGuid())
{
CurrentValue = ValueConverter.Convert(item?.Answer?.ToString() ?? string.Empty, (QuestionType)item!.QuestionType),
QuestionId = item.QuestionId,
ScoresheetInstanceId = instance.Id
};
instance.Answers.Add(ans);
}

await scoresheetInstanceRepository.UpdateAsync(instance);
}

if (await featureChecker.IsEnabledAsync(FeatureConsts.Reporting))
{
reportingDataGeneratorService.GenerateAndSet(scoresheet, instance);
}
}
}

public static class ScorehseetExtensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,20 @@
using Unity.Flex.Domain.WorksheetInstances;
using Unity.Flex.Domain.WorksheetLinks;
using Unity.Flex.Domain.Worksheets;
using Unity.Flex.Reporting.DataGenerators;
using Unity.Flex.WorksheetInstances;
using Unity.Flex.Worksheets.Values;
using Unity.Modules.Shared.Features;
using Volo.Abp.Domain.Services;
using Volo.Abp.Features;

namespace Unity.Flex.Domain.Services
{
public class WorksheetsManager(IWorksheetInstanceRepository worksheetInstanceRepository,
IWorksheetRepository worksheetRepository,
IWorksheetLinkRepository worksheetLinkRepository) : DomainService
IWorksheetLinkRepository worksheetLinkRepository,
IReportingDataGeneratorService<Worksheet, WorksheetInstance> reportingService,
IFeatureChecker featureChecker) : DomainService
{
public async Task PersistWorksheetData(PersistWorksheetIntanceValuesEto eventData)
{
Expand Down Expand Up @@ -68,14 +73,21 @@ public async Task UpdateWorksheetInstanceValueAsync(WorksheetInstance instance)
var worksheet = await worksheetRepository.GetAsync(instance.WorksheetId, true);
var fieldDefinitions = worksheet.Sections.SelectMany(s => s.Fields).ToList();
var instanceCurrentValue = new WorksheetInstanceValue();

foreach (var field in instance.Values)
{
var fieldDefinition = fieldDefinitions.Find(s => s.Id == field.CustomFieldId);
if (fieldDefinition != null)
instanceCurrentValue.Values.Add(new FieldInstanceValue(fieldDefinition.Key,
JsonNode.Parse(field.CurrentValue)?["value"]?.ToString() ?? string.Empty));
}

instance.SetValue(JsonSerializer.Serialize(instanceCurrentValue));

if (await featureChecker.IsEnabledAsync(FeatureConsts.Reporting))
{
reportingService.GenerateAndSet(worksheet, instance);
}
}

private void UpdateExistingWorksheetInstance(WorksheetInstance worksheetInstance, Worksheet? worksheet, List<ValueFieldContainer> fields)
Expand Down Expand Up @@ -183,9 +195,9 @@ private async Task<WorksheetInstance> CreateNewWorksheetInstanceAsync(IWorksheet

foreach (var field in allFields)
{
var match = eventData.CustomFields.Find(s => s.fieldName == field.Name);
var (_, chefsPropertyName, value) = eventData.CustomFields.Find(s => s.fieldName == field.Name);
newInstance.AddValue(field.Id,
ValueConverter.Convert(match.value?.ToString() ?? string.Empty, field.Type, match.chefsPropertyName, eventData.VersionData));
ValueConverter.Convert(value?.ToString() ?? string.Empty, field.Type, chefsPropertyName, eventData.VersionData));
}

var newWorksheetInstance = await worksheetInstanceRepository.InsertAsync(newInstance);
Expand All @@ -206,6 +218,7 @@ public async Task<Worksheet> CloneWorksheetAsync(Guid id)
var highestVersion = worksheetVersions.Max(s => s.Version);
var clonedWorksheet = new Worksheet(Guid.NewGuid(), $"{versionSplit[0]}-v{highestVersion + 1}", worksheet.Title);
clonedWorksheet.SetVersion(highestVersion + 1);

foreach (var section in worksheet.Sections.OrderBy(s => s.Order))
{
var clonedSection = new WorksheetSection(Guid.NewGuid(), section.Name);
Expand All @@ -219,7 +232,7 @@ public async Task<Worksheet> CloneWorksheetAsync(Guid id)

var result = await worksheetRepository.InsertAsync(clonedWorksheet);
return result;
}
}

private static CustomField? FindCustomFieldByName(Worksheet? worksheet, string fieldName)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Domain.Repositories;

namespace Unity.Flex.Domain.WorksheetInstances
{
public interface ICustomFieldValueRepository : IBasicRepository<CustomFieldValue, Guid>
{
Task<List<CustomFieldValue>> GetListByWorksheetInstanceAsync(Guid worksheetInstanceId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,22 @@ public class WorksheetInstance : FullAuditedAggregateRoot<Guid>, IMultiTenant, I

public virtual Collection<CustomFieldValue> Values { get; private set; } = [];

[Column(TypeName = "jsonb")]
public virtual string ReportData { get; private set; } = "{}";

protected WorksheetInstance()
{
/* This constructor is for ORMs to be used while getting the entity from the database. */
}

public WorksheetInstance(Guid id,
Guid worksheetId,
Guid correlationId,
Guid correlationId,
string correlationProvider,
Guid worksheetCorrelationId,
string worksheetCorrelationProvider,
string correlationAnchor)
string correlationAnchor,
string? reportData = null)
{
Id = id;
CorrelationId = correlationId;
Expand All @@ -47,6 +51,7 @@ public WorksheetInstance(Guid id,
WorksheetCorrelationProvider = worksheetCorrelationProvider;
UiAnchor = correlationAnchor;
WorksheetId = worksheetId;
ReportData = reportData ?? string.Empty;
}

public WorksheetInstance AddValue(Guid customFieldId, string currentValue)
Expand All @@ -66,5 +71,11 @@ public WorksheetInstance SetAnchor(string uiAnchor)
UiAnchor = uiAnchor;
return this;
}

public WorksheetInstance SetReportingData(string reportingData)
{
ReportData = reportingData;
return this;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Text.Json.Serialization;
using Unity.Flex.Domain.Worksheets;
using Unity.Modules.Shared.Correlation;
using Volo.Abp.Domain.Entities.Auditing;
Expand All @@ -14,6 +15,7 @@ public class WorksheetLink : AuditedAggregateRoot<Guid>, IMultiTenant, ICorrelat
public string CorrelationProvider { get; private set; } = string.Empty;
public string UiAnchor { get; private set; } = string.Empty;

[JsonIgnore]
public virtual Worksheet Worksheet
{
set => _worksheet = value;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Text.Json.Serialization;
using Unity.Flex.Worksheets;
using Unity.Flex.Worksheets.Definitions;
using Volo.Abp;
Expand All @@ -23,7 +24,8 @@ public class CustomField : FullAuditedEntity<Guid>, IMultiTenant

public Guid? TenantId { get; set; }

// Navigation
// Navigation
[JsonIgnore]
public virtual WorksheetSection Section
{
set => _section = value;
Expand Down
Loading