Skip to content

Commit

Permalink
[ODS-5418] Remove DescriptorIds from descriptor resource payloads (#868)
Browse files Browse the repository at this point in the history
Co-authored-by: Geoffrey McElhanon <[email protected]>
  • Loading branch information
simpat-adam and gmcelhanon authored Nov 9, 2023
1 parent b72f5bd commit 9f01dce
Show file tree
Hide file tree
Showing 61 changed files with 2,139 additions and 13,472 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
using EdFi.Ods.Common.IO;
using EdFi.Ods.Common.Logging;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.Ods.Common.Providers;
Expand Down Expand Up @@ -114,6 +115,11 @@ protected override void Load(ContainerBuilder builder)
.As<IDomainModelProvider>()
.SingleInstance();

// Domain model transformers
builder.RegisterType<PriorDescriptorIdRemover>()
.As<IDomainModelDefinitionsTransformer>()
.SingleInstance();

// Schemas
builder.Register(c => c.Resolve<IDomainModelProvider>().GetDomainModel().Schemas.ToArray())
.As<Schema[]>()
Expand Down
4 changes: 3 additions & 1 deletion Application/EdFi.Ods.Common/Extensions/ResourceExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ public static IEnumerable<ResourceProperty> NonReferencedProperties(this Resourc
.ToHashSet();

return resourceClassBase.AllProperties
.Where(p => (p.IsUnified() && p.IsLocallyDefined && !p.PropertyType.IsNullable) || !propertiesOfReferences.Contains(p.PropertyName));
.Where(p => (p.IsUnified() && p.IsLocallyDefined && !p.PropertyType.IsNullable)
|| !propertiesOfReferences.Contains(p.PropertyName))
.Where(p => !p.JsonIgnore);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,8 @@
// See the LICENSE and NOTICES files in the project root for more information.

using System.Collections.Generic;
using EdFi.Ods.Common.Models.Definitions;

namespace EdFi.Ods.Common.Models
namespace EdFi.Ods.Common.Models.Definitions.Transformers
{
public interface IDomainModelDefinitionsTransformer
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// 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.Collections.Generic;
using System.Linq;
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Models.Domain;

namespace EdFi.Ods.Common.Models.Definitions.Transformers;

/// <summary>
/// Implements a transformer that removes the PriorDescriptorId property from the edfi.Descriptor entity's definition
/// to prevent any artifacts from being generated or rendered for it. This class should be removed once the property
/// has been removed from the source ApiModel.json file generated by MetaEd.
/// </summary>
public class PriorDescriptorIdRemover : IDomainModelDefinitionsTransformer
{
public IEnumerable<DomainModelDefinitions> TransformDefinitions(IEnumerable<DomainModelDefinitions> definitions)
{
foreach (DomainModelDefinitions domainModelDefinitions in definitions)
{
// Look for the edfi.Descriptor entity definition
var entityDefinition = domainModelDefinitions.EntityDefinitions?.FirstOrDefault(
ed => new FullName(ed.Schema, ed.Name) == EdFiConventions.DescriptorFullName);

if (entityDefinition != null)
{
// Remove the PriorDescriptorId property
entityDefinition.LocallyDefinedProperties =
entityDefinition.LocallyDefinedProperties
.Where(p => p.PropertyName != "PriorDescriptorId")
.ToArray();
}

yield return domainModelDefinitions;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using System.Linq;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;

namespace EdFi.Ods.Common.Models.Domain
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ public ResourceProperty(ResourceMemberBase containingMember, ResourceClassBase r
&& entityProperty.Entity.IsPersonEntity()
&& UniqueIdConventions.IsUniqueId(entityProperty.PropertyName, entityProperty.Entity.Name));

// Concrete DescriptorId properties should not be exposed over JSON or API metadata
JsonIgnore = entityProperty.Entity.IsDescriptorEntity && entityProperty.IsIdentifying;

IsLocallyDefined = entityProperty.IsLocallyDefined;
IsServerAssigned = entityProperty.IsServerAssigned;

Expand Down Expand Up @@ -276,6 +279,12 @@ private bool IsUsiWithTransformedResourcePropertyName(EntityProperty property)
&& property.DefiningProperty.Entity.IsPersonEntity();
}

/// <summary>
/// Indicates whether the property should be excluded from the JSON representation of the resource
/// and corresponding Open API metadata.
/// </summary>
public bool JsonIgnore { get; }

/// <inheritdoc cref="ResourceMemberBase.JsonPath" />
public override string JsonPath
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using EdFi.Ods.Common;
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Tests.TestExtension;
using EdFi.TestFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Linq;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Tests.TestExtension;
using EdFi.TestFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using EdFi.Ods.Common.Extensions;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.TestFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Xml.Linq;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.Ods.Common.Models.Validation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Xml.Linq;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.Ods.Common.Models.Validation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using EdFi.Ods.Common.Conventions;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.TestFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EdFi.Ods.Common;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Tests._Extensions;
using EdFi.TestFixture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using EdFi.Ods.Common;
using EdFi.Ods.Common.Models;
using EdFi.Ods.Common.Models.Definitions;
using EdFi.Ods.Common.Models.Definitions.Transformers;
using EdFi.Ods.Common.Models.Domain;
using EdFi.Ods.Common.Models.Resource;
using EdFi.Ods.Features.OpenApiMetadata.Dtos;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ string IDescriptor.Namespace
get { return Namespace; }
set { Namespace = value; }
}
int? IDescriptor.PriorDescriptorId
{
get { return PriorDescriptorId; }
set { PriorDescriptorId = value; }
}
string IDescriptor.ShortDescription
{
get { return ShortDescription; }
Expand Down Expand Up @@ -2060,11 +2055,6 @@ string IDescriptor.Namespace
get { return Namespace; }
set { Namespace = value; }
}
int? IDescriptor.PriorDescriptorId
{
get { return PriorDescriptorId; }
set { PriorDescriptorId = value; }
}
string IDescriptor.ShortDescription
{
get { return ShortDescription; }
Expand Down Expand Up @@ -2244,11 +2234,6 @@ string IDescriptor.Namespace
get { return Namespace; }
set { Namespace = value; }
}
int? IDescriptor.PriorDescriptorId
{
get { return PriorDescriptorId; }
set { PriorDescriptorId = value; }
}
string IDescriptor.ShortDescription
{
get { return ShortDescription; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public ArtMediumDescriptorMappingContract(
bool isEffectiveBeginDateSupported,
bool isEffectiveEndDateSupported,
bool isNamespaceSupported,
bool isPriorDescriptorIdSupported,
bool isShortDescriptionSupported
)
{
Expand All @@ -52,7 +51,6 @@ bool isShortDescriptionSupported
IsEffectiveBeginDateSupported = isEffectiveBeginDateSupported;
IsEffectiveEndDateSupported = isEffectiveEndDateSupported;
IsNamespaceSupported = isNamespaceSupported;
IsPriorDescriptorIdSupported = isPriorDescriptorIdSupported;
IsShortDescriptionSupported = isShortDescriptionSupported;
}

Expand All @@ -61,7 +59,6 @@ bool isShortDescriptionSupported
public bool IsEffectiveBeginDateSupported { get; }
public bool IsEffectiveEndDateSupported { get; }
public bool IsNamespaceSupported { get; }
public bool IsPriorDescriptorIdSupported { get; }
public bool IsShortDescriptionSupported { get; }

bool IMappingContract.IsMemberSupported(string memberName)
Expand All @@ -78,8 +75,6 @@ bool IMappingContract.IsMemberSupported(string memberName)
return IsEffectiveEndDateSupported;
case "Namespace":
return IsNamespaceSupported;
case "PriorDescriptorId":
return IsPriorDescriptorIdSupported;
case "ShortDescription":
return IsShortDescriptionSupported;
default:
Expand Down Expand Up @@ -575,7 +570,6 @@ public FavoriteBookCategoryDescriptorMappingContract(
bool isEffectiveBeginDateSupported,
bool isEffectiveEndDateSupported,
bool isNamespaceSupported,
bool isPriorDescriptorIdSupported,
bool isShortDescriptionSupported
)
{
Expand All @@ -584,7 +578,6 @@ bool isShortDescriptionSupported
IsEffectiveBeginDateSupported = isEffectiveBeginDateSupported;
IsEffectiveEndDateSupported = isEffectiveEndDateSupported;
IsNamespaceSupported = isNamespaceSupported;
IsPriorDescriptorIdSupported = isPriorDescriptorIdSupported;
IsShortDescriptionSupported = isShortDescriptionSupported;
}

Expand All @@ -593,7 +586,6 @@ bool isShortDescriptionSupported
public bool IsEffectiveBeginDateSupported { get; }
public bool IsEffectiveEndDateSupported { get; }
public bool IsNamespaceSupported { get; }
public bool IsPriorDescriptorIdSupported { get; }
public bool IsShortDescriptionSupported { get; }

bool IMappingContract.IsMemberSupported(string memberName)
Expand All @@ -610,8 +602,6 @@ bool IMappingContract.IsMemberSupported(string memberName)
return IsEffectiveEndDateSupported;
case "Namespace":
return IsNamespaceSupported;
case "PriorDescriptorId":
return IsPriorDescriptorIdSupported;
case "ShortDescription":
return IsShortDescriptionSupported;
default:
Expand Down Expand Up @@ -651,7 +641,6 @@ public MembershipTypeDescriptorMappingContract(
bool isEffectiveBeginDateSupported,
bool isEffectiveEndDateSupported,
bool isNamespaceSupported,
bool isPriorDescriptorIdSupported,
bool isShortDescriptionSupported
)
{
Expand All @@ -660,7 +649,6 @@ bool isShortDescriptionSupported
IsEffectiveBeginDateSupported = isEffectiveBeginDateSupported;
IsEffectiveEndDateSupported = isEffectiveEndDateSupported;
IsNamespaceSupported = isNamespaceSupported;
IsPriorDescriptorIdSupported = isPriorDescriptorIdSupported;
IsShortDescriptionSupported = isShortDescriptionSupported;
}

Expand All @@ -669,7 +657,6 @@ bool isShortDescriptionSupported
public bool IsEffectiveBeginDateSupported { get; }
public bool IsEffectiveEndDateSupported { get; }
public bool IsNamespaceSupported { get; }
public bool IsPriorDescriptorIdSupported { get; }
public bool IsShortDescriptionSupported { get; }

bool IMappingContract.IsMemberSupported(string memberName)
Expand All @@ -686,8 +673,6 @@ bool IMappingContract.IsMemberSupported(string memberName)
return IsEffectiveEndDateSupported;
case "Namespace":
return IsNamespaceSupported;
case "PriorDescriptorId":
return IsPriorDescriptorIdSupported;
case "ShortDescription":
return IsShortDescriptionSupported;
default:
Expand Down
Loading

0 comments on commit 9f01dce

Please sign in to comment.