Skip to content

Commit

Permalink
[ODS-1462] Use semantic model to derive entity specifications (#862)
Browse files Browse the repository at this point in the history
  • Loading branch information
simpat-jesus authored Nov 9, 2023
1 parent 9f01dce commit 0953d71
Show file tree
Hide file tree
Showing 13 changed files with 244 additions and 311 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,48 +6,38 @@
using System;
using System.Linq;
using EdFi.Common.Extensions;
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Extensions;

namespace EdFi.Ods.Common.Specifications
namespace EdFi.Ods.Common.Specifications;

public class EducationOrganizationEntitySpecification : IEducationOrganizationEntitySpecification
{
// NOTE: This class should be deprecated in factor of a model-driven approach.
public class EducationOrganizationEntitySpecification
private readonly IEducationOrganizationTypesProvider _educationOrganizationTypesProvider;

public EducationOrganizationEntitySpecification(IEducationOrganizationTypesProvider educationOrganizationTypesProvider)
{
private const string EducationOrganizationBaseTypeName = "EducationOrganization";

public static string[] ValidEducationOrganizationTypes { get; } =
{
"EducationOrganization", // Abstract base type
"StateEducationAgency",
"EducationServiceCenter",
"EducationOrganizationNetwork",
"LocalEducationAgency",
"School",
"CommunityOrganization",
"CommunityProvider",
"PostSecondaryInstitution",
"EducationOrganizationNetworkAssociation",
"OrganizationDepartment"
};

public static bool IsEducationOrganizationEntity(Type type) => IsEducationOrganizationEntity(type.Name);

public static bool IsEducationOrganizationEntity(string typeName)
=> ValidEducationOrganizationTypes.Contains(typeName, StringComparer.InvariantCultureIgnoreCase);

public static bool IsEducationOrganizationBaseEntity(string typeName) => typeName == EducationOrganizationBaseTypeName;

public static bool IsEducationOrganizationIdentifier(string propertyName)
{
string entityName;
_educationOrganizationTypesProvider = educationOrganizationTypesProvider;
}

public bool IsEducationOrganizationEntity(Type type) => IsEducationOrganizationEntity(type.Name);

// TODO: Embedded convention (EdOrg identifiers ends with "Id")
if (propertyName.TryTrimSuffix("Id", out entityName))
{
return IsEducationOrganizationEntity(entityName);
}
public bool IsEducationOrganizationEntity(string typeName)
=> _educationOrganizationTypesProvider.EducationOrganizationTypes.Contains(typeName, StringComparer.InvariantCultureIgnoreCase);

return false;
public bool IsEducationOrganizationBaseEntity(string typeName)
=> typeName == EdFiConventions.EducationOrganizationFullName.Name;

public bool IsEducationOrganizationIdentifier(string propertyName)
{
string entityName;

// TODO: Embedded convention (EdOrg identifiers ends with "Id")
if (propertyName.TryTrimSuffix("Id", out entityName))
{
return IsEducationOrganizationEntity(entityName);
}

return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System;
using System.Linq;
using EdFi.Common.Extensions;
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Domain;

namespace EdFi.Ods.Common.Specifications;

public class EducationOrganizationTypesProvider : IEducationOrganizationTypesProvider
{
private readonly Lazy<Entity> _educationOrganizationEntity;
private readonly Lazy<string[]> _validEducationOrganizationTypes;

public EducationOrganizationTypesProvider(IDomainModelProvider domainModelProvider)
{
_educationOrganizationEntity = new(() => domainModelProvider.GetDomainModel()
.EntityByFullName[EdFiConventions.EducationOrganizationFullName]);

_validEducationOrganizationTypes = new(() => domainModelProvider.GetDomainModel()
.Entities.Where(e => e.BaseEntity == _educationOrganizationEntity.Value)
.Select(e => e.Name)
.InsertAtHead(_educationOrganizationEntity.Value.Name)
.ToArray()
);
}

/// <inheritdoc cref="IEducationOrganizationTypesProvider.EducationOrganizationTypes" />
public string[] EducationOrganizationTypes
{
get => _validEducationOrganizationTypes.Value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

using System;

namespace EdFi.Ods.Common.Specifications
{
public interface IEducationOrganizationEntitySpecification
{
bool IsEducationOrganizationBaseEntity(string typeName);
bool IsEducationOrganizationEntity(string typeName);
bool IsEducationOrganizationEntity(Type type);
bool IsEducationOrganizationIdentifier(string propertyName);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// SPDX-License-Identifier: Apache-2.0
// Licensed to the Ed-Fi Alliance under one or more agreements.
// The Ed-Fi Alliance licenses this file to you under the Apache License, Version 2.0.
// See the LICENSE and NOTICES files in the project root for more information.

namespace EdFi.Ods.Common.Specifications;

/// <summary>
/// Defines a method for obtaining the names of the Education Organization type entities
/// in the model.
/// </summary>
public interface IEducationOrganizationTypesProvider
{
/// <summary>
/// Gets the names of the entities of the Education Organization types found in the
/// model.
/// </summary>
string[] EducationOrganizationTypes { get; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
// See the LICENSE and NOTICES files in the project root for more information.

using Autofac;
using EdFi.Ods.Entities.Common.EdFi;
using EdFi.Ods.Api.Security.AuthorizationStrategies.Relationships;
using EdFi.Ods.Entities.Common.EdFi;
using EdFi.Ods.Standard.Security.Authorization.Overrides;

namespace EdFi.Ods.Standard.Container.Modules
Expand Down
Loading

0 comments on commit 0953d71

Please sign in to comment.