Skip to content

Commit

Permalink
Map adaptivity element in MBZ and integrate MoodlePluginModAdleradapt…
Browse files Browse the repository at this point in the history
…ivity (#416)

* Restructured ElementJson interface hierarchy

* Adapted types of elements in ReadDsl.cs and XmlFactories to new type hierarchy

* Renamed "DSL" to "ATF" in Generator

* Implemented the logic for mapping the adaptivity elements to question.xml

* Added new factory for adaptivity activity

* Added generation of new section in Moodle for BaseLearningElements

* Added new contextId for MBZ 

* Fixed format error that occurred when restoring moodle course

* Fixed some typos in generation of ATF

* Added, adjusted and fixed corresponding tests 

---------

Co-authored-by: Niklas Stich <[email protected]>
  • Loading branch information
MarvinHo64 and niklasstich authored Oct 27, 2023
1 parent d965553 commit b710d78
Show file tree
Hide file tree
Showing 113 changed files with 3,386 additions and 1,507 deletions.
12 changes: 6 additions & 6 deletions AuthoringTool/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
using ElectronWrapper;
using FluentValidation;
using Generator.API;
using Generator.DSL;
using Generator.ATF;
using Generator.WorldExport;
using Microsoft.AspNetCore.Localization;
using Microsoft.Extensions.Caching.Memory;
Expand Down Expand Up @@ -182,7 +182,7 @@ internal static void ConfigurePresentationLogic(IServiceCollection services)
services.AddScoped<IPresentationLogic, PresentationLogic>();
services.AddScoped<ILearningWorldPresenter, LearningWorldPresenter>();
services.AddScoped(p =>
(ILearningWorldPresenterOverviewInterface) p.GetService(typeof(ILearningWorldPresenter))!);
(ILearningWorldPresenterOverviewInterface)p.GetService(typeof(ILearningWorldPresenter))!);
services.AddScoped<ILearningSpacePresenter, LearningSpacePresenter>();
services.AddSingleton<IAuthoringToolWorkspaceViewModel, AuthoringToolWorkspaceViewModel>();
services.AddScoped<IErrorService, ErrorService>();
Expand All @@ -209,8 +209,8 @@ internal static void ConfigureGenerator(IServiceCollection services)
{
services.AddSingleton<IWorldGenerator, WorldGenerator>();
services.AddSingleton<IBackupFileGenerator, BackupFileGenerator>();
services.AddSingleton<ICreateDsl, CreateDsl>();
services.AddSingleton<IReadDsl, ReadDsl>();
services.AddSingleton<ICreateAtf, CreateAtf>();
services.AddSingleton<IReadAtf, ReadAtf>();
}

internal static void ConfigureApiAccess(IServiceCollection services)
Expand Down Expand Up @@ -264,7 +264,7 @@ internal static void ConfigureUtilities(IServiceCollection services)
internal static void ConfigureCommands(IServiceCollection services)
{
services.AddSingleton<ICommandStateManager, CommandStateManager>();
services.AddSingleton<IOnUndoRedo>(p => (CommandStateManager) p.GetService<ICommandStateManager>()!);
services.AddSingleton<IOnUndoRedo>(p => (CommandStateManager)p.GetService<ICommandStateManager>()!);
}

internal static void ConfigureCommandFactories(IServiceCollection services)
Expand Down Expand Up @@ -301,7 +301,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
app.UseStaticFiles();

// Add localization cultures
var supportedCultures = new[] {"de-DE", "en-DE"};
var supportedCultures = new[] { "de-DE", "en-DE" };
var localizationOptions = new RequestLocalizationOptions()
.SetDefaultCulture(supportedCultures[0])
.AddSupportedCultures(supportedCultures)
Expand Down
4 changes: 2 additions & 2 deletions AuthoringToolTest/StartupUt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using BusinessLogic.Validation;
using BusinessLogic.Validation.Validators;
using DataAccess.Persistence;
using Generator.DSL;
using Generator.ATF;
using Generator.WorldExport;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Caching.Memory;
Expand Down Expand Up @@ -135,7 +135,7 @@ public void Startup_ConfigureServices_CanResolveAllBusinessLogicServices(Type re

private static readonly Type[] ConfigureGeneratorRequiredTypes =
{
typeof(IWorldGenerator), typeof(IBackupFileGenerator), typeof(ICreateDsl), typeof(IReadDsl)
typeof(IWorldGenerator), typeof(IBackupFileGenerator), typeof(ICreateAtf), typeof(IReadAtf)
};

[Test]
Expand Down
2 changes: 1 addition & 1 deletion BusinessLogic/API/IWorldGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace BusinessLogic.API;
public interface IWorldGenerator
{
/// <summary>
/// Creates the DSL document, reads it, creates the needed folder structure for the backup, fills the folders with
/// Creates the ATF document, reads it, creates the needed folder structure for the backup, fills the folders with
/// the needed xml-files and saves it to the desired location as .mbz file.
/// </summary>
/// <param name="learningWorld"></param> Information about the learningWorld, topics, spaces and elements
Expand Down
18 changes: 9 additions & 9 deletions Generator/API/WorldGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
using AutoMapper;
using BusinessLogic.API;
using BusinessLogic.Entities;
using Generator.DSL;
using Generator.ATF;
using Generator.WorldExport;
using PersistEntities;

Expand All @@ -11,17 +11,17 @@ namespace Generator.API;
public class WorldGenerator : IWorldGenerator
{
private readonly IFileSystem _fileSystem;
public readonly ICreateDsl CreateDsl;
public readonly IReadDsl ReadDsl;
public readonly ICreateAtf CreateAtf;
public readonly IReadAtf ReadAtf;

internal IMapper Mapper;

public WorldGenerator(IBackupFileGenerator backupFileGenerator, ICreateDsl createDsl, IReadDsl readDsl,
public WorldGenerator(IBackupFileGenerator backupFileGenerator, ICreateAtf createAtf, IReadAtf readAtf,
IMapper mapper, IFileSystem fileSystem)
{
BackupFile = backupFileGenerator;
CreateDsl = createDsl;
ReadDsl = readDsl;
CreateAtf = createAtf;
ReadAtf = readAtf;
Mapper = mapper;
_fileSystem = fileSystem;
}
Expand All @@ -34,9 +34,9 @@ public void ConstructBackup(LearningWorld learningWorld, string filepath)
{
try
{
var dslPath = CreateDsl.GenerateAndExportLearningWorldJson(Mapper.Map<LearningWorldPe>(learningWorld));
ReadDsl.ReadLearningWorld(dslPath);
BackupFile.WriteXmlFiles((ReadDsl as ReadDsl)!);
var atfPath = CreateAtf.GenerateAndExportLearningWorldJson(Mapper.Map<LearningWorldPe>(learningWorld));
ReadAtf.ReadLearningWorld(atfPath);
BackupFile.WriteXmlFiles((ReadAtf as ReadAtf)!);
BackupFile.WriteBackupFile(filepath);
}
finally
Expand Down
16 changes: 16 additions & 0 deletions Generator/ATF/AdaptivityElement/AdaptivityContentJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System.Text.Json.Serialization;

namespace Generator.ATF.AdaptivityElement;

public class AdaptivityContentJson : IAdaptivityContentJson
{
[JsonConstructor]
public AdaptivityContentJson(string introText, List<IAdaptivityTaskJson> adaptivityTasks)
{
IntroText = introText;
AdaptivityTasks = adaptivityTasks;
}

public string IntroText { get; set; }
public List<IAdaptivityTaskJson> AdaptivityTasks { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class AdaptivityElementJson : IAdaptivityElementJson
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class AdaptivityQuestionJson : IAdaptivityQuestionJson
{
[JsonConstructor]
public AdaptivityQuestionJson(string questionType, int questionId, string questionUuid, int questionDifficulty,
public AdaptivityQuestionJson(ResponseType questionType, int questionId, string questionUuid,
int questionDifficulty,
string questionText, List<IAdaptivityRuleJson> adaptivityRules, List<IChoiceJson> choices)
{
QuestionType = questionType;
Expand All @@ -17,7 +18,9 @@ public AdaptivityQuestionJson(string questionType, int questionId, string questi
Choices = choices;
}

public string QuestionType { get; set; }
[JsonConverter(typeof(JsonStringEnumConverter))]
public ResponseType QuestionType { get; set; }

public int QuestionId { get; set; }
public string QuestionUUID { get; set; }
public int QuestionDifficulty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class AdaptivityRuleJson : IAdaptivityRuleJson
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class AdaptivityTaskJson : IAdaptivityTaskJson
{
[JsonConstructor]
public AdaptivityTaskJson(int taskId, string taskUuid, string taskTitle, bool optional,
int requiredDifficulty, List<IAdaptivityQuestionJson> adaptivityQuestions)
int? requiredDifficulty, List<IAdaptivityQuestionJson> adaptivityQuestions)
{
TaskId = taskId;
TaskUUID = taskUuid;
Expand All @@ -20,6 +20,6 @@ public AdaptivityTaskJson(int taskId, string taskUuid, string taskTitle, bool op
public string TaskUUID { get; set; }
public string TaskTitle { get; set; }
public bool Optional { get; set; }
public int RequiredDifficulty { get; set; }
public int? RequiredDifficulty { get; set; }
public List<IAdaptivityQuestionJson> AdaptivityQuestions { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class ChoiceJson : IChoiceJson
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public class CommentActionJson : IAdaptivityActionJson
{
Expand Down
14 changes: 14 additions & 0 deletions Generator/ATF/AdaptivityElement/ContentReferenceActionJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.ATF.AdaptivityElement;

public class ContentReferenceActionJson : IAdaptivityActionJson
{
public ContentReferenceActionJson(int elementId, string? hintText)
{
ElementId = elementId;
HintText = hintText;
}

public int ElementId { get; set; }

public string? HintText { get; set; }
}
14 changes: 14 additions & 0 deletions Generator/ATF/AdaptivityElement/ElementReferenceActionJson.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace Generator.ATF.AdaptivityElement;

public class ElementReferenceActionJson : IAdaptivityActionJson
{
public ElementReferenceActionJson(int elementId, string? hintText)
{
ElementId = elementId;
HintText = hintText;
}

public int ElementId { get; set; }

public string? HintText { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(CommentActionJson), typeDiscriminator: JsonTypes.CommentActionType)]
[JsonDerivedType(typeof(ElementReferenceActionJson), typeDiscriminator: JsonTypes.ElementReferenceActionType)]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(AdaptivityContentJson), typeDiscriminator: JsonTypes.AdaptivityContentType)]
public interface IAdaptivityContentJson
{
string IntroText { get; set; }
bool ShuffleTasks { get; set; }
List<IAdaptivityTaskJson> AdaptivityTask { get; set; }
List<IAdaptivityTaskJson> AdaptivityTasks { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

public interface IAdaptivityElementJson : IInternalElementJson
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(AdaptivityQuestionJson), typeDiscriminator: JsonTypes.AdaptivityQuestionType)]
public interface IAdaptivityQuestionJson
{
string QuestionType { get; set; }
ResponseType QuestionType { get; set; }
int QuestionId { get; set; }
string QuestionUUID { get; set; }
int QuestionDifficulty { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(AdaptivityRuleJson), typeDiscriminator: JsonTypes.CorrectnessTriggerType)]
public interface IAdaptivityRuleJson
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(AdaptivityTaskJson), typeDiscriminator: JsonTypes.AdaptivityTaskType)]
public interface IAdaptivityTaskJson
Expand All @@ -9,6 +9,6 @@ public interface IAdaptivityTaskJson
string TaskUUID { get; set; }
string TaskTitle { get; set; }
bool Optional { get; set; }
int RequiredDifficulty { get; set; }
int? RequiredDifficulty { get; set; }
List<IAdaptivityQuestionJson> AdaptivityQuestions { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL.AdaptivityElement;
namespace Generator.ATF.AdaptivityElement;

[JsonDerivedType(typeof(ChoiceJson), typeDiscriminator: JsonTypes.AdaptivityQuestionAnswerType)]
public interface IChoiceJson
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.Text.Json.Serialization;

namespace Generator.DSL;
namespace Generator.ATF;

public class BaseLearningElementJson : IBaseLearningElementJson
{
Expand Down
Loading

0 comments on commit b710d78

Please sign in to comment.