-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Martin Todorov
committed
Nov 7, 2024
1 parent
1d64399
commit fcaff82
Showing
3 changed files
with
39 additions
and
13 deletions.
There are no files selected for viewing
32 changes: 32 additions & 0 deletions
32
src/Altinn.Broker.API/Helpers/ValidateUseManifestFileShim.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,32 @@ | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace Altinn.Broker.Helpers | ||
{ | ||
[AttributeUsage(AttributeTargets.Class, AllowMultiple = true)] | ||
public class ValidateUseManifestFileShim : ValidationAttribute | ||
{ | ||
protected override ValidationResult IsValid(object value, ValidationContext validationContext) | ||
{ | ||
var useManifestFileShimProperty = validationContext.ObjectType.GetProperty("UseManifestFileShim"); | ||
var externalServiceCodeLegacyProperty = validationContext.ObjectType.GetProperty("ExternalServiceCodeLegacy"); | ||
var externalServiceEditionCodeLegacyProperty = validationContext.ObjectType.GetProperty("ExternalServiceEditionCodeLegacy"); | ||
var useManifestFileShimValue = (bool?)useManifestFileShimProperty.GetValue(validationContext.ObjectInstance, null); | ||
var externalServiceCodeLegacyValue = externalServiceCodeLegacyProperty.GetValue(validationContext.ObjectInstance, null); | ||
var externalServiceEditionCodeLegacyValue = externalServiceEditionCodeLegacyProperty.GetValue(validationContext.ObjectInstance, null); | ||
|
||
if (useManifestFileShimValue == true) | ||
{ | ||
if (externalServiceCodeLegacyValue == null || (externalServiceCodeLegacyValue is string strValue && string.IsNullOrEmpty(strValue))) | ||
{ | ||
return new ValidationResult("ExternalServiceCodeLegacy must be set and not be an empty string."); | ||
} | ||
|
||
if (externalServiceEditionCodeLegacyValue == null || (externalServiceEditionCodeLegacyValue is int intValue && intValue == 0)) | ||
{ | ||
return new ValidationResult("ExternalServiceEditionCodeLegacy must be set and not be zero."); | ||
} | ||
} | ||
return ValidationResult.Success; | ||
} | ||
} | ||
} |
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