Skip to content

Commit

Permalink
Partial implementation of UpdateWritingSystemProxy
Browse files Browse the repository at this point in the history
GUID Id vs string WsId is still an issue, as is the Font/Fonts issue.
  • Loading branch information
rmunn committed Nov 18, 2024
1 parent 4409d47 commit 12db010
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 6 deletions.
13 changes: 11 additions & 2 deletions backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -188,9 +188,18 @@ public Task<WritingSystem> CreateWritingSystem(WritingSystemType type, WritingSy
return Task.FromResult(FromLcmWritingSystem(ws, index, type));
}

public Task<WritingSystem> UpdateWritingSystem(WritingSystemId id, WritingSystemType type, UpdateObjectInput<WritingSystem> update)
public async Task<WritingSystem> UpdateWritingSystem(WritingSystemId id, WritingSystemType type, UpdateObjectInput<WritingSystem> update)
{
throw new NotImplementedException(); // TODO: This needs to be implemented now, because UpdateWritingSystem(before, after) needs to call this
Cache.ServiceLocator.WritingSystemManager.GetOrSet(id.Code, out var lcmWritingSystem);
await Cache.DoUsingNewOrCurrentUOW("Update WritingSystem",
"Revert WritingSystem",
async () =>

Check warning on line 196 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FW Lite and run tests

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.

Check warning on line 196 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FwHeadless / publish-fw-headless

This async method lacks 'await' operators and will run synchronously. Consider using the 'await' operator to await non-blocking API calls, or 'await Task.Run(...)' to do CPU-bound work on a background thread.
{
var updateProxy = new UpdateWritingSystemProxy(lcmWritingSystem, this) { Type = type }; // TODO: Doesn't compile, wants Font to be set. Also wants a GUID Id which we don't have...

Check failure on line 198 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FW Lite and run tests

Required member 'WritingSystem.Id' must be set in the object initializer or attribute constructor.

Check failure on line 198 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FW Lite and run tests

Required member 'WritingSystem.Id' must be set in the object initializer or attribute constructor.

Check failure on line 198 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FwHeadless / publish-fw-headless

Required member 'WritingSystem.Id' must be set in the object initializer or attribute constructor.

Check failure on line 198 in backend/FwLite/FwDataMiniLcmBridge/Api/FwDataMiniLcmApi.cs

View workflow job for this annotation

GitHub Actions / Build FwHeadless / publish-fw-headless

Required member 'WritingSystem.Id' must be set in the object initializer or attribute constructor.
update.Apply(updateProxy);
updateProxy.CommitUpdate(Cache);
});
return await GetWritingSystem(id, type);
}

public async Task<WritingSystem> UpdateWritingSystem(WritingSystem before, WritingSystem after)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
using MiniLcm.Models;
using SIL.LCModel;
using SIL.LCModel.Core.WritingSystems;
using SIL.LCModel.DomainServices;

namespace FwDataMiniLcmBridge.Api.UpdateProxy;

public record UpdateWritingSystemProxy : WritingSystem
{
private readonly CoreWritingSystemDefinition _origLcmWritingSystem;
private readonly CoreWritingSystemDefinition _workingLcmWritingSystem;
private readonly FwDataMiniLcmApi _lexboxLcmApi;

public UpdateWritingSystemProxy(CoreWritingSystemDefinition lcmWritingSystem, FwDataMiniLcmApi lexboxLcmApi)
{
_origLcmWritingSystem = lcmWritingSystem;
_workingLcmWritingSystem = new CoreWritingSystemDefinition(lcmWritingSystem, cloneId: true);
_lexboxLcmApi = lexboxLcmApi;
}

public void CommitUpdate(LcmCache cache)
{
if (_workingLcmWritingSystem.Id == _origLcmWritingSystem.Id)
{
cache.ServiceLocator.WritingSystemManager.Set(_workingLcmWritingSystem);
}
else
{
// Changing the ID of a writing system requires LCM to do a lot of work, so only go through that process if absolutely required
WritingSystemServices.MergeWritingSystems(cache, _workingLcmWritingSystem, _origLcmWritingSystem);
}
}

public override required WritingSystemId WsId
{
get => _workingLcmWritingSystem.Id;
set => _workingLcmWritingSystem.Id = value;
}

public override required string Name
{
get => _workingLcmWritingSystem.LanguageName;
set { } // Silently do nothing; name should be derived from WsId at all times, so if the name should change then so should the WsId
}

public override required string Abbreviation
{
get => _workingLcmWritingSystem.Abbreviation;
set => _workingLcmWritingSystem.Abbreviation = value;
}

// TODO: Change WritingSystem Font property to be a list of strings instead of a single string, then do something like this
// public override required List<string> Fonts
// {
// get => _workingLcmWritingSystem.Fonts.Select(f => f.Name).ToList();
// set => throw new NotImplementedException();
// }
}
9 changes: 5 additions & 4 deletions backend/FwLite/MiniLcm/Models/WritingSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
public record WritingSystem: IObjectWithId
{
public required Guid Id { get; set; }
public required WritingSystemId WsId { get; set; }
public required string Name { get; set; }
public required string Abbreviation { get; set; }
public required string Font { get; set; }
public virtual required WritingSystemId WsId { get; set; }
public virtual required string Name { get; set; }
public virtual required string Abbreviation { get; set; }
// TODO: Font will need to become Fonts, a list or array of strings, to better match the LCM model
public virtual required string Font { get; set; }

public DateTimeOffset? DeletedAt { get; set; }
public required WritingSystemType Type { get; set; }
Expand Down

0 comments on commit 12db010

Please sign in to comment.