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

Reworked PDPs to enable layering PDPs, added platform.base, added Scripture extender layering PDP, replaced name from ProjectMetadata with project setting platform.name #930

Merged
merged 12 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
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
3 changes: 3 additions & 0 deletions assets/localization/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@
"%settings_platform_interfaceLanguage_label%": "Interface Language",
"%project_settings_platform_group1_label%": "Platform Settings",
"%project_settings_platform_group1_description%": "Project settings pertaining to the software overall",
"%project_settings_platform_name_label%": "Project Short Name",
"%project_name_missing%": "_NoName_",
"%project_settings_platform_fullName_label%": "Project Full Name",
"%project_full_name_missing%": "*Name Missing*",
"%project_settings_platform_language_label%": "Project Primary Language",
"%project_settings_platform_isEditable_label%": "Is Editable",
"%project_settings_platform_isEditable_description%": "Whether this project is editable. A project that is not editable is sometimes called a resource."
Expand Down
7 changes: 5 additions & 2 deletions c-sharp-tests/PapiTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ internal abstract class PapiTestBase
#endregion

#region Test setup/teardown
// Ignore warning here because child classes need this to be async
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
[SetUp]
public virtual async Task TestSetup()
{
Expand All @@ -30,6 +32,7 @@ public virtual async Task TestSetup()
_projects = new DummyLocalParatextProjects();
_client = new DummyPapiClient();
}
#pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously

[TearDown]
public virtual void TestTearDown()
Expand Down Expand Up @@ -100,8 +103,8 @@ protected static ProjectDetails CreateProjectDetails(
List<string>? projectInterfaces = null
)
{
ProjectMetadata metadata = new(id, name, projectInterfaces ?? []);
return new ProjectDetails(metadata, "testDirectoryThatDoesNotExist");
ProjectMetadata metadata = new(id, projectInterfaces ?? []);
return new ProjectDetails(name, metadata, "testDirectoryThatDoesNotExist");
}

/// <summary>
Expand Down
24 changes: 12 additions & 12 deletions c-sharp-tests/Projects/LocalParatextProjectsTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ public void TearDown()
[TestCase("ABC")]
public void Initialize_NonStandardFolderName_ProjectIsRetrievable(string folder)
{
CreateTempProject(folder, CreateParatextProjectMetadata("ABC"));
CreateTempProject(folder, CreateParatextProjectDetails(folder, "ABC"));

_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo("ABC"));
Assert.That(details.Name, Is.EqualTo("ABC"));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

Expand All @@ -55,27 +55,27 @@ public void Initialize_NonStandardFolderName_ProjectIsRetrievable(string folder)
[TestCase("A-B-C_441f1e41ffb8d319650847df35f4ffb78f12914e", "ABC")]
public void Initialize_NameDoesNotMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

[TestCase("ABC_541f1e41ffb8d319650847df35f4ffb78f12914e", "ABC")]
[TestCase("AB-C_541f1e41ffb8d319650847df35f4ffb78f12914e", "AB-C")]
public void Initialize_IdDoesNotMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

Expand All @@ -85,25 +85,25 @@ public void Initialize_IdDoesNotMatch_ProjectIsRetrievable(string folder, string
[TestCase("A-B-C_441f1e41ffb8d319650847df35f4ffb78f12914e", "A-B-C")]
public void Initialize_IdAndNameMatch_ProjectIsRetrievable(string folder, string name)
{
var metadata = CreateParatextProjectMetadata(name);
var metadata = CreateParatextProjectDetails(folder, name);
CreateTempProject(folder, metadata);
_localProjects.Initialize(false);
var details = _localProjects.GetAllProjectDetails().Single();
Assert.That(details, Is.EqualTo(_localProjects.GetProjectDetails(TEST_ID)));
Assert.That(details.HomeDirectory, Does.EndWith(folder));
Assert.That(details.Metadata.Name, Is.EqualTo(name));
Assert.That(details.Name, Is.EqualTo(name));
Assert.That(details.Metadata.ID.Equals(TEST_ID, StringComparison.OrdinalIgnoreCase));
}

#endregion

private void CreateTempProject(string folder, ProjectMetadata metadata)
private void CreateTempProject(string folder, ProjectDetails details)
{
((TestLocalParatextProjectsInTempDir)_localProjects).CreateTempProject(folder, metadata);
((TestLocalParatextProjectsInTempDir)_localProjects).CreateTempProject(folder, details);
}

private static ProjectMetadata CreateParatextProjectMetadata(string name)
private static ProjectDetails CreateParatextProjectDetails(string folder, string name)
{
return new ProjectMetadata(TEST_ID, name, ["paratext"]);
return new ProjectDetails(name, new ProjectMetadata(TEST_ID, ["paratext"]), folder);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace TestParanextDataProvider.Projects
internal class ParatextProjectDataProviderFactoryTests : PapiTestBase
{
private const string PDB_FACTORY_GET_REQUEST =
$"object:platform.pdpFactory-{ParatextProjectDataProviderFactory.PDPF_NAME}.function";
$"object:platform.pdpFactory-{ParatextProjectDataProviderFactory.PDPF_NAME}-pdpf.function";

[SetUp]
public override async Task TestSetup()
Expand Down
6 changes: 3 additions & 3 deletions c-sharp-tests/Projects/TestLocalParatextProjectsInTempDir.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ public void Dispose()

protected override string ProjectRootFolder => _folder.Path;

internal void CreateTempProject(string folder, ProjectMetadata projectMetadata)
internal void CreateTempProject(string folder, ProjectDetails projectDetails)
{
var folderPath = Path.Combine(ProjectRootFolder, folder);
CreateDirectory(folderPath);
var settings = new MinimalParatextProjectSettings
{
Name = projectMetadata.Name,
Guid = projectMetadata.ID
Name = projectDetails.Name,
Guid = projectDetails.Metadata.ID
};
var settingsPath = Path.Join(folderPath, "Settings.xml");
XmlSerializationHelper.SerializeToFileWithWriteThrough(settingsPath, settings);
Expand Down
9 changes: 2 additions & 7 deletions c-sharp/JsonUtils/ProjectMetadataConverter.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Paranext.DataProvider.Projects;

Expand All @@ -7,7 +6,6 @@ namespace Paranext.DataProvider.JsonUtils
internal static class ProjectMetadataConverter
{
private const string ID = "id";
private const string NAME = "name";
private const string PROJECT_INTERFACES = "projectInterfaces";

public static bool TryGetMetadata(
Expand All @@ -20,9 +18,8 @@ out string errorMessage
{
JObject parsedArgs = JObject.Parse(jsonString);
string id = Get(parsedArgs, ID);
string name = Get(parsedArgs, NAME);
List<string> projectInterfaces = GetStrings(parsedArgs, PROJECT_INTERFACES);
projectMetadata = new ProjectMetadata(id, name, projectInterfaces);
projectMetadata = new ProjectMetadata(id, projectInterfaces);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -62,17 +59,15 @@ public static string ToJsonString(ProjectMetadata projectMetadata)
return new JObject
{
[ID] = projectMetadata.ID,
[NAME] = projectMetadata.Name,
[PROJECT_INTERFACES] = JToken.FromObject(projectMetadata.ProjectInterfaces)
}.ToString();
}

public static string ToJsonString(string id, string name, List<string> projectInterfaces)
public static string ToJsonString(string id, List<string> projectInterfaces)
{
return new JObject
{
[ID] = id,
[NAME] = name,
[PROJECT_INTERFACES] = JToken.FromObject(projectInterfaces)
}.ToString();
}
Expand Down
22 changes: 12 additions & 10 deletions c-sharp/Projects/LocalParatextProjects.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class LocalParatextProjects
// Inside of each project's "home" directory, these are the subdirectories and files
protected const string PROJECT_SETTINGS_FILE = "Settings.xml";

protected static readonly List<string> _paratextProjectInterfaces = [ProjectInterfaces.Paratext];
public static readonly List<string> ParatextProjectInterfaces = [ProjectInterfaces.Base, ProjectInterfaces.USFM_BCV, ProjectInterfaces.USX_Chapter];

/// <summary>
/// Directory inside a project's root directory where Platform.Bible's extension data is stored
Expand Down Expand Up @@ -125,7 +125,7 @@ private void AddProjectToMaps(ProjectDetails projectDetails)

var projectName = new ProjectName
{
ShortName = projectDetails.Metadata.Name,
ShortName = projectDetails.Name,
ProjectPath = projectPath
};
ScrTextCollection.Add(new ScrText(projectName, RegistrationInfo.DefaultUser));
Expand All @@ -148,27 +148,27 @@ private IEnumerable<ProjectDetails> LoadAllProjectDetails(bool shouldIncludePT9P
// My Paratext 9 Projects
if (rootFolder == Paratext9ProjectsFolder && Path.GetFileName(dir).StartsWith('_')) continue;

ProjectMetadata? projectMetadata;
ProjectDetails? projectDetails;
string errorMessage;
try
{
projectMetadata = LoadProjectMetadata(dir, out errorMessage);
projectDetails = LoadProjectDetails(dir, out errorMessage);
}
catch (Exception ex)
{
Console.WriteLine($"Error while getting project metadata from {dir}: {ex}");
Console.WriteLine($"Error while getting project details from {dir}: {ex}");
continue;
}

if (projectMetadata == null)
if (projectDetails == null)
Console.WriteLine(errorMessage);
else
yield return new ProjectDetails(projectMetadata, dir);
yield return projectDetails;
}
}
}

private static ProjectMetadata? LoadProjectMetadata(
private static ProjectDetails? LoadProjectDetails(
string projectHomeDir,
out string errorMessage
)
Expand Down Expand Up @@ -199,10 +199,12 @@ out string errorMessage
}
var id = idNode.InnerText;

var metadata = new ProjectMetadata(id, shortName, _paratextProjectInterfaces);
var metadata = new ProjectMetadata(id, ParatextProjectInterfaces);

var details = new ProjectDetails(shortName, metadata, projectHomeDir);

errorMessage = "";
return metadata;
return details;
}

private void SetUpSampleProject()
Expand Down
7 changes: 5 additions & 2 deletions c-sharp/Projects/ParatextProjectDataProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ParatextProjectDataProviderFactory(
PapiClient papiClient,
LocalParatextProjects paratextProjects
)
: base([ProjectInterfaces.Paratext], PDPF_NAME, papiClient)
: base(LocalParatextProjects.ParatextProjectInterfaces, PDPF_NAME, papiClient)
{
_paratextProjects = paratextProjects;
}
Expand All @@ -27,7 +27,10 @@ protected override Task StartFactory()
bool? shouldIncludePT9ProjectsOnWindows = false;
if (OperatingSystem.IsWindows())
{
shouldIncludePT9ProjectsOnWindows = SettingsService.GetSettingValue<bool>(PapiClient, Settings.INCLUDE_MY_PARATEXT_9_PROJECTS);
shouldIncludePT9ProjectsOnWindows = SettingsService.GetSettingValue<bool>(
PapiClient,
Settings.INCLUDE_MY_PARATEXT_9_PROJECTS
);
if (!shouldIncludePT9ProjectsOnWindows.HasValue)
throw new Exception($"Setting {Settings.INCLUDE_MY_PARATEXT_9_PROJECTS} was null!");
}
Expand Down
2 changes: 1 addition & 1 deletion c-sharp/Projects/ProjectDataProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ out string errorMessage
throw new Exception("No data scope provided");

dataScope.ProjectID = ProjectDetails.Metadata.ID;
dataScope.ProjectName = ProjectDetails.Metadata.Name;
dataScope.ProjectName = ProjectDetails.Name;
return dataScope;
}

Expand Down
2 changes: 1 addition & 1 deletion c-sharp/Projects/ProjectDataProviderFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected ProjectDataProviderFactory(List<string> projectInterfaces, string pdpf
public async Task Initialize()
{
await StartFactory();
var name = $"platform.pdpFactory-{_pdpfName}";
var name = $"platform.pdpFactory-{_pdpfName}-pdpf";
await RegisterNetworkObject(
name,
new MessageEventProjectDataProviderFactoryCreated(
Expand Down
7 changes: 6 additions & 1 deletion c-sharp/Projects/ProjectDetails.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
using Paratext.Data.DBLServices;

namespace Paranext.DataProvider.Projects;

/// <summary>
/// All information about a project we want to store and pass around internally
/// </summary>
internal class ProjectDetails
{
public ProjectDetails(ProjectMetadata metadata, string homeDirectory)
public ProjectDetails(string name, ProjectMetadata metadata, string homeDirectory)
{
Name = name;
Metadata = metadata;
HomeDirectory = homeDirectory;
}

public string Name { get; }

public ProjectMetadata Metadata { get; }

/// <summary>
Expand Down
8 changes: 7 additions & 1 deletion c-sharp/Projects/ProjectInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,11 @@ namespace Paranext.DataProvider.Projects;
/// </summary>
public static class ProjectInterfaces
{
public const string Paratext = "ParatextStandard";
/// <summary>
/// The name of the `projectInterface` representing the essential methods every Base Project Data
/// Provider must implement
/// </summary>
public const string Base = "platform.base";
public const string USFM_BCV = "platformScripture.USFM_BCV";
public const string USX_Chapter = "platformScripture.USX_Chapter";
}
10 changes: 2 additions & 8 deletions c-sharp/Projects/ProjectMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,14 @@ namespace Paranext.DataProvider.Projects;
/// Returned from Project Data Provider Factories in order to inform others about what projects they
/// support in what form.
/// </summary>
public class ProjectMetadata(string id, string name, List<string> projectInterfaces)
public class ProjectMetadata(string id, List<string> projectInterfaces)
{
/// <summary>
/// ID of the project (must be unique and case-insensitive)
/// </summary>
[JsonProperty("id")]
public string ID { get; } = id.ToUpperInvariant();

/// <summary>
/// Short name of the project (not necessarily unique)
/// </summary>
[JsonProperty("name")]
public string Name { get; } = name;

/// <summary>
/// Indicates what sort of project this is which implies its data shape (e.g., what data streams should be available)
/// </summary>
Expand All @@ -31,6 +25,6 @@ public class ProjectMetadata(string id, string name, List<string> projectInterfa

public override string ToString()
{
return $"[{Name} ({ID}): {string.Join(',', ProjectInterfaces)}]";
return $"[({ID}): {string.Join(',', ProjectInterfaces)}]";
}
}
2 changes: 1 addition & 1 deletion c-sharp/Projects/RawDirectoryProjectStreamManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public void Initialize() // TODO: This doesn't seem to be used
{
if (!Directory.Exists(_projectDetails.HomeDirectory))
throw new Exception(
$"Project contents missing for {_projectDetails.Metadata.Name} ({_projectDetails.Metadata.ID})"
$"Project contents missing for {_projectDetails.Name} ({_projectDetails.Metadata.ID})"
);
}

Expand Down
4 changes: 4 additions & 0 deletions c-sharp/Services/ProjectSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ public sealed class ProjectSettings
public const string PB_BOOKS_PRESENT = "platformScripture.booksPresent";
public const string PT_BOOKS_PRESENT = "BooksPresent";

public const string PB_NAME = "platform.name";
public const string PT_NAME = "Name";

public const string PB_FULL_NAME = "platform.fullName";
public const string PT_FULL_NAME = "FullName";

Expand All @@ -27,6 +30,7 @@ public sealed class ProjectSettings
new()
{
{ PB_BOOKS_PRESENT, PT_BOOKS_PRESENT },
{ PB_NAME, PT_NAME },
{ PB_FULL_NAME, PT_FULL_NAME },
{ PB_LANGUAGE, PT_LANGUAGE },
{ PB_VERSIFICATION, PT_VERSIFICATION },
Expand Down
1 change: 0 additions & 1 deletion extensions/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"webpack-merge": "^5.10.0",
"zip-folder-promise": "^1.2.0"
},
"workspaces": ["src/*"],
"volta": {
"extends": "../package.json"
}
Expand Down
Loading
Loading