-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ODS-6182] Detect Profile scenarios where resources (or any of its ch…
…ildren) cannot be created due to excluded required members (#955)
- Loading branch information
1 parent
cdd9786
commit b00b70d
Showing
42 changed files
with
12,420 additions
and
822 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
Application/EdFi.Ods.Common/Exceptions/DataPolicyException.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
// 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; | ||
|
||
namespace EdFi.Ods.Common.Exceptions; | ||
|
||
/// <summary> | ||
/// An exception that indicates that a Profile (Data Policy) has prevented the request data from being processed. | ||
/// </summary> | ||
public class DataPolicyException : BadRequestDataException | ||
{ | ||
// Fields containing override values for Problem Details | ||
private const string TypePart = "policy"; | ||
private const string TitleText = "Data Policy Enforced"; | ||
private const string DefaultDetail = | ||
"The resource cannot be saved because a data policy has been applied to the request that prevents it."; | ||
|
||
private const string ResourceMessageFormat = | ||
"The Profile definition for '{0}' excludes (or does not include) one or more required data elements needed to create the resource."; | ||
|
||
private const string ResourceChildMessageFormat = | ||
"The Profile definition for '{0}' excludes (or does not include) one or more required data elements needed to create a child item of type '{1}' in the resource."; | ||
|
||
public DataPolicyException(string profileName) | ||
: base(DefaultDetail) | ||
{ | ||
((IEdFiProblemDetails)this).Errors = new[] { string.Format(ResourceMessageFormat, profileName) }; | ||
} | ||
|
||
public DataPolicyException(string profileName, string childTypeName) | ||
: base(DefaultDetail) | ||
{ | ||
((IEdFiProblemDetails)this).Errors = new[] { string.Format(ResourceChildMessageFormat, profileName, childTypeName) }; | ||
} | ||
|
||
// --------------------------- | ||
// Boilerplate for overrides | ||
// --------------------------- | ||
public override string Title { get => TitleText; } | ||
|
||
protected override IEnumerable<string> GetTypeParts() | ||
{ | ||
foreach (var part in base.GetTypeParts()) | ||
{ | ||
yield return part; | ||
} | ||
|
||
yield return TypePart; | ||
} | ||
// --------------------------- | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.